Sha256: 95d4baa3270c2ccd50814c382258c3b91e6f209dbe3b5bbb626dcf96e26c034f

Contents?: true

Size: 1.51 KB

Versions: 28

Compression:

Stored size: 1.51 KB

Contents

require 'test_helper'

module Workarea
  module Pricing
    class PriceTest < TestCase
      def sku
        @sku ||= Sku.new(id: 'SKU')
      end

      def test_validation_callback
        price = sku.prices.build(regular: nil)
        price.valid?
        assert_equal(0.to_m, price.regular)
      end

      def test_sell
        assert_equal(4.to_m, sku.prices.build(regular: 4).sell)

        sku.on_sale = true
        price = sku.prices.build(regular: 4, sale: 3)
        assert_equal(3.to_m, price.sell)

        sku.on_sale = false
        price = sku.prices.build(regular: 4)
        assert_equal(4.to_m, price.sell)
      end

      def test_generic
        price = Price.new
        assert(price.generic?)

        price.min_quantity = 2
        refute(price.generic?)
      end

      def test_on_sale
        price = sku.prices.build
        refute(price.on_sale?)

        sku.on_sale = true
        price.on_sale = true
        assert(price.on_sale?)

        sku.on_sale = true
        price.on_sale = false
        assert(price.on_sale?)

        sku.on_sale = false
        price.on_sale = true
        assert(price.on_sale?)

        sku.on_sale = false
        price.on_sale = false
        refute(price.on_sale?)
      end

      def test_unsupported_segmentation
        price = Price.new(active_segment_ids: %w(foo bar))
        refute(price.valid?)
        assert_includes(
          price.errors[:active_segment_ids],
          t('workarea.errors.messages.unsupported_segmentation')
        )
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.26 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.25 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.23 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.22 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.21 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.20 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.19 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.18 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.17 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.16 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.15 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.14 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.13 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.12 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.11 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.10 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.9 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.8 test/models/workarea/pricing/price_test.rb
workarea-core-3.5.7 test/models/workarea/pricing/price_test.rb