diff --git a/features/step_definitions/publication_steps.rb b/features/step_definitions/publication_steps.rb index edf0239c954..3bc9ff89cd8 100644 --- a/features/step_definitions/publication_steps.rb +++ b/features/step_definitions/publication_steps.rb @@ -4,17 +4,17 @@ end Given /^a draft publication "([^"]*)" with a PDF attachment$/ do |title| - attachment = Attachment.new(file: pdf_attachment) + attachment = build(:attachment, file: pdf_attachment) create(:draft_publication, title: title, attachments: [attachment]) end Given /^a submitted publication "([^"]*)" with a PDF attachment$/ do |title| - attachment = Attachment.new(file: pdf_attachment) + attachment = build(:attachment, file: pdf_attachment) create(:submitted_publication, title: title, attachments: [attachment]) end Given /^a published publication "([^"]*)" with a PDF attachment$/ do |title| - attachment = Attachment.new(file: pdf_attachment) + attachment = build(:attachment, file: pdf_attachment) create(:published_publication, title: title, attachments: [attachment]) end diff --git a/test/support/admin_document_controller_test_helpers.rb b/test/support/admin_document_controller_test_helpers.rb index 1ba5ac47c45..fc1f0b3ea84 100644 --- a/test/support/admin_document_controller_test_helpers.rb +++ b/test/support/admin_document_controller_test_helpers.rb @@ -191,7 +191,9 @@ def should_allow_attachments_for(document_type) test 'creating a document should attach file' do greenpaper_pdf = fixture_file_upload('greenpaper.pdf', 'application/pdf') attributes = controller_attributes_for(document_type) - attributes[:attachments_attributes] = { "0" => { file: greenpaper_pdf } } + attributes[:attachments_attributes] = { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } post :create, document: attributes @@ -216,7 +218,9 @@ def should_allow_attachments_for(document_type) post :create, document: controller_attributes_for(document_type, title: "", - attachments_attributes: { "0" => { file: greenpaper_pdf } } + attachments_attributes: { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } ) assert_select "form#document_new" do @@ -229,7 +233,9 @@ def should_allow_attachments_for(document_type) post :create, document: controller_attributes_for(document_type, title: "", - attachments_attributes: { "0" => { file: greenpaper_pdf } } + attachments_attributes: { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } ) assert_select "form#document_new" do @@ -241,7 +247,9 @@ def should_allow_attachments_for(document_type) test 'creating a document with invalid data should not show any attachment info' do attributes = controller_attributes_for(document_type) greenpaper_pdf = fixture_file_upload('greenpaper.pdf') - attributes[:attachments_attributes] = { "0" => { file: greenpaper_pdf } } + attributes[:attachments_attributes] = { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } post :create, document: attributes.merge(title: '') @@ -253,8 +261,8 @@ def should_allow_attachments_for(document_type) csv_file = fixture_file_upload('sample-from-excel.csv', 'text/csv') attributes = controller_attributes_for(document_type) attributes[:attachments_attributes] = { - "0" => { file: greenpaper_pdf }, - "1" => { file: csv_file } + "0" => attributes_for(:attachment, file: greenpaper_pdf), + "1" => attributes_for(:attachment, file: csv_file) } post :create, document: attributes @@ -286,7 +294,9 @@ def should_allow_attachments_for(document_type) document = create(document_type) put :update, id: document, document: document.attributes.merge( - attachments_attributes: { "0" => { file: greenpaper_pdf } } + attachments_attributes: { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } ) document.reload @@ -303,7 +313,10 @@ def should_allow_attachments_for(document_type) document = create(document_type) put :update, id: document, document: document.attributes.merge( - attachments_attributes: { "0" => { file: greenpaper_pdf }, "1" => { file: csv_file } } + attachments_attributes: { + "0" => attributes_for(:attachment, file: greenpaper_pdf), + "1" => attributes_for(:attachment, file: csv_file) + } ) document.reload @@ -333,7 +346,9 @@ def should_allow_attachments_for(document_type) put :update, id: document, document: controller_attributes_for(document_type, title: "", - attachments_attributes: { "0" => { file: greenpaper_pdf } } + attachments_attributes: { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } ) assert_select "form#document_edit" do @@ -347,7 +362,9 @@ def should_allow_attachments_for(document_type) put :update, id: document, document: controller_attributes_for(document_type, title: "", - attachments_attributes: { "0" => { file: greenpaper_pdf } } + attachments_attributes: { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } ) assert_select "form#document_edit" do @@ -376,7 +393,9 @@ def should_allow_attachments_for(document_type) put :update, id: document, document: document.attributes.merge( lock_version: lock_version, - attachments_attributes: { "0" => { file: greenpaper_pdf } } + attachments_attributes: { + "0" => attributes_for(:attachment, file: greenpaper_pdf) + } ) assert_select "form#document_edit" do