diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 73834c32d..05250b78c 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -36,6 +36,17 @@ def random_locales_attributes(**attribute_names_with_values) end end +def add_image_to(imageable, sample_image_files) + # imageable should respond to #title & #author + imageable.image = Image.create!({ + imageable: imageable, + title: imageable.title, + attachment: Rack::Test::UploadedFile.new(sample_image_files.sample), + user: imageable.author + }) + imageable.save! +end + log "Creating dev seeds for tenant #{Tenant.current_schema}" unless Tenant.default? load_dev_seeds "settings" diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 9a4bea0d9..bdae27338 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -1,27 +1,20 @@ -INVESTMENT_IMAGE_FILES = %w[ - brennan-ehrhardt-25066-unsplash_713x513.jpg - carl-nenzen-loven-381554-unsplash_713x475.jpg - carlos-zurita-215387-unsplash_713x475.jpg - hector-arguello-canals-79584-unsplash_713x475.jpg - olesya-grichina-218176-unsplash_713x475.jpg - sole-d-alessandro-340443-unsplash_713x475.jpg -].map do |filename| - Rails.root.join("db", - "dev_seeds", - "images", - "budget", - "investments", filename) -end +def add_image_to_investment(investment) + image_files = %w[ + brennan-ehrhardt-25066-unsplash_713x513.jpg + carl-nenzen-loven-381554-unsplash_713x475.jpg + carlos-zurita-215387-unsplash_713x475.jpg + hector-arguello-canals-79584-unsplash_713x475.jpg + olesya-grichina-218176-unsplash_713x475.jpg + sole-d-alessandro-340443-unsplash_713x475.jpg + ].map do |filename| + Rails.root.join("db", + "dev_seeds", + "images", + "budget", + "investments", filename) + end -def add_image_to(imageable) - # imageable should respond to #title & #author - imageable.image = Image.create!({ - imageable: imageable, - title: imageable.title, - attachment: Rack::Test::UploadedFile.new(INVESTMENT_IMAGE_FILES.sample), - user: imageable.author - }) - imageable.save! + add_image_to(investment, image_files) end section "Creating Budgets" do @@ -122,7 +115,7 @@ section "Creating Investments" do terms_of_service: "1" }.merge(translation_attributes)) - add_image_to(investment) if Random.rand > 0.5 + add_image_to_investment(investment) if Random.rand > 0.5 end end @@ -167,7 +160,7 @@ section "Winner Investments" do price: rand(10000..heading.price), terms_of_service: "1" ) - add_image_to(investment) if Random.rand > 0.3 + add_image_to_investment(investment) if Random.rand > 0.3 end budget.headings.each do |heading| Budget::Result.new(budget, heading).calculate_winners diff --git a/db/dev_seeds/proposals.rb b/db/dev_seeds/proposals.rb index 453960ded..61caf0773 100644 --- a/db/dev_seeds/proposals.rb +++ b/db/dev_seeds/proposals.rb @@ -1,24 +1,17 @@ -IMAGE_FILES = %w[ - firdouss-ross-414668-unsplash_846x475.jpg - nathan-dumlao-496190-unsplash_713x475.jpg - steve-harvey-597760-unsplash_713x475.jpg - tim-mossholder-302931-unsplash_713x475.jpg -].map do |filename| - Rails.root.join("db", - "dev_seeds", - "images", - "proposals", filename) -end +def add_image_to_proposal(proposal) + image_files = %w[ + firdouss-ross-414668-unsplash_846x475.jpg + nathan-dumlao-496190-unsplash_713x475.jpg + steve-harvey-597760-unsplash_713x475.jpg + tim-mossholder-302931-unsplash_713x475.jpg + ].map do |filename| + Rails.root.join("db", + "dev_seeds", + "images", + "proposals", filename) + end -def add_image_to(imageable) - # imageable should respond to #title & #author - imageable.image = Image.create!({ - imageable: imageable, - title: imageable.title, - attachment: Rack::Test::UploadedFile.new(IMAGE_FILES.sample), - user: imageable.author - }) - imageable.save! + add_image_to(proposal, image_files) end section "Creating Proposals" do @@ -47,7 +40,7 @@ section "Creating Proposals" do proposal.save! end end - add_image_to proposal + add_image_to_proposal proposal end end @@ -75,7 +68,7 @@ section "Creating Archived Proposals" do proposal.save! end end - add_image_to proposal + add_image_to_proposal proposal end end @@ -103,7 +96,7 @@ section "Creating Successful Proposals" do proposal.save! end end - add_image_to proposal + add_image_to_proposal proposal end tags = Tag.where(kind: "category") @@ -128,7 +121,7 @@ section "Creating Successful Proposals" do proposal.save! end end - add_image_to proposal + add_image_to_proposal proposal end end