Sha256: 66dfb17fc08ba1aa203069f22fa267b73c31d6b49ce594800623e334a150ec6d

Contents?: true

Size: 1003 Bytes

Versions: 8

Compression:

Stored size: 1003 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

8 entries across 8 versions & 2 rubygems

Version Path
goca-spree-core-3.1.14.rails.5.0.1 lib/spree/testing_support/factories/customer_return_factory.rb
goca-spree-core-3.1.14.rails.5.0 lib/spree/testing_support/factories/customer_return_factory.rb
goca-spree-core-3.1.15.rails.5.0 lib/spree/testing_support/factories/customer_return_factory.rb
goca-spree-core-3.1.15.pre.rails.pre.5.0 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.2.9 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.3.6 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.2.8 lib/spree/testing_support/factories/customer_return_factory.rb
spree_core-3.3.5 lib/spree/testing_support/factories/customer_return_factory.rb