add spec
This commit is contained in:
@@ -35,6 +35,32 @@ 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
|
||||||
|
release_types = %w[AcquiredMediaRelease AppearanceRelease LocationRelease MaterialRelease MedicalRelease MiscRelease MusicRelease TalentRelease]
|
||||||
|
create_releases_for_all_types
|
||||||
|
|
||||||
|
release_types.each do |type|
|
||||||
|
lowercase_plural = type.constantize.model_name.plural
|
||||||
|
GenerateContractsZipJob.perform_now(project, download, type, 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
|
||||||
|
if entry.name == csv_file_name
|
||||||
|
csv_file = entry.get_input_stream.read
|
||||||
|
release_class = Object.const_get @release_type
|
||||||
|
headers = release_class.csv_headers
|
||||||
|
puts headers
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context "When there are errors" do
|
context "When there are errors" do
|
||||||
let(:error) { StandardError.new("Contracts or contract templates not found.") }
|
let(:error) { StandardError.new("Contracts or contract templates not found.") }
|
||||||
|
|
||||||
@@ -58,4 +84,17 @@ describe GenerateContractsZipJob do
|
|||||||
path = Rails.root.join("spec", "fixtures", "files")
|
path = Rails.root.join("spec", "fixtures", "files")
|
||||||
File.delete("#{path}/my-video-project_appearance-releases.zip") if File.exists? "#{path}/my-video-project_appearance-releases.zip"
|
File.delete("#{path}/my-video-project_appearance-releases.zip") if File.exists? "#{path}/my-video-project_appearance-releases.zip"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_releases_for_all_types
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user