class Spree::TestingSupport::OrderWalkthrough
Public Class Methods
up_to(state)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 6 def self.up_to(state) new.up_to(state) end
Public Instance Methods
up_to(state)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 10 def up_to(state) # Need to create a valid zone too... @zone = ::FactoryBot.create(:zone) @country = ::FactoryBot.create(:country) @state = ::FactoryBot.create(:state, country: @country) @zone.members << Spree::ZoneMember.create(zoneable: @country) # A shipping method must exist for rates to be displayed on checkout page ::FactoryBot.create(:shipping_method, zones: [@zone]).tap do |sm| sm.calculator.preferred_amount = 10 sm.calculator.preferred_currency = Spree::Config[:currency] sm.calculator.save end order = Spree::Order.create!( email: "solidus@example.com", store: Spree::Store.first || ::FactoryBot.create(:store) ) add_line_item!(order) order.next! states_to_process = if state == :complete states else end_state_position = states.index(state.to_sym) states[0..end_state_position] end states_to_process.each do |state_to_process| send(state_to_process, order) end order end
Private Instance Methods
add_line_item!(order)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 48 def add_line_item!(order) ::FactoryBot.create(:line_item, order: order) order.reload end
address(order)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 53 def address(order) order.bill_address = ::FactoryBot.create(:address, country: @country, state: @state) order.ship_address = ::FactoryBot.create(:address, country: @country, state: @state) order.next! end
complete(order)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 75 def complete(order) # noop? end
confirm(order)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 71 def confirm(order) order.complete! end
delivery(order)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 59 def delivery(order) order.next! end
payment(order)
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 63 def payment(order) credit_card = ::FactoryBot.create(:credit_card) order.payments.create!(payment_method: credit_card.payment_method, amount: order.total, source: credit_card) # TODO: maybe look at some way of making this payment_state change automatic order.payment_state = 'paid' order.next! end
states()
click to toggle source
# File lib/spree/testing_support/order_walkthrough.rb, line 79 def states [:address, :delivery, :payment, :confirm] end