Sha256: eb1e20413403bbf26761df4c72ea8d5d5b105abefd5e33d85317dd608a2e7a88

Contents?: true

Size: 1.15 KB

Versions: 21

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

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

21 entries across 21 versions & 1 rubygems

Version Path
solidus_core-4.3.4 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.2.4 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.1.5 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.3.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.3.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.1.4 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.3.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.3.0 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.2.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.1.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.0.4 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.0.3 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.1.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.2.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.2.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.2.0 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.1.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.0.2 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.0.1 lib/spree/testing_support/factories/adjustment_factory.rb
solidus_core-4.1.0 lib/spree/testing_support/factories/adjustment_factory.rb