Skip to content

Commit

Permalink
add eligibility checking to automatic free shipping promotions
Browse files Browse the repository at this point in the history
  • Loading branch information
fylooi committed Sep 8, 2017
1 parent 292e7ac commit 4c8b3c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core/app/models/spree/promotion_handler/shipping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def activate
end

not_connected_automatic_promotions.each do |promotion|
promotion.activate(order: order)
if promotion.eligible?(order)
promotion.activate(order: order)
end
end
end

Expand Down
16 changes: 14 additions & 2 deletions core/spec/models/spree/promotion_handler/shipping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ module PromotionHandler
context 'with apply_automatically' do
let!(:promotion) { create(:promotion, apply_automatically: true, promotion_actions: [action]) }

it "creates the adjustment" do
expect { subject.activate }.to change { shipment.adjustments.count }.by(1)
context 'for eligible promotion' do
it "creates the adjustment" do
expect { subject.activate }.to change { shipment.adjustments.count }.by(1)
end
end

context 'for ineligible promotion' do
let!(:promotion) do
create(:promotion, :with_item_total_rule, item_total_threshold_amount: 1_000, apply_automatically: true, promotion_actions: [action])
end

it "does not create the adjustment" do
expect { subject.activate }.to change { shipment.adjustments.count }.by(0)
end
end
end

Expand Down

0 comments on commit 4c8b3c6

Please sign in to comment.