Sha256: 707bfcc42b0141cb251156ac57200d5df496bd4493bcc0fd7d0d1937d378d38b

Contents?: true

Size: 1.98 KB

Versions: 29

Compression:

Stored size: 1.98 KB

Contents

class OrderWalkthrough
  def self.up_to(state)
    # A default store must exist to provide store settings
    unless Spree::Store.exists?
      FactoryGirl.create(:store)
    end

    # A payment method must exist for an order to proceed through the Address state
    unless Spree::PaymentMethod.exists?
      FactoryGirl.create(:check_payment_method)
    end

    # Need to create a valid zone too...
    zone = FactoryGirl.create(:zone)
    country = FactoryGirl.create(:country)
    zone.members << Spree::ZoneMember.create(:zoneable => country)
    country.states << FactoryGirl.create(:state, :country => country)

    # A shipping method must exist for rates to be displayed on checkout page
    unless Spree::ShippingMethod.exists?
      FactoryGirl.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: "spree@example.com")
    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

  private

  def self.add_line_item!(order)
    FactoryGirl.create(:line_item, order: order)
    order.reload
  end

  def self.address(order)
    order.bill_address = FactoryGirl.create(:address, :country_id => Spree::Zone.global.members.first.zoneable.id)
    order.ship_address = FactoryGirl.create(:address, :country_id => Spree::Zone.global.members.first.zoneable.id)
    order.next!
  end

  def self.delivery(order)
    order.next!
  end

  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

  def self.complete(order)
    #noop?
  end

  def self.states
    [:address, :delivery, :payment, :complete]
  end

end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
spree_core-3.1.14 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.13 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.12 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.11 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.10 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.9 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.8 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.7 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.6 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.5 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.4 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.3 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.2 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.0.10 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.1 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.0 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.0.rc4 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.0.9 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.0.rc3 lib/spree/testing_support/order_walkthrough.rb
spree_core-3.1.0.rc2 lib/spree/testing_support/order_walkthrough.rb