Sha256: 827a91ca92fb6f3e5f8fd23fc7c94d0f1a9c331f82bdf91b5a5288b9e501890b

Contents?: true

Size: 1.4 KB

Versions: 32

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

module Spree
  module PromotionHandler
    describe Page, type: :model do
      let(:order) { create(:order_with_line_items, line_items_count: 1) }

      let(:promotion) { Promotion.create(name: "10% off", path: '10off') }
      before do
        calculator = Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
        action = Promotion::Actions::CreateItemAdjustments.create(calculator: calculator)
        promotion.actions << action
      end

      it "activates at the right path" do
        expect(order.line_item_adjustments.count).to eq(0)
        Spree::PromotionHandler::Page.new(order, '10off').activate
        expect(order.line_item_adjustments.count).to eq(1)
      end

      context "when promotion is expired" do
        before do
          promotion.update_columns(
            starts_at: 1.week.ago,
            expires_at: 1.day.ago
          )
        end

        it "is not activated" do
          expect(order.line_item_adjustments.count).to eq(0)
          Spree::PromotionHandler::Page.new(order, '10off').activate
          expect(order.line_item_adjustments.count).to eq(0)
        end
      end

      it "does not activate at the wrong path" do
        expect(order.line_item_adjustments.count).to eq(0)
        Spree::PromotionHandler::Page.new(order, 'wrongpath').activate
        expect(order.line_item_adjustments.count).to eq(0)
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.2.2 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.1.1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.0.3 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-1.4.2 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-1.3.2 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.3.0 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.0.2 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-1.4.1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.2.1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.2.0 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.1.0 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/promotion_handler/page_spec.rb
solidus_core-2.0.1 spec/models/spree/promotion_handler/page_spec.rb