Sha256: d936aa260a4f86ae332aae2b815c56b56c88c746b2fdb6550e4aef6d2125755f

Contents?: true

Size: 1.2 KB

Versions: 48

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factories/calculator_factory'
require 'spree/testing_support/factories/shipping_category_factory'
require 'spree/testing_support/factories/zone_factory'

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

48 entries across 48 versions & 2 rubygems

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