Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move factory_bot static attrs to dynamic #2831

Merged
merged 1 commit into from
Sep 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions core/lib/spree/testing_support/factories/address_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
factory :address, class: 'Spree::Address' do
transient do
# There's `Spree::Address#country_iso=`, prohibiting me from using `country_iso` here
country_iso_code 'US'
state_code 'AL'
country_iso_code { 'US' }
state_code { 'AL' }
end

firstname 'John'
lastname nil
company 'Company'
address1 '10 Lovely Street'
address2 'Northwest'
city 'Herndon'
firstname { 'John' }
lastname { nil }
company { 'Company' }
address1 { '10 Lovely Street' }
address2 { 'Northwest' }
city { 'Herndon' }
sequence(:zipcode, 10001) { |i| i.to_s }
phone '555-555-0199'
alternative_phone '555-555-0199'
phone { '555-555-0199' }
alternative_phone { '555-555-0199' }

state do |address|
Spree::State.joins(:country).where('spree_countries.iso = (?)', country_iso_code).find_by(abbr: state_code) ||
Expand All @@ -36,10 +36,10 @@
end

factory :ship_address, parent: :address do
address1 'A Different Road'
address1 { 'A Different Road' }
end

factory :bill_address, parent: :address do
address1 'PO Box 1337'
address1 { 'PO Box 1337' }
end
end
10 changes: 5 additions & 5 deletions core/lib/spree/testing_support/factories/adjustment_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
factory :adjustment, class: 'Spree::Adjustment' do
order
adjustable { order }
amount 100.0
label 'Shipping'
amount { 100.0 }
label { 'Shipping' }
association(:source, factory: :tax_rate)
eligible true
eligible { true }

after(:build) do |adjustment|
adjustments = adjustment.adjustable.adjustments
Expand All @@ -25,8 +25,8 @@
factory :tax_adjustment, class: 'Spree::Adjustment' do
order { adjustable.order }
association(:adjustable, factory: :line_item)
amount 10.0
label 'VAT 5%'
amount { 10.0 }
label { 'VAT 5%' }

after(:create) do |adjustment|
# Set correct tax category, so that adjustment amount is not 0
Expand Down
10 changes: 5 additions & 5 deletions core/lib/spree/testing_support/factories/calculator_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

FactoryBot.define do
factory :calculator, aliases: [:flat_rate_calculator], class: 'Spree::Calculator::FlatRate' do
preferred_amount 10.0
preferred_amount { 10.0 }
end

factory :no_amount_calculator, class: 'Spree::Calculator::FlatRate' do
preferred_amount 0
preferred_amount { 0 }
end

factory :default_tax_calculator, class: 'Spree::Calculator::DefaultTax' do
end

factory :shipping_calculator, class: 'Spree::Calculator::Shipping::FlatRate' do
preferred_amount 10.0
preferred_amount { 10.0 }
end

factory :shipping_no_amount_calculator, class: 'Spree::Calculator::Shipping::FlatRate' do
preferred_amount 0
preferred_amount { 0 }
end

factory :percent_on_item_calculator, class: 'Spree::Calculator::PercentOnLineItem' do
preferred_percent 10
preferred_percent { 10 }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

FactoryBot.define do
factory :country, class: 'Spree::Country' do
iso 'US'
iso { 'US' }

transient do
carmen_country { Carmen::Country.coded(iso) || fail("Unknown country iso code: #{iso.inspect}") }
Expand Down
10 changes: 5 additions & 5 deletions core/lib/spree/testing_support/factories/credit_card_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

FactoryBot.define do
factory :credit_card, class: 'Spree::CreditCard' do
verification_value 123
month 12
verification_value { 123 }
month { 12 }
year { 1.year.from_now.year }
number '4111111111111111'
name 'Spree Commerce'
number { '4111111111111111' }
name { 'Spree Commerce' }
association(:payment_method, factory: :credit_card_payment_method)
association(:address)

trait :failing do
number "0000000000000000"
number { "0000000000000000" }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
association(:stock_location, factory: :stock_location)

transient do
line_items_count 1
line_items_count { 1 }
return_items_count { line_items_count }
shipped_order { create :shipped_order, line_items_count: line_items_count }
return_authorization { create :return_authorization, order: shipped_order }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
FactoryBot.define do
factory :inventory_unit, class: 'Spree::InventoryUnit' do
transient do
order nil
order { nil }
end

variant
Expand All @@ -19,7 +19,7 @@
build(:line_item, variant: variant)
end
end
state 'on_hand'
state { 'on_hand' }
shipment { build(:shipment, state: 'pending', order: line_item.order) }
# return_authorization
end
Expand Down
4 changes: 2 additions & 2 deletions core/lib/spree/testing_support/factories/line_item_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

FactoryBot.define do
factory :line_item, class: 'Spree::LineItem' do
quantity 1
quantity { 1 }
price { BigDecimal('10.00') }
order
transient do
product nil
product { nil }
end
variant do
(product || create(:product)).master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
FactoryBot.define do
factory :option_type, class: 'Spree::OptionType' do
sequence(:name) { |n| "foo-size-#{n}" }
presentation 'Size'
presentation { 'Size' }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
factory :option_value, class: 'Spree::OptionValue' do
sequence(:name) { |n| "Size-#{n}" }

presentation 'S'
presentation { 'S' }
option_type
end
end
26 changes: 13 additions & 13 deletions core/lib/spree/testing_support/factories/order_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
user
bill_address
ship_address
completed_at nil
completed_at { nil }
email { user.try(:email) }
store

Expand Down Expand Up @@ -40,10 +40,10 @@
ship_address

transient do
line_items_count 1
line_items_count { 1 }
line_items_attributes { [{}] * line_items_count }
shipment_cost 100
shipping_method nil
shipment_cost { 100 }
shipping_method { nil }
stock_location { create(:stock_location) }
end

Expand All @@ -64,7 +64,7 @@

factory :completed_order_with_promotion do
transient do
promotion nil
promotion { nil }
end

after(:create) do |order, evaluator|
Expand All @@ -81,11 +81,11 @@
end

factory :order_ready_to_complete do
state 'confirm'
payment_state 'checkout'
state { 'confirm' }
payment_state { 'checkout' }

transient do
payment_type :credit_card_payment
payment_type { :credit_card_payment }
end

after(:create) do |order, evaluator|
Expand All @@ -100,7 +100,7 @@
end

factory :completed_order_with_totals do
state 'complete'
state { 'complete' }

after(:create) do |order|
order.shipments.each do |shipment|
Expand All @@ -116,11 +116,11 @@
end

factory :order_ready_to_ship do
payment_state 'paid'
shipment_state 'ready'
payment_state { 'paid' }
shipment_state { 'ready' }

transient do
payment_type :credit_card_payment
payment_type { :credit_card_payment }
end

after(:create) do |order, evaluator|
Expand All @@ -133,7 +133,7 @@

factory :shipped_order do
transient do
with_cartons true
with_cartons { true }
end
after(:create) do |order, evaluator|
order.shipments.each do |shipment|
Expand Down
12 changes: 6 additions & 6 deletions core/lib/spree/testing_support/factories/payment_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@
association(:payment_method, factory: :credit_card_payment_method)
source { create(:credit_card, user: order.user, address: order.bill_address) }
order
state 'checkout'
response_code '12345'
state { 'checkout' }
response_code { '12345' }

trait :completed do
state 'completed'
state { 'completed' }
end

trait :failing do
response_code '00000'
response_code { '00000' }
association(:source, :failing, { factory: :credit_card })
end

factory :payment_with_refund do
transient do
refund_amount 5
refund_amount { 5 }
end

amount { refund_amount }

state 'completed'
state { 'completed' }

refunds { build_list :refund, 1, amount: refund_amount }
end
Expand Down
30 changes: 15 additions & 15 deletions core/lib/spree/testing_support/factories/payment_method_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

FactoryBot.define do
factory :payment_method, aliases: [:credit_card_payment_method], class: 'Spree::PaymentMethod::BogusCreditCard' do
name 'Credit Card'
available_to_admin true
available_to_users true
name { 'Credit Card' }
available_to_admin { true }
available_to_users { true }
end

factory :check_payment_method, class: 'Spree::PaymentMethod::Check' do
name 'Check'
available_to_admin true
available_to_users true
name { 'Check' }
available_to_admin { true }
available_to_users { true }
end

# authorize.net was moved to spree_gateway.
# Leaving this factory in place with bogus in case anyone is using it.
factory :simple_credit_card_payment_method, class: 'Spree::PaymentMethod::SimpleBogusCreditCard' do
name 'Credit Card'
available_to_admin true
available_to_users true
name { 'Credit Card' }
available_to_admin { true }
available_to_users { true }
end

factory :store_credit_payment_method, class: 'Spree::PaymentMethod::StoreCredit' do
name "Store Credit"
description "Store Credit"
active true
available_to_admin false
available_to_users false
auto_capture true
name { "Store Credit" }
description { "Store Credit" }
active { true }
available_to_admin { false }
available_to_users { false }
auto_capture { true }
end
end
4 changes: 2 additions & 2 deletions core/lib/spree/testing_support/factories/price_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
FactoryBot.define do
factory :price, class: 'Spree::Price' do
variant
amount 19.99
currency 'USD'
amount { 19.99 }
currency { 'USD' }
end
end
12 changes: 6 additions & 6 deletions core/lib/spree/testing_support/factories/product_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
FactoryBot.define do
factory :base_product, class: 'Spree::Product' do
sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
description "As seen on TV!"
price 19.99
cost_price 17.00
description { "As seen on TV!" }
price { 19.99 }
cost_price { 17.00 }
sku { generate(:sku) }
available_on { 1.year.ago }
deleted_at nil
deleted_at { nil }
shipping_category { |r| Spree::ShippingCategory.first || r.association(:shipping_category) }

# ensure stock item will be created for this products master
before(:create) { create(:stock_location) if Spree::StockLocation.count == 0 }

factory :custom_product do
name 'Custom Product'
price 17.99
name { 'Custom Product' }
price { 17.99 }

tax_category { |r| Spree::TaxCategory.first || r.association(:tax_category) }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

FactoryBot.define do
factory :promotion_category, class: 'Spree::PromotionCategory' do
name 'Promotion Category'
name { 'Promotion Category' }
end
end
Loading