Sha256: f7b69d8dd26507cd85db0f045c5818ba51bf80ee1ac34935cbfa6f3b4415012f

Contents?: true

Size: 1.6 KB

Versions: 56

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factory_bot'
Spree::TestingSupport::FactoryBot.when_cherry_picked do
  Spree::TestingSupport::FactoryBot.deprecate_cherry_picking

  require 'spree/testing_support/factories/line_item_factory'
  require 'spree/testing_support/factories/order_factory'
  require 'spree/testing_support/factories/tax_category_factory'
  require 'spree/testing_support/factories/tax_rate_factory'
  require 'spree/testing_support/factories/zone_factory'
end

FactoryBot.define do
  factory :adjustment, class: 'Spree::Adjustment' do
    order
    adjustable { order }
    amount { 100.0 }
    label { 'Shipping' }
    association(:source, factory: :tax_rate)
    eligible { true }

    after(:build) do |adjustment|
      adjustments = adjustment.adjustable.adjustments
      if adjustments.loaded? && !adjustments.include?(adjustment)
        adjustments.proxy_association.add_to_target(adjustment)
      end
    end

    factory :tax_adjustment, class: 'Spree::Adjustment' do
      order { adjustable.order }
      association(:adjustable, factory: :line_item)
      amount { 10.0 }
      label { 'VAT 5%' }

      after(:create) do |adjustment|
        # Set correct tax category, so that adjustment amount is not 0
        if adjustment.adjustable.is_a?(Spree::LineItem)
          if adjustment.adjustable.tax_category.present?
            adjustment.source.tax_categories = [adjustment.adjustable.tax_category]
          else
            adjustment.source.tax_categories = []
          end
          adjustment.source.save
          adjustment.recalculate
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
solidus_core-3.0.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.1.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.1.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.1.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.1.0 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.11 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.0.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.10 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.0.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.0.0 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.9 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.8 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.7 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.6 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-3.0.0.rc2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-2.11.5 lib/spree/testing_support/factories/adjustment_factory.rb