Skip to content

Commit

Permalink
Merge pull request #4056 from mamhoff/distinct-promotion-has-actions
Browse files Browse the repository at this point in the history
Fix Spree::Promotion.has_actions scope
  • Loading branch information
kennyadsl committed May 28, 2021
2 parents bbc5dfe + 9a826fb commit 05a14cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Promotion < Spree::Base
where(table[:expires_at].eq(nil).or(table[:expires_at].gt(time)))
end
scope :has_actions, -> do
joins(:promotion_actions)
joins(:promotion_actions).distinct
end
scope :applied, -> { joins(:order_promotions).distinct }

Expand Down
24 changes: 24 additions & 0 deletions core/spec/models/spree/promotion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@
end
end

describe '.has_actions' do
subject { described_class.has_actions }

let(:promotion) { create(:promotion, starts_at: Date.yesterday, name: "name1") }

before { promotion }

it "doesn't return promotion without actions" do
expect(subject).to be_empty
end

context 'when promotion has two actions' do
let(:promotion) { create(:promotion, :with_action, starts_at: Date.yesterday, name: "name1") }

before do
promotion.actions << Spree::Promotion::Actions::CreateAdjustment.new
end

it 'returns distinct promotion' do
expect(subject).to match [promotion]
end
end
end

describe "#apply_automatically" do
subject { build(:promotion) }

Expand Down

0 comments on commit 05a14cd

Please sign in to comment.