Skip to content

Commit

Permalink
Do not consider unpromotionable line items discountable
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Mar 21, 2022
1 parent 6290769 commit 6b92efa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/app/models/spree/promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def order_discountable?(order)
end

def line_item_discountable?(line_item)
rules.all? { |rule| rule.line_item_discountable?(line_item) }
line_item.variant.product.promotionable? &&
rules.all? { |rule| rule.line_item_discountable?(line_item) }
end

def shipment_discountable?(shipment)
Expand Down
28 changes: 24 additions & 4 deletions core/spec/models/spree/promotion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,9 @@
end

describe "#line_item_discountable?" do
let(:line_item) { double Spree::LineItem }
let(:product) { build(:product) }
let(:variant) { build(:variant, product: product) }
let(:line_item) { build(:line_item, variant: variant) }
let(:true_rule) { stub_model Spree::PromotionRule, line_item_discountable?: true }
let(:false_rule) { stub_model Spree::PromotionRule, line_item_discountable?: false }
let(:rules) { [] }
Expand All @@ -946,15 +948,33 @@

subject { promotion.line_item_discountable?(line_item) }

context 'when the order is eligible for promotion' do
context 'when there are no rules' do
context 'when there are no rules' do
it { is_expected.to be }
end

context 'when there are rules' do
context 'when all rules allow action on the line item' do
let(:rules) { [true_rule] }
it { is_expected.to be }
end

context 'when at least one rule does not allow action on the line item' do
let(:rules) { [true_rule, false_rule] }
it { is_expected.not_to be }
end
end

context 'when the line_item is not eligible for promotion' do
let(:product) { build(:product, promotionable: false) }

context 'when there are no rules' do
it { is_expected.not_to be }
end

context 'when there are rules' do
context 'when all rules allow action on the line item' do
let(:rules) { [true_rule] }
it { is_expected.to be }
it { is_expected.not_to be }
end

context 'when at least one rule does not allow action on the line item' do
Expand Down

0 comments on commit 6b92efa

Please sign in to comment.