Class: OrderWalkthrough
- Inherits:
-
Object
- Object
- OrderWalkthrough
- Defined in:
- lib/spree/testing_support/order_walkthrough.rb
Class Method Summary collapse
- .add_line_item!(order) ⇒ Object
- .address(order) ⇒ Object
- .complete(_order) ⇒ Object
- .delivery(order) ⇒ Object
- .payment(order) ⇒ Object
- .states ⇒ Object
- .up_to(state) ⇒ Object
Class Method Details
.add_line_item!(order) ⇒ Object
40 41 42 43 |
# File 'lib/spree/testing_support/order_walkthrough.rb', line 40 def self.add_line_item!(order) FactoryBot.create(:line_item, order: order) order.reload end |
.address(order) ⇒ Object
45 46 47 48 49 |
# File 'lib/spree/testing_support/order_walkthrough.rb', line 45 def self.address(order) order.bill_address = FactoryBot.create(:address, country_id: Spree::Zone.global.members.first.zoneable.id) order.ship_address = FactoryBot.create(:address, country_id: Spree::Zone.global.members.first.zoneable.id) order.next! end |
.complete(_order) ⇒ Object
62 63 64 |
# File 'lib/spree/testing_support/order_walkthrough.rb', line 62 def self.complete(_order) # noop? end |
.delivery(order) ⇒ Object
51 52 53 |
# File 'lib/spree/testing_support/order_walkthrough.rb', line 51 def self.delivery(order) order.next! end |
.payment(order) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/spree/testing_support/order_walkthrough.rb', line 55 def self.payment(order) order.payments.create!(payment_method: Spree::PaymentMethod.first, amount: order.total) # TODO: maybe look at some way of making this payment_state change automatic order.payment_state = 'paid' order.next! end |
.states ⇒ Object
66 67 68 |
# File 'lib/spree/testing_support/order_walkthrough.rb', line 66 def self.states [:address, :delivery, :payment, :complete] end |
.up_to(state) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/spree/testing_support/order_walkthrough.rb', line 2 def self.up_to(state) # A default store must exist to provide store settings FactoryBot.create(:store) unless Spree::Store.exists? # A payment method must exist for an order to proceed through the Address state unless Spree::PaymentMethod.exists? FactoryBot.create(:check_payment_method) end # Need to create a valid zone too... zone = FactoryBot.create(:zone) country = FactoryBot.create(:country) zone.members << Spree::ZoneMember.create(zoneable: country) country.states << FactoryBot.create(:state, country: country) # A shipping method must exist for rates to be displayed on checkout page unless Spree::ShippingMethod.exists? FactoryBot.create(:shipping_method).tap do |sm| sm.calculator.preferred_amount = 10 sm.calculator.preferred_currency = Spree::Config[:currency] sm.calculator.save end end order = Spree::Order.create!(email: '[email protected]') add_line_item!(order) order.next! end_state_position = states.index(state.to_sym) states[0...end_state_position].each do |state| send(state, order) end order end |