From e08b516284a383a1e8d90430a4dbd0721516df11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 2 Nov 2019 00:01:49 +0100 Subject: [PATCH] Reduce changelog entries generated by dev seeds Since we were saving the same budget investments several times, once for every language, we were creating more than 1000 changelog entries. Assigning the language attributes when creating the investments generates less entries, making it easier to work with them. --- db/dev_seeds/budgets.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 3904ee694..a1e4738f2 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -121,13 +121,16 @@ section "Creating Investments" do 100.times do heading = Budget::Heading.all.sample - investment = Budget::Investment.create!( + translation_attributes = random_locales.each_with_object({}) do |locale, attributes| + attributes["title_#{locale.to_s.underscore}"] = "Title for locale #{locale}" + attributes["description_#{locale.to_s.underscore}"] = "

Description for locale #{locale}

" + end + + investment = Budget::Investment.create!({ author: User.all.sample, heading: heading, group: heading.group, budget: heading.group.budget, - title: Faker::Lorem.sentence(3).truncate(60), - description: "

#{Faker::Lorem.paragraphs.join("

")}

", created_at: rand((Time.current - 1.week)..Time.current), feasibility: %w[undecided unfeasible feasible feasible feasible feasible].sample, unfeasibility_explanation: Faker::Lorem.paragraph, @@ -136,15 +139,7 @@ section "Creating Investments" do price: rand(1..100) * 100000, skip_map: "1", terms_of_service: "1" - ) - - random_locales.map do |locale| - Globalize.with_locale(locale) do - investment.title = "Title for locale #{locale}" - investment.description = "

Description for locale #{locale}

" - investment.save! - end - end + }.merge(translation_attributes)) add_image_to(investment) if Random.rand > 0.5 end