Extract image_path out of factories block (#5038)

* Extract image_path out of factories block

* Move path back within the block
This commit is contained in:
Mac Siri 2019-12-09 15:39:25 -05:00 committed by Ben Halpern
parent b2872eb2f3
commit b9734583bb
3 changed files with 19 additions and 28 deletions

View file

@ -1,12 +1,9 @@
FactoryBot.define do
image = Rack::Test::UploadedFile.new(
Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg"),
"image/jpeg",
)
image_path = Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg")
factory :badge do
title { Faker::Book.title + " #{rand(1000)}" }
title { Faker::Book.title + " #{rand(1000)}" }
description { Faker::Lorem.sentence }
badge_image { image }
badge_image { Rack::Test::UploadedFile.new(image_path, "image/jpeg") }
end
end

View file

@ -1,14 +1,11 @@
FactoryBot.define do
sequence(:podcast_slug) { |n| "slug-#{n}" }
image = Rack::Test::UploadedFile.new(
Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg"),
"image/jpeg",
)
image_path = Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg")
factory :podcast do
title { Faker::Beer.name }
image { image }
image { Rack::Test::UploadedFile.new(image_path, "image/jpeg") }
description { Faker::Hipster.paragraph(sentence_count: 1) }
slug { generate :podcast_slug }
feed_url { Faker::Internet.url }

View file

@ -4,26 +4,23 @@ FactoryBot.define do
sequence(:twitter_username) { |n| "twitter#{n}" }
sequence(:github_username) { |n| "github#{n}" }
image = Rack::Test::UploadedFile.new(
Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg"),
"image/jpeg",
)
image_path = Rails.root.join("spec", "support", "fixtures", "images", "image1.jpeg")
factory :user do
name { Faker::Name.name }
email { generate :email }
username { generate :username }
profile_image { image }
twitter_username { generate :twitter_username }
github_username { generate :github_username }
summary { Faker::Lorem.paragraph[0..rand(190)] }
website_url { Faker::Internet.url }
confirmed_at { Time.current }
saw_onboarding { true }
checked_code_of_conduct { true }
name { Faker::Name.name }
email { generate :email }
username { generate :username }
profile_image { Rack::Test::UploadedFile.new(image_path, "image/jpeg") }
twitter_username { generate :twitter_username }
github_username { generate :github_username }
summary { Faker::Lorem.paragraph[0..rand(190)] }
website_url { Faker::Internet.url }
confirmed_at { Time.current }
saw_onboarding { true }
checked_code_of_conduct { true }
checked_terms_and_conditions { true }
signup_cta_variant { "navbar_basic" }
email_digest_periodic { false }
signup_cta_variant { "navbar_basic" }
email_digest_periodic { false }
after(:create) do |user|
create(:identity, user_id: user.id)