Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use taxon children when searching classification #3168

Merged
merged 1 commit into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions core/app/models/spree/promotion/rules/taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ def eligible?(order, _options = {})
eligibility_errors.empty?
end

# TODO: Fix bug - well described by jhawthorn in #1409:
# `eligible?` checks the configured taxons and all descendants,
# `actionable?` only seems to check against the taxons themselves (not children)
def actionable?(line_item)
found = Spree::Classification.where(
product_id: line_item.variant.product_id,
taxon_id: taxon_ids
taxon_id: rule_taxon_ids_with_children
).exists?

case preferred_match_policy
Expand Down
51 changes: 44 additions & 7 deletions core/spec/models/spree/promotion/rules/taxon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@
let(:order) { create :order_with_line_items }
let(:taxon) { create :taxon, name: 'first' }

before do
rule.preferred_match_policy = 'invalid'
rule.save!(validate: false)
line_item.product.taxons << taxon
rule.taxons << taxon
end

context 'with an invalid match policy' do
before do
rule.preferred_match_policy = 'invalid'
rule.save!(validate: false)
line_item.product.taxons << taxon
rule.taxons << taxon
end

it 'logs a warning and uses "any" policy' do
expect(Spree::Deprecation).to(
receive(:warn).
Expand All @@ -170,5 +170,42 @@
).to be_truthy
end
end

context 'when a product has a taxon of a taxon rule' do
before do
product.taxons << taxon
rule.taxons << taxon
rule.save!
end

it 'is actionable' do
expect(rule).to be_actionable(line_item)
end
end

context 'when a product has a taxon child of a taxon rule' do
before do
taxon.children << taxon2
product.taxons << taxon2
rule.taxons << taxon
rule.save!
end

it 'is actionable' do
expect(rule).to be_actionable(line_item)
end
end

context 'when a product does not have taxon or child taxon of a taxon rule' do
before do
product.taxons << taxon2
rule.taxons << taxon
rule.save!
end

it 'is not actionable' do
expect(rule).not_to be_actionable(line_item)
end
end
end
end