From 4f232c3a258be95cd110d67f264e5d8b46582a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 18 Sep 2021 17:20:52 +0200 Subject: [PATCH] Use the file_fixture helper in tests This way we don't have to write `"spec/fixtures/files"` every time. Note this method isn't included in factories. We could include it like so: ``` FactoryBot::SyntaxRunner.class_eval do include ActiveSupport::Testing::FileFixtures self.file_fixture_path = RSpec.configuration.file_fixture_path end ``` However, I'm not sure about the possible side effects, and since we only use attachments in a few factories, there isn't much gain in applying the monkey-patch. --- spec/lib/remote_census_api_spec.rb | 2 +- spec/lib/tasks/active_storage_spec.rb | 2 +- spec/models/direct_upload_spec.rb | 8 ++--- spec/models/document_spec.rb | 2 +- spec/models/image_spec.rb | 2 +- .../local_census_records/import_spec.rb | 10 +++--- spec/models/site_customization/image_spec.rb | 8 ++--- spec/shared/models/acts_as_imageable.rb | 8 ++--- spec/shared/models/document_validations.rb | 2 +- spec/shared/models/image_validations.rb | 4 +-- spec/shared/system/nested_documentable.rb | 32 ++++++++----------- spec/shared/system/nested_imageable.rb | 26 +++++++-------- .../common_actions/remote_census_mock.rb | 6 ++-- spec/system/admin/budget_phases_spec.rb | 2 +- .../admin/legislation/processes_spec.rb | 2 +- .../local_census_records/imports_spec.rb | 13 ++++---- .../questions/answers/images/images_spec.rb | 2 +- .../site_customization/documents_spec.rb | 2 +- .../admin/site_customization/images_spec.rb | 14 ++++---- spec/system/admin/widgets/cards_spec.rb | 2 +- spec/system/ckeditor_spec.rb | 2 +- spec/system/legislation/proposals_spec.rb | 2 +- 22 files changed, 73 insertions(+), 80 deletions(-) diff --git a/spec/lib/remote_census_api_spec.rb b/spec/lib/remote_census_api_spec.rb index 2e25b6e1e..616dfdce5 100644 --- a/spec/lib/remote_census_api_spec.rb +++ b/spec/lib/remote_census_api_spec.rb @@ -26,7 +26,7 @@ describe RemoteCensusApi do end describe "request messages" do - let(:valid_response) { File.read("spec/fixtures/files/remote_census_api/valid.xml") } + let(:valid_response) { File.read(file_fixture("remote_census_api/valid.xml")) } def request_with(params) { "request" => params } diff --git a/spec/lib/tasks/active_storage_spec.rb b/spec/lib/tasks/active_storage_spec.rb index 9b2edc68d..0f43b39cd 100644 --- a/spec/lib/tasks/active_storage_spec.rb +++ b/spec/lib/tasks/active_storage_spec.rb @@ -35,7 +35,7 @@ describe "active storage tasks" do end it "does not modify old ckeditor attachments" do - image = Ckeditor::Picture.create!(data: Rack::Test::UploadedFile.new("spec/fixtures/files/clippy.png")) + image = Ckeditor::Picture.create!(data: Rack::Test::UploadedFile.new(file_fixture("clippy.png"))) expect(image.storage_data.attachment.name).to eq "storage_data" diff --git a/spec/models/direct_upload_spec.rb b/spec/models/direct_upload_spec.rb index 815421180..bdf079680 100644 --- a/spec/models/direct_upload_spec.rb +++ b/spec/models/direct_upload_spec.rb @@ -10,10 +10,10 @@ describe DirectUpload do end it "is not valid for different kind of combinations with invalid atttachment content types" do - expect(build(:direct_upload, :proposal, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid - expect(build(:direct_upload, :proposal, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid - expect(build(:direct_upload, :budget_investment, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid - expect(build(:direct_upload, :budget_investment, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid + expect(build(:direct_upload, :proposal, :documents, attachment: File.new(file_fixture("clippy.png")))).not_to be_valid + expect(build(:direct_upload, :proposal, :image, attachment: File.new(file_fixture("empty.pdf")))).not_to be_valid + expect(build(:direct_upload, :budget_investment, :documents, attachment: File.new(file_fixture("clippy.png")))).not_to be_valid + expect(build(:direct_upload, :budget_investment, :image, attachment: File.new(file_fixture("empty.pdf")))).not_to be_valid end it "is not valid without resource_type" do diff --git a/spec/models/document_spec.rb b/spec/models/document_spec.rb index af3294e9f..1d7a087a4 100644 --- a/spec/models/document_spec.rb +++ b/spec/models/document_spec.rb @@ -5,7 +5,7 @@ describe Document do it_behaves_like "document validations", "proposal_document" it "stores attachments with Active Storage" do - document = create(:document, attachment: File.new("spec/fixtures/files/clippy.pdf")) + document = create(:document, attachment: File.new(file_fixture("clippy.pdf"))) expect(document.attachment).to be_attached expect(document.attachment.filename).to eq "clippy.pdf" diff --git a/spec/models/image_spec.rb b/spec/models/image_spec.rb index da5b70d46..7022e0b40 100644 --- a/spec/models/image_spec.rb +++ b/spec/models/image_spec.rb @@ -5,7 +5,7 @@ describe Image do it_behaves_like "image validations", "proposal_image" it "stores attachments with Active Storage" do - image = create(:image, attachment: File.new("spec/fixtures/files/clippy.jpg")) + image = create(:image, attachment: File.new(file_fixture("clippy.jpg"))) expect(image.attachment).to be_attached expect(image.attachment.filename).to eq "clippy.jpg" diff --git a/spec/models/local_census_records/import_spec.rb b/spec/models/local_census_records/import_spec.rb index 3aaca8a11..70ec5038b 100644 --- a/spec/models/local_census_records/import_spec.rb +++ b/spec/models/local_census_records/import_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe LocalCensusRecords::Import do - let(:base_files_path) { %w[spec fixtures files local_census_records import] } + let(:base_files_path) { "local_census_records/import/" } let(:import) { build(:local_census_records_import) } describe "Validations" do @@ -17,7 +17,7 @@ describe LocalCensusRecords::Import do context "When file extension" do it "is wrong it should not be valid" do - file = Rack::Test::UploadedFile.new("spec/fixtures/files/clippy.gif") + file = Rack::Test::UploadedFile.new(file_fixture("clippy.gif")) import = build(:local_census_records_import, file: file) expect(import).not_to be_valid @@ -25,7 +25,7 @@ describe LocalCensusRecords::Import do it "is csv it should be valid" do path = base_files_path << "valid.csv" - file = Rack::Test::UploadedFile.new(Rails.root.join(*path)) + file = Rack::Test::UploadedFile.new(file_fixture(path)) import = build(:local_census_records_import, file: file) expect(import).to be_valid @@ -35,7 +35,7 @@ describe LocalCensusRecords::Import do context "When file headers" do it "are all missing it should not be valid" do path = base_files_path << "valid-without-headers.csv" - file = Rack::Test::UploadedFile.new(Rails.root.join(*path)) + file = Rack::Test::UploadedFile.new(file_fixture(path)) import = build(:local_census_records_import, file: file) expect(import).not_to be_valid @@ -64,7 +64,7 @@ describe LocalCensusRecords::Import do it "Add invalid local census records to invalid_records array" do path = base_files_path << "invalid.csv" - file = Rack::Test::UploadedFile.new(Rails.root.join(*path)) + file = Rack::Test::UploadedFile.new(file_fixture(path)) import.file = file import.save! diff --git a/spec/models/site_customization/image_spec.rb b/spec/models/site_customization/image_spec.rb index c1bb77880..eef988bd1 100644 --- a/spec/models/site_customization/image_spec.rb +++ b/spec/models/site_customization/image_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe SiteCustomization::Image do it "stores images with Active Storage" do image = create(:site_customization_image, name: "map", - image: File.new("spec/fixtures/files/custom_map.jpg")) + image: File.new(file_fixture("custom_map.jpg"))) expect(image.image).to be_attached expect(image.image.filename).to eq "custom_map.jpg" @@ -13,7 +13,7 @@ describe SiteCustomization::Image do it "is valid with a 260x80 image" do image = build(:site_customization_image, name: "logo_header", - image: File.new("spec/fixtures/files/logo_header-260x80.png")) + image: File.new(file_fixture("logo_header-260x80.png"))) expect(image).to be_valid end @@ -21,7 +21,7 @@ describe SiteCustomization::Image do it "is valid with a 223x80 image" do image = build(:site_customization_image, name: "logo_header", - image: File.new("spec/fixtures/files/logo_header.png")) + image: File.new(file_fixture("logo_header.png"))) expect(image).to be_valid end @@ -29,7 +29,7 @@ describe SiteCustomization::Image do it "is not valid with a 400x80 image" do image = build(:site_customization_image, name: "logo_header", - image: File.new("spec/fixtures/files/logo_email_custom.png")) + image: File.new(file_fixture("logo_email_custom.png"))) expect(image).not_to be_valid end diff --git a/spec/shared/models/acts_as_imageable.rb b/spec/shared/models/acts_as_imageable.rb index b4624372d..ed0d2df14 100644 --- a/spec/shared/models/acts_as_imageable.rb +++ b/spec/shared/models/acts_as_imageable.rb @@ -7,21 +7,21 @@ shared_examples "acts as imageable" do |imageable_factory| describe "file extension" do it "is not valid with '.png' extension" do - image.attachment = File.new("spec/fixtures/files/clippy.png") + image.attachment = File.new(file_fixture("clippy.png")) expect(image).not_to be_valid expect(image.errors[:attachment].size).to eq(1) end it "is not valid with '.gif' extension" do - image.attachment = File.new("spec/fixtures/files/clippy.gif") + image.attachment = File.new(file_fixture("clippy.gif")) expect(image).not_to be_valid expect(image.errors[:attachment].size).to eq(1) end it "is valid with '.jpg' extension" do - image.attachment = File.new("spec/fixtures/files/clippy.jpg") + image.attachment = File.new(file_fixture("clippy.jpg")) expect(image).to be_valid end @@ -33,7 +33,7 @@ shared_examples "acts as imageable" do |imageable_factory| end it "is not valid when image dimmensions are smaller than 475X475" do - image.attachment = File.new("spec/fixtures/files/logo_header.jpg") + image.attachment = File.new(file_fixture("logo_header.jpg")) expect(image).not_to be_valid end diff --git a/spec/shared/models/document_validations.rb b/spec/shared/models/document_validations.rb index 3594b1a57..01d13de23 100644 --- a/spec/shared/models/document_validations.rb +++ b/spec/shared/models/document_validations.rb @@ -22,7 +22,7 @@ shared_examples "document validations" do |documentable_factory| it "is valid for all accepted content types" do acceptedcontenttypes.each do |content_type| extension = content_type.split("/").last - document.attachment = File.new("spec/fixtures/files/empty.#{extension}") + document.attachment = File.new(file_fixture("empty.#{extension}")) expect(document).to be_valid end diff --git a/spec/shared/models/image_validations.rb b/spec/shared/models/image_validations.rb index ed26d0499..230fe4089 100644 --- a/spec/shared/models/image_validations.rb +++ b/spec/shared/models/image_validations.rb @@ -21,7 +21,7 @@ shared_examples "image validations" do |imageable_factory| it "is valid for all accepted content types" do acceptedcontenttypes.each do |content_type| extension = content_type.split("/").last - image.attachment = File.new("spec/fixtures/files/clippy.#{extension}") + image.attachment = File.new(file_fixture("clippy.#{extension}")) expect(image).to be_valid end @@ -30,7 +30,7 @@ shared_examples "image validations" do |imageable_factory| it "is not valid for png and gif image content types" do ["gif", "png"].each do |content_type| extension = content_type.split("/").last - image.attachment = File.new("spec/fixtures/files/clippy.#{extension}") + image.attachment = File.new(file_fixture("clippy.#{extension}")) expect(image).not_to be_valid end diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index 3e5d03f96..51cba390f 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -51,7 +51,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login visit send(path, arguments) documentable.class.max_documents_allowed.times.each do - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + documentable_attach_new_file(file_fixture("empty.pdf")) end expect(page).to have_css ".max-documents-notice" @@ -77,7 +77,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_link "Add new document" within "#nested-documents" do - attach_file "Choose document", Rails.root.join("spec/fixtures/files/empty.pdf") + attach_file "Choose document", file_fixture("empty.pdf") expect(page).to have_css ".loading-bar.complete" end @@ -90,7 +90,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login visit send(path, arguments) - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + documentable_attach_new_file(file_fixture("empty.pdf")) expect_document_has_title(0, "empty.pdf") end @@ -104,7 +104,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na within "#nested-documents" do input = find("input[name$='[title]']") fill_in input[:id], with: "My Title" - attach_file "Choose document", Rails.root.join("spec/fixtures/files/empty.pdf") + attach_file "Choose document", file_fixture("empty.pdf") expect(page).to have_css ".loading-bar.complete" end @@ -116,7 +116,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login visit send(path, arguments) - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + documentable_attach_new_file(file_fixture("empty.pdf")) expect(page).to have_css ".loading-bar.complete" end @@ -125,10 +125,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login visit send(path, arguments) - documentable_attach_new_file( - Rails.root.join("spec/fixtures/files/logo_header.gif"), - false - ) + documentable_attach_new_file(file_fixture("logo_header.gif"), false) expect(page).to have_css ".loading-bar.errors" end @@ -142,7 +139,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden) expect(cached_attachment_field.value).to be_empty - attach_file "Choose document", Rails.root.join("spec/fixtures/files/empty.pdf") + attach_file "Choose document", file_fixture("empty.pdf") expect(page).to have_css(".loading-bar.complete") expect(cached_attachment_field.value).not_to be_empty @@ -152,10 +149,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login visit send(path, arguments) - documentable_attach_new_file( - Rails.root.join("spec/fixtures/files/logo_header.gif"), - false - ) + documentable_attach_new_file(file_fixture("logo_header.gif"), false) cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden) expect(cached_attachment_field.value).to be_empty @@ -178,7 +172,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login visit send(path, arguments) - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + documentable_attach_new_file(file_fixture("empty.pdf")) click_link "Remove document" expect(page).not_to have_css("#nested-documents .document") @@ -201,7 +195,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + documentable_attach_new_file(file_fixture("empty.pdf")) click_on submit_button expect(page).to have_content documentable_success_notice @@ -215,7 +209,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + documentable_attach_new_file(file_fixture("empty.pdf")) click_on submit_button documentable_redirected_to_resource_show_or_navigate_to @@ -239,7 +233,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na send(fill_resource_method_name) if fill_resource_method_name %w[clippy empty logo].take(documentable.class.max_documents_allowed).each do |filename| - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/#{filename}.pdf")) + documentable_attach_new_file(file_fixture("#{filename}.pdf")) end click_on submit_button @@ -291,7 +285,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login visit send(path, arguments) - documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) + documentable_attach_new_file(file_fixture("empty.pdf")) within_fieldset("Documents") { fill_in "Title", with: "Original" } click_button submit_button diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index f6fe1b723..123a54425 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -38,7 +38,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p visit send(path, arguments) click_link "Add image" - attach_file "Choose image", Rails.root.join("spec/fixtures/files/clippy.jpg") + attach_file "Choose image", file_fixture("clippy.jpg") expect(page).to have_selector ".file-name", text: "clippy.jpg" end @@ -47,7 +47,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p do_login_for user visit send(path, arguments) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) expect_image_has_title("clippy.jpg") end @@ -59,7 +59,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p click_link "Add image" input_title = find(".image input[name$='[title]']") fill_in input_title[:id], with: "Title" - attach_file "Choose image", Rails.root.join("spec/fixtures/files/clippy.jpg") + attach_file "Choose image", file_fixture("clippy.jpg") if has_many_images expect(find("input[id$='_title']").value).to eq "Title" @@ -72,7 +72,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p do_login_for user visit send(path, arguments) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) expect(page).to have_selector ".loading-bar.complete" end @@ -81,7 +81,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p do_login_for user visit send(path, arguments) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/logo_header.png"), false) + imageable_attach_new_file(file_fixture("logo_header.png"), false) expect(page).to have_selector ".loading-bar.errors" end @@ -95,7 +95,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden) expect(cached_attachment_field.value).to be_empty - attach_file "Choose image", Rails.root.join("spec/fixtures/files/clippy.jpg") + attach_file "Choose image", file_fixture("clippy.jpg") expect(page).to have_css(".loading-bar.complete") expect(cached_attachment_field.value).not_to be_empty @@ -105,7 +105,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p do_login_for user visit send(path, arguments) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/logo_header.png"), false) + imageable_attach_new_file(file_fixture("logo_header.png"), false) cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden) @@ -133,7 +133,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p do_login_for user visit send(path, arguments) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) within_fieldset("Descriptive image") { fill_in "Title", with: "" } click_on submit_button @@ -145,7 +145,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p do_login_for user visit send(path, arguments) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) within "#nested-image .image" do click_link "Remove image" @@ -172,7 +172,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) expect(page).to have_selector ".loading-bar.complete" @@ -186,7 +186,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) expect(page).to have_selector ".loading-bar.complete" @@ -205,12 +205,12 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p do_login_for user visit send(path, arguments) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) original_src = find(:fieldset, "Descriptive image").find("img")[:src] click_link "Remove image" - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/custom_map.jpg")) + imageable_attach_new_file(file_fixture("custom_map.jpg")) updated_src = find(:fieldset, "Descriptive image").find("img")[:src] diff --git a/spec/support/common_actions/remote_census_mock.rb b/spec/support/common_actions/remote_census_mock.rb index b140c17e4..0ec9aac17 100644 --- a/spec/support/common_actions/remote_census_mock.rb +++ b/spec/support/common_actions/remote_census_mock.rb @@ -5,15 +5,15 @@ module RemoteCensusMock include DocumentParser def mock_valid_remote_census_response - mock_remote_census_response(File.read("spec/fixtures/files/remote_census_api/valid.xml")) + mock_remote_census_response(File.read(file_fixture("remote_census_api/valid.xml"))) end def mock_invalid_remote_census_response - mock_remote_census_response(File.read("spec/fixtures/files/remote_census_api/invalid.xml")) + mock_remote_census_response(File.read(file_fixture("remote_census_api/invalid.xml"))) end def mock_invalid_signature_sheet_remote_census_response - xml = File.read("spec/fixtures/files/remote_census_api/invalid.xml") + xml = File.read(file_fixture("remote_census_api/invalid.xml")) Signature.new.document_types.each do |document_type| get_document_number_variants(document_type, "12345678Z").each do diff --git a/spec/system/admin/budget_phases_spec.rb b/spec/system/admin/budget_phases_spec.rb index 0d07bcc2f..257b33141 100644 --- a/spec/system/admin/budget_phases_spec.rb +++ b/spec/system/admin/budget_phases_spec.rb @@ -46,7 +46,7 @@ describe "Admin budget phases" do scenario "shows successful notice when updating the phase with a valid image" do visit edit_admin_budget_budget_phase_path(budget, budget.current_phase) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) click_on "Save changes" diff --git a/spec/system/admin/legislation/processes_spec.rb b/spec/system/admin/legislation/processes_spec.rb index d19a3a16c..ca001bbf1 100644 --- a/spec/system/admin/legislation/processes_spec.rb +++ b/spec/system/admin/legislation/processes_spec.rb @@ -175,7 +175,7 @@ describe "Admin collaborative legislation", :admin do fill_in "End", with: base_date + 5.days end - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) click_button "Create process" diff --git a/spec/system/admin/local_census_records/imports_spec.rb b/spec/system/admin/local_census_records/imports_spec.rb index 29154ebbb..a5d39d4dd 100644 --- a/spec/system/admin/local_census_records/imports_spec.rb +++ b/spec/system/admin/local_census_records/imports_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe "Imports", :admin do - let(:base_files_path) { %w[spec fixtures files local_census_records import] } + let(:base_files_path) { "local_census_records/import/" } describe "New" do scenario "Should show import form" do @@ -17,7 +17,7 @@ describe "Imports", :admin do scenario "Should show success notice after successful import" do within "form#new_local_census_records_import" do path = base_files_path << "valid.csv" - file = File.join(Rails.root, *path) + file = file_fixture(path) attach_file("local_census_records_import_file", file) click_button "Save" end @@ -35,8 +35,7 @@ describe "Imports", :admin do scenario "Should show alert when file is not supported" do within "form#new_local_census_records_import" do - path = ["spec", "fixtures", "files", "clippy.jpg"] - file = File.join(Rails.root, *path) + file = file_fixture("clippy.jpg") attach_file("local_census_records_import_file", file) click_button "Save" end @@ -47,7 +46,7 @@ describe "Imports", :admin do scenario "Should show successfully created local census records at created group" do within "form#new_local_census_records_import" do path = base_files_path << "valid.csv" - file = File.join(Rails.root, *path) + file = file_fixture(path) attach_file("local_census_records_import_file", file) click_button "Save" end @@ -59,7 +58,7 @@ describe "Imports", :admin do scenario "Should show invalid local census records at errored group" do within "form#new_local_census_records_import" do path = base_files_path << "invalid.csv" - file = File.join(Rails.root, *path) + file = file_fixture(path) attach_file("local_census_records_import_file", file) click_button "Save" end @@ -71,7 +70,7 @@ describe "Imports", :admin do scenario "Should show error messages inside cells at errored group" do within "form#new_local_census_records_import" do path = base_files_path << "invalid.csv" - file = File.join(Rails.root, *path) + file = file_fixture(path) attach_file("local_census_records_import_file", file) click_button "Save" end diff --git a/spec/system/admin/poll/questions/answers/images/images_spec.rb b/spec/system/admin/poll/questions/answers/images/images_spec.rb index 2d8049f1f..154e2e8fd 100644 --- a/spec/system/admin/poll/questions/answers/images/images_spec.rb +++ b/spec/system/admin/poll/questions/answers/images/images_spec.rb @@ -38,7 +38,7 @@ describe "Images", :admin do expect(page).not_to have_content("clippy.jpg") visit new_admin_answer_image_path(answer) - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) click_button "Save image" expect(page).to have_css("img[title='clippy.jpg']") diff --git a/spec/system/admin/site_customization/documents_spec.rb b/spec/system/admin/site_customization/documents_spec.rb index 6a2063299..5e86779d6 100644 --- a/spec/system/admin/site_customization/documents_spec.rb +++ b/spec/system/admin/site_customization/documents_spec.rb @@ -54,7 +54,7 @@ describe "Documents", :admin do scenario "Create" do visit new_admin_site_customization_document_path - attach_file("document_attachment", "#{Rails.root}/spec/fixtures/files/logo.pdf") + attach_file("document_attachment", file_fixture("logo.pdf")) click_button "Upload" expect(page).to have_content "Document uploaded succesfully" diff --git a/spec/system/admin/site_customization/images_spec.rb b/spec/system/admin/site_customization/images_spec.rb index d79468563..c20b33e7e 100644 --- a/spec/system/admin/site_customization/images_spec.rb +++ b/spec/system/admin/site_customization/images_spec.rb @@ -10,7 +10,7 @@ describe "Admin custom images", :admin do end within("tr#image_logo_header") do - attach_file "site_customization_image_image", "spec/fixtures/files/logo_header.png" + attach_file "site_customization_image_image", file_fixture("logo_header.png") click_button "Update" end @@ -22,7 +22,7 @@ describe "Admin custom images", :admin do visit admin_site_customization_images_path within("tr#image_map") do - attach_file "site_customization_image_image", "spec/fixtures/files/custom_map.jpg" + attach_file "site_customization_image_image", file_fixture("custom_map.jpg") click_button "Update" end @@ -37,7 +37,7 @@ describe "Admin custom images", :admin do visit admin_site_customization_images_path within("tr#image_map") do - attach_file "site_customization_image_image", "spec/fixtures/files/custom_map.jpg" + attach_file "site_customization_image_image", file_fixture("custom_map.jpg") click_button "Update" end @@ -63,7 +63,7 @@ describe "Admin custom images", :admin do scenario "Custom apple touch icon is replaced on front views" do create(:site_customization_image, name: "apple-touch-icon-200", - image: File.new("spec/fixtures/files/apple-touch-icon-custom-200.png")) + image: File.new(file_fixture("apple-touch-icon-custom-200.png"))) visit root_path @@ -77,7 +77,7 @@ describe "Admin custom images", :admin do visit admin_site_customization_images_path within("tr#image_logo_email") do - attach_file "site_customization_image_image", "spec/fixtures/files/logo_email_custom.png" + attach_file "site_customization_image_image", file_fixture("logo_email_custom.png") click_button "Update" end @@ -92,7 +92,7 @@ describe "Admin custom images", :admin do visit admin_site_customization_images_path within("tr#image_social_media_icon") do - attach_file "site_customization_image_image", "spec/fixtures/files/logo_header.png" + attach_file "site_customization_image_image", file_fixture("logo_header.png") click_button "Update" end @@ -104,7 +104,7 @@ describe "Admin custom images", :admin do visit admin_site_customization_images_path within("tr#image_social_media_icon") do - attach_file "site_customization_image_image", "spec/fixtures/files/social_media_icon.png" + attach_file "site_customization_image_image", file_fixture("social_media_icon.png") click_button "Update" end diff --git a/spec/system/admin/widgets/cards_spec.rb b/spec/system/admin/widgets/cards_spec.rb index 650e374b3..ed299dd03 100644 --- a/spec/system/admin/widgets/cards_spec.rb +++ b/spec/system/admin/widgets/cards_spec.rb @@ -251,7 +251,7 @@ describe "Cards", :admin do def attach_image_to_card click_link "Add image" - attach_file "Choose image", Rails.root.join("spec/fixtures/files/clippy.jpg") + attach_file "Choose image", file_fixture("clippy.jpg") expect(page).to have_field("widget_card_image_attributes_title", with: "clippy.jpg") end diff --git a/spec/system/ckeditor_spec.rb b/spec/system/ckeditor_spec.rb index 03fc745b0..44d2a1096 100644 --- a/spec/system/ckeditor_spec.rb +++ b/spec/system/ckeditor_spec.rb @@ -33,7 +33,7 @@ describe "CKEditor" do click_link "Upload" within_frame(1) do - attach_file "Send it to the Server", Rails.root.join("spec/fixtures/files/clippy.jpg") + attach_file "Send it to the Server", file_fixture("clippy.jpg") end click_link "Send it to the Server" diff --git a/spec/system/legislation/proposals_spec.rb b/spec/system/legislation/proposals_spec.rb index cfeac71fa..80eef133f 100644 --- a/spec/system/legislation/proposals_spec.rb +++ b/spec/system/legislation/proposals_spec.rb @@ -146,7 +146,7 @@ describe "Legislation Proposals" do fill_in "Proposal title", with: "Legislation proposal with image" fill_in "Proposal summary", with: "Including an image on a legislation proposal" - imageable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.jpg")) + imageable_attach_new_file(file_fixture("clippy.jpg")) check "legislation_proposal_terms_of_service" click_button "Create proposal"