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.
This commit is contained in:
Javi Martín
2021-09-18 17:20:52 +02:00
parent 5ff66f96cd
commit 4f232c3a25
22 changed files with 73 additions and 80 deletions

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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']")

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"