Sha256: c3dea649c2e3eb49c4c628ad90c55431606eb66a0b32100efdb4be3333187b2d

Contents?: true

Size: 1007 Bytes

Versions: 69

Compression:

Stored size: 1007 Bytes

Contents

FactoryBot.define do
  factory :customer_return, class: Spree::CustomerReturn do
    association(:stock_location, factory: :stock_location)

    transient do
      line_items_count   { 1 }
      return_items_count { line_items_count }
    end

    before(:create) do |customer_return, evaluator|
      shipped_order = create(:shipped_order, line_items_count: evaluator.line_items_count)

      shipped_order.inventory_units.take(evaluator.return_items_count).each do |inventory_unit|
        customer_return.return_items << build(:return_item, inventory_unit: inventory_unit)
      end
    end

    factory :customer_return_with_accepted_items do
      after(:create) do |customer_return|
        customer_return.return_items.each(&:accept!)
      end
    end
  end

  # for the case when you want to supply existing return items instead of generating some
  factory :customer_return_without_return_items, class: Spree::CustomerReturn do
    association(:stock_location, factory: :stock_location)
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
spree_core-4.0.0.beta lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.4 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.3 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.2 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.1 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.0 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.0.rc3 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.0.rc2 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.7.0.rc1 lib/spree/testing_support/factories/customer_return_factory.rb