improve spec
This commit is contained in:
@@ -25,6 +25,31 @@ describe GenerateContractsZipJob do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe ".perform_now" do
|
describe ".perform_now" do
|
||||||
|
shared_examples "generates ZIP containig CSV file with all releases data" do
|
||||||
|
it "generates ZIP containing CSV file with all releases data for all release types" do
|
||||||
|
lowercase_plural = subject.constantize.model_name.plural
|
||||||
|
GenerateContractsZipJob.perform_now(project, download, subject, project.public_send(lowercase_plural).ids)
|
||||||
|
|
||||||
|
generated_zip = download.file.blob.download
|
||||||
|
csv_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.csv"
|
||||||
|
Zip::InputStream.open(StringIO.new(generated_zip)) do |io|
|
||||||
|
while entry = io.get_next_entry
|
||||||
|
next unless entry.name == csv_file_name
|
||||||
|
|
||||||
|
csv_file = entry.get_input_stream.read
|
||||||
|
|
||||||
|
release_class = Object.const_get subject
|
||||||
|
release_headers = release_class.csv_headers
|
||||||
|
|
||||||
|
release_headers.each do |header|
|
||||||
|
expect(csv_file).to match header
|
||||||
|
expect(csv_file).not_to match translation_missing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "updates a download record and creates attachment for it" do
|
it "updates a download record and creates attachment for it" do
|
||||||
GenerateContractsZipJob.perform_now(project, download, "AppearanceRelease", project.appearance_releases.ids)
|
GenerateContractsZipJob.perform_now(project, download, "AppearanceRelease", project.appearance_releases.ids)
|
||||||
|
|
||||||
@@ -35,36 +60,60 @@ describe GenerateContractsZipJob do
|
|||||||
expect(download.file).to be_attached
|
expect(download.file).to be_attached
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates ZIP containing CSV file with all releases data for all release types" do
|
context "generates ZIP for acquired media releases" do
|
||||||
release_types = %w[AcquiredMediaRelease AppearanceRelease LocationRelease MaterialRelease MedicalRelease MiscRelease MusicRelease TalentRelease]
|
let(:release) { create(:acquired_media_release_with_contract_template, :native, project: project) }
|
||||||
create_releases_for_all_types
|
subject { 'AcquiredMediaRelease' }
|
||||||
|
|
||||||
release_types.each do |type|
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
lowercase_plural = type.constantize.model_name.plural
|
end
|
||||||
GenerateContractsZipJob.perform_now(project, download, type, project.public_send(lowercase_plural).ids)
|
|
||||||
|
|
||||||
generated_zip = download.file.blob.download
|
context "generates ZIP for appearance releases" do
|
||||||
csv_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.csv"
|
let(:release) { create(:appearance_release_with_contract_template, :native, project: project, person_name: "John Doe") }
|
||||||
Zip::InputStream.open(StringIO.new(generated_zip)) do |io|
|
subject { 'AppearanceRelease' }
|
||||||
while entry = io.get_next_entry
|
|
||||||
next unless entry.name == csv_file_name
|
|
||||||
|
|
||||||
csv_file = entry.get_input_stream.read
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
|
end
|
||||||
|
|
||||||
release_class = Object.const_get type
|
context "generates ZIP for location releases" do
|
||||||
release_headers = release_class.csv_headers
|
let(:release) { create(:location_release_with_contract_template, :native, project: project) }
|
||||||
|
subject { 'LocationRelease' }
|
||||||
|
|
||||||
release_headers.each do |header|
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
expect(csv_file).to match header
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
dummy_zip_file_name = "#{project.name.parameterize}_#{lowercase_plural.gsub('_', '-')}.zip"
|
context "generates ZIP for material releases" do
|
||||||
if File.exist?(file_fixture(dummy_zip_file_name))
|
let(:release) { create(:material_release_with_contract_template, :native, project: project) }
|
||||||
File.delete(file_fixture(dummy_zip_file_name))
|
subject { 'MaterialRelease' }
|
||||||
end
|
|
||||||
end
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "generates ZIP for medical releases" do
|
||||||
|
let(:release) { create(:medical_release_with_contract_template, :native, project: project) }
|
||||||
|
subject { 'MedicalRelease' }
|
||||||
|
|
||||||
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "generates ZIP for misc releases" do
|
||||||
|
let(:release) { create(:misc_release_with_contract_template, :native, project: project) }
|
||||||
|
subject { 'MiscRelease' }
|
||||||
|
|
||||||
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "generates ZIP for music releases" do
|
||||||
|
let(:release) { create(:music_release_with_contract_template, project: project) }
|
||||||
|
subject { 'MusicRelease' }
|
||||||
|
|
||||||
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "generates ZIP for talent releases" do
|
||||||
|
let(:release) { create(:talent_release_with_contract_template, :native, project: project) }
|
||||||
|
subject { 'TalentRelease' }
|
||||||
|
|
||||||
|
it_behaves_like "generates ZIP containig CSV file with all releases data"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "When there are errors" do
|
context "When there are errors" do
|
||||||
@@ -88,21 +137,16 @@ describe GenerateContractsZipJob do
|
|||||||
# Delete the file created in fixture.
|
# Delete the file created in fixture.
|
||||||
# Or the tests will fail on next run due to already existing files in existing zip.
|
# Or the tests will fail on next run due to already existing files in existing zip.
|
||||||
path = Rails.root.join("spec", "fixtures", "files")
|
path = Rails.root.join("spec", "fixtures", "files")
|
||||||
if File.exists? "#{path}/my-video-project_appearance-releases.zip"
|
releases = %w[acquired-media appearance location material medical misc music talent]
|
||||||
File.delete("#{path}/my-video-project_appearance-releases.zip")
|
releases.each do |release|
|
||||||
|
if File.exists? "#{path}/my-video-project_#{release}-releases.zip"
|
||||||
|
File.delete("#{path}/my-video-project_#{release}-releases.zip")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def translation_missing
|
||||||
def create_releases_for_all_types
|
/translation missing/
|
||||||
create(:acquired_media_release_with_contract_template, :native, project: project)
|
|
||||||
create(:appearance_release_with_contract_template, :native, project: project, person_name: "John Doe")
|
|
||||||
create(:location_release_with_contract_template, :native, project: project)
|
|
||||||
create(:material_release_with_contract_template, :native, project: project)
|
|
||||||
create(:medical_release_with_contract_template, :native, project: project)
|
|
||||||
create(:misc_release_with_contract_template, :native, project: project)
|
|
||||||
create(:music_release_with_contract_template, project: project)
|
|
||||||
create(:talent_release_with_contract_template, :native, project: project)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user