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:
@@ -15,14 +15,12 @@ end
|
||||
|
||||
def add_image_to(imageable)
|
||||
# imageable should respond to #title & #author
|
||||
File.open(INVESTMENT_IMAGE_FILES.sample) do |file|
|
||||
imageable.image = Image.create!({
|
||||
imageable: imageable,
|
||||
title: imageable.title,
|
||||
attachment: file,
|
||||
user: imageable.author
|
||||
})
|
||||
end
|
||||
imageable.image = Image.create!({
|
||||
imageable: imageable,
|
||||
title: imageable.title,
|
||||
attachment: Rack::Test::UploadedFile.new(INVESTMENT_IMAGE_FILES.sample),
|
||||
user: imageable.author
|
||||
})
|
||||
imageable.save!
|
||||
end
|
||||
|
||||
|
||||
@@ -12,14 +12,12 @@ end
|
||||
|
||||
def add_image_to(imageable)
|
||||
# imageable should respond to #title & #author
|
||||
File.open(IMAGE_FILES.sample) do |file|
|
||||
imageable.image = Image.create!({
|
||||
imageable: imageable,
|
||||
title: imageable.title,
|
||||
attachment: file,
|
||||
user: imageable.author
|
||||
})
|
||||
end
|
||||
imageable.image = Image.create!({
|
||||
imageable: imageable,
|
||||
title: imageable.title,
|
||||
attachment: Rack::Test::UploadedFile.new(IMAGE_FILES.sample),
|
||||
user: imageable.author
|
||||
})
|
||||
imageable.save!
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
section "Creating header and cards for the homepage" do
|
||||
def create_image_attachment(type)
|
||||
{
|
||||
attachment: File.new(Rails.root.join("db/dev_seeds/images/#{type}_background.jpg")),
|
||||
attachment: Rack::Test::UploadedFile.new("db/dev_seeds/images/#{type}_background.jpg"),
|
||||
title: "#{type}_background.jpg",
|
||||
user: User.first
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user