Skip to content

Commit

Permalink
Merge pull request #622 from Dkendal/refactor/fix-invalid-factories
Browse files Browse the repository at this point in the history
Fix some broken factories
  • Loading branch information
jordan-brough committed Jan 1, 2016
2 parents 22edfa8 + 4ca4d8f commit 4272125
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryGirl.define do
factory :adjustment, class: Spree::Adjustment do
association(:adjustable, factory: :order)
order
adjustable { order }
amount 100.0
label 'Shipping'
association(:source, factory: :tax_rate)
Expand Down
2 changes: 2 additions & 0 deletions core/lib/spree/testing_support/factories/payment_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
refund_amount 5
end

amount { refund_amount }

state 'completed'

refunds { build_list :refund, 1, amount: refund_amount }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
FactoryGirl.define do
factory :base_shipping_method, class: Spree::ShippingMethod do
factory(
:shipping_method,
aliases: [
:base_shipping_method
],
class: Spree::ShippingMethod
) do
zones { |a| [Spree::Zone.global] }
name 'UPS Ground'
code 'UPS_GROUND'

calculator { |s| s.association(:shipping_calculator, strategy: :build, preferred_amount: s.cost) }

transient do
cost 10.0
end

before(:create) do |shipping_method, evaluator|
if shipping_method.shipping_categories.empty?
shipping_method.shipping_categories << (Spree::ShippingCategory.first || create(:shipping_category))
end
end

factory :shipping_method, class: Spree::ShippingMethod do
transient do
cost 10.0
end

calculator { |s| s.association(:shipping_calculator, strategy: :build, preferred_amount: s.cost) }
end

factory :free_shipping_method, class: Spree::ShippingMethod do
cost nil
association(:calculator, factory: :shipping_no_amount_calculator, strategy: :build)
end
end
Expand Down
5 changes: 4 additions & 1 deletion core/lib/spree/testing_support/factories/stock_factory.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryGirl.define do
# must use build()
factory :stock_packer, class: Spree::Stock::Packer do
skip_create

transient do
stock_location { build(:stock_location) }
contents []
Expand All @@ -10,6 +11,8 @@
end

factory :stock_package, class: Spree::Stock::Package do
skip_create

transient do
stock_location { build(:stock_location) }
contents { [] }
Expand Down

0 comments on commit 4272125

Please sign in to comment.