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

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

View File

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

View File

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