Sha256: be0e494dca83560e8dcbb7ecf4251a724d174f65a7de0717084da68685d0eade

Contents?: true

Size: 1.33 KB

Versions: 48

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factories/stock_location_factory'
require 'spree/testing_support/factories/order_factory'
require 'spree/testing_support/factories/return_item_factory'

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 }
      shipped_order { create :shipped_order, line_items_count: line_items_count }
      return_authorization { create :return_authorization, order: shipped_order }
    end

    before(:create) do |customer_return, evaluator|
      evaluator.shipped_order.inventory_units.take(evaluator.return_items_count).each do |inventory_unit|
        customer_return.return_items << build(:return_item, inventory_unit: inventory_unit, return_authorization: evaluator.return_authorization)
      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

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.6.5 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.9.1 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.9.0 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.9.0.rc.1 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.8.4 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.8.3 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.7.2 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.6.4 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.8.2 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.8.1 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.6.3 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.8.0 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core-2.7.1 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 lib/spree/testing_support/factories/customer_return_factory.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 lib/spree/testing_support/factories/customer_return_factory.rb