Sha256: 4829bc8fcf6a36edfe6e27bbb847ec883395c439f2efff5e039400b5248b4726

Contents?: true

Size: 1.02 KB

Versions: 24

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

FactoryBot.define do
  factory(
    :shipping_method,
    aliases: [
      :base_shipping_method
    ],
    class: 'Spree::ShippingMethod'
  ) do
    zones do
      [Spree::Zone.find_by(name: 'GlobalZone') || FactoryBot.create(:global_zone)]
    end

    name { 'UPS Ground' }
    code { 'UPS_GROUND' }
    carrier { 'UPS' }
    service_level { '1DAYGROUND' }

    calculator { |s| s.association(:shipping_calculator, strategy: :build, preferred_amount: s.cost, preferred_currency: s.currency) }

    transient do
      cost { 10.0 }
      currency { Spree::Config[:currency] }
    end

    before(:create) do |shipping_method, _evaluator|
      if shipping_method.shipping_categories.empty?
        shipping_method.shipping_categories << (Spree::ShippingCategory.first || create(:shipping_category))
      end
    end

    factory :free_shipping_method, class: 'Spree::ShippingMethod' do
      cost { nil }
      association(:calculator, factory: :shipping_no_amount_calculator, strategy: :build)
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
solidus_core-4.4.2 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.4.1 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.4.0 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.3.4 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.2.4 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.1.5 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.3.3 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.3.2 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.1.4 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.3.1 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.3.0 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.2.3 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.1.3 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.0.4 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.0.3 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.1.2 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.2.2 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.2.1 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.2.0 lib/spree/testing_support/factories/shipping_method_factory.rb
solidus_core-4.1.1 lib/spree/testing_support/factories/shipping_method_factory.rb