Move address factory modification to address_factory file and make it always create a state and country in the address if they dont exist in the DB

This commit is contained in:
Luis Ramos
2020-08-06 10:11:47 +01:00
parent 43e64f3555
commit 6f17b80bb8
2 changed files with 9 additions and 5 deletions

View File

@@ -178,11 +178,6 @@ FactoryBot.define do
end
FactoryBot.modify do
factory :address do
state { Spree::State.find_by name: 'Victoria' }
country { Spree::Country.find_by name: 'Australia' || Spree::Country.first }
end
factory :credit_card do
cc_type 'visa'
end

View File

@@ -1,5 +1,14 @@
FactoryBot.modify do
factory :address do
state { Spree::State.find_by(name: 'Victoria') || Spree::State.first || create(:state) }
country do |address|
if address.state
address.state.country
else
Spree::Country.find_by(name: 'Australia') || Spree::Country.first || create(:country)
end
end
trait :randomized do
firstname { Faker::Name.first_name }
lastname { Faker::Name.last_name }