Sha256: 4135ae42805b6708d58f84e163f132770fef07c709bed83831f0305bd1f48383

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe Spree::Promotion::Actions::FreeShipping, :type => :model do
  let(:order) { create(:completed_order_with_totals) }
  let(:promotion) { create(:promotion) }
  let(:action) { Spree::Promotion::Actions::FreeShipping.create }
  let(:payload) { { order: order } }

  it_behaves_like 'an adjustment source'

  # From promotion spec:
  context "#perform" do
    before do
      order.shipments << create(:shipment)
      promotion.promotion_actions << action
    end

    it "should create a discount with correct negative amount" do
      expect(order.shipments.count).to eq(2)
      expect(order.shipments.first.cost).to eq(100)
      expect(order.shipments.last.cost).to eq(100)
      expect(action.perform(payload)).to be true
      expect(promotion.credits_count).to eq(2)
      expect(order.shipment_adjustments.count).to eq(2)
      expect(order.shipment_adjustments.first.amount.to_i).to eq(-100)
      expect(order.shipment_adjustments.last.amount.to_i).to eq(-100)
    end

    it "should not create a discount when order already has one from this promotion" do
      expect(action.perform(payload)).to be true
      expect(action.perform(payload)).to be false
      expect(promotion.credits_count).to eq(2)
      expect(order.shipment_adjustments.count).to eq(2)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
spree_core-3.1.5 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.4 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.3 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.2 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.0.10 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.1 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.0 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.0.rc4 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.0.9 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.0.rc3 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.0.rc2 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.1.0.rc1 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.0.8 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.0.7 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.0.6.1 spec/models/spree/promotion/actions/free_shipping_spec.rb
spree_core-3.0.6 spec/models/spree/promotion/actions/free_shipping_spec.rb