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

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