Sha256: c81fb5054fe276c9a83cf036747529f7ca114876125bddded6c7a02dffb9faa9

Contents?: true

Size: 1.13 KB

Versions: 34

Compression:

Stored size: 1.13 KB

Contents

require 'test_helper'

module Workarea
  module Pricing
    class SkuTest < TestCase
      setup :configure_locales
      teardown :reset_locales

      def test_validations
        sku = Sku.new(id: 'SKU')
        sku.prices.build(regular: 5.to_m, min_quantity: 2)
        refute(sku.valid?)

        sku.prices.build(regular: 5.to_m, min_quantity: 1)
        assert(sku.valid?)
      end

      def test_find_price
        sku = Sku.new(id: 'SKU')
        sku.prices.build(min_quantity: 1, regular: 1.50)
        sku.prices.build(min_quantity: 5, regular: 1.25)

        assert_equal(1.25.to_m, sku.find_price(quantity: 5).regular)
      end

      def test_active_prices
        sku = create_pricing_sku
        price = sku.prices.create!(regular: 1.to_m)

        I18n.for_each_locale do |locale|
          assert_includes(sku.active_prices, price, "Price not active in #{locale}")
        end
      end

      private

      def configure_locales
        @original_locales = I18n.available_locales
        I18n.available_locales << :de
      end

      def reset_locales
        I18n.available_locales = @original_locales
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.44 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.43 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.42 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.41 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.40 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.39 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.38 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.37 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.36 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.35 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.34 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.33 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.32 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.31 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.30 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.29 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.28 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.27 test/models/workarea/pricing/sku_test.rb
workarea-core-3.4.26 test/models/workarea/pricing/sku_test.rb