Files
grecia/db/dev_seeds/widgets.rb
Javi Martín 8eea6f585a 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.
2022-02-23 19:00:33 +01:00

58 lines
1.6 KiB
Ruby

section "Creating header and cards for the homepage" do
def create_image_attachment(type)
{
attachment: Rack::Test::UploadedFile.new("db/dev_seeds/images/#{type}_background.jpg"),
title: "#{type}_background.jpg",
user: User.first
}
end
Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].map do |attribute|
[attribute, -> { I18n.t("seeds.cards.header.#{attribute}") }]
end.to_h
).merge(
link_url: "http://consulproject.org/",
header: true,
image_attributes: create_image_attachment("header")
)
)
Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].map do |attribute|
[attribute, -> { I18n.t("seeds.cards.debate.#{attribute}") }]
end.to_h
).merge(
link_url: "https://youtu.be/zU_0UN4VajY",
header: false,
image_attributes: create_image_attachment("debate")
)
)
Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].map do |attribute|
[attribute, -> { I18n.t("seeds.cards.proposal.#{attribute}") }]
end.to_h
).merge(
link_url: "https://youtu.be/ZHqBpT4uCoM",
header: false,
image_attributes: create_image_attachment("proposal")
)
)
Widget::Card.create!(
random_locales_attributes(
%i[title description link_text label].map do |attribute|
[attribute, -> { I18n.t("seeds.cards.budget.#{attribute}") }]
end.to_h
).merge(
link_url: "https://youtu.be/igQ8KGZdk9c",
header: false,
image_attributes: create_image_attachment("budget")
)
)
end