Sha256: 2c6764b0df77274b1e93a4d6b688686a8bb84fdc07f712499e88eb174e28fb1b

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'spree/testing_support/factories/order_factory'

FactoryGirl.define do
  # The order with line items factory was updated in 1.2 to take a stock
  # location as a transient attribute. This brings that change so we can
  # specify the stock location which is used for the origin address for packages
  # and can be removed when we no longer want to support Solidus 1.0 and 1.1.
  factory :order_with_line_items_and_stock_location, parent: :order do
    bill_address
    ship_address

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

    after(:create) do |order, evaluator|
      evaluator.stock_location # must evaluate before creating line items

      evaluator.line_items_attributes.each do |attributes|
        attributes = {
          order: order,
          price: evaluator.line_items_price
        }.merge(attributes)

        create(:line_item, attributes)
      end
      order.line_items.reload

      create(
        :shipment,
        order: order,
        cost: evaluator.shipment_cost,
        shipping_method: evaluator.shipping_method,
        stock_location: evaluator.stock_location
      )

      order.shipments.reload

      order.update!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_active_shipping-1.0.0 spec/factories/order_factory_override.rb