Remove hack to allow IO files in Active Storage

We were using this hack in order to allow `File.new` attachments in
tests files. However, we can use the `fixture_file_upload` helper
instead.

Just like it happened with `file_fixture`, this helper method doesn't
work in fixtures, so in this case we're using `Rack::Test::UploadedFile`
instead.
This commit is contained in:
Javi Martín
2021-09-18 17:37:54 +02:00
parent 4f232c3a25
commit 8eea6f585a
17 changed files with 43 additions and 48 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(file_fixture("clippy.png"))
image.attachment = fixture_file_upload("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(file_fixture("clippy.gif"))
image.attachment = fixture_file_upload("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(file_fixture("clippy.jpg"))
image.attachment = fixture_file_upload("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(file_fixture("logo_header.jpg"))
image.attachment = fixture_file_upload("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(file_fixture("empty.#{extension}"))
document.attachment = fixture_file_upload("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(file_fixture("clippy.#{extension}"))
image.attachment = fixture_file_upload("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(file_fixture("clippy.#{extension}"))
image.attachment = fixture_file_upload("clippy.#{extension}")
expect(image).not_to be_valid
end