Use variables instead of constants in dev seeds
While running the `dev_seed` twice, as we do in the tests, we were getting the following warnings: ``` db/dev_seeds/proposals.rb:1: warning: already initialized constant IMAGE_FILES db/dev_seeds/budgets.rb:1: warning: already initialized constant INVESTMENT_IMAGE_FILES ``` So we're extracting a method which allows us to use local variables while removing duplication. We had this warning with every version of Ruby, not just Ruby 2.7, but since we're getting rid of all the warnings, we're taking care of this one as well.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
INVESTMENT_IMAGE_FILES = %w[
|
||||
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
|
||||
@@ -13,15 +14,7 @@ INVESTMENT_IMAGE_FILES = %w[
|
||||
"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
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
IMAGE_FILES = %w[
|
||||
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
|
||||
@@ -10,15 +11,7 @@ IMAGE_FILES = %w[
|
||||
"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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user