Skip to content

Commit

Permalink
Remove Rules::Taxon#actionable?
Browse files Browse the repository at this point in the history
This can be done with the LineItemTaxon rule now.
  • Loading branch information
mamhoff committed Apr 1, 2022
1 parent cacc347 commit e0b6781
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 90 deletions.
16 changes: 0 additions & 16 deletions core/app/models/spree/promotion/rules/taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ def eligible?(order, _options = {})
eligibility_errors.empty?
end

def actionable?(line_item)
found = Spree::Classification.where(
product_id: line_item.variant.product_id,
taxon_id: rule_taxon_ids_with_children
).exists?

case preferred_match_policy
when 'any', 'all'
found
when 'none'
!found
else
raise "unexpected match policy: #{preferred_match_policy.inspect}"
end
end

def taxon_ids_string
taxons.pluck(:id).join(',')
end
Expand Down
74 changes: 0 additions & 74 deletions core/spec/models/spree/promotion/rules/taxon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@
expect(rule).to be_eligible(order)
end

context 'when order contains items from different taxons' do
before do
product.taxons << taxon
rule.taxons << taxon
end

it 'should act on a product within the eligible taxon' do
expect(rule).to be_actionable(order.line_items.last)
end

it 'should not act on a product in another taxon' do
order.line_items << create(:line_item, product: create(:product, taxons: [taxon2]))
expect(rule).not_to be_actionable(order.line_items.last)
end
end

context "when order does not have any prefered taxon" do
before { rule.taxons << taxon2 }
it { expect(rule).not_to be_eligible(order) }
Expand Down Expand Up @@ -157,62 +141,4 @@
end
end
end

describe '#actionable?' do
let(:line_item) { order.line_items.first! }
let(:order) { create :order_with_line_items }
let(:taxon) { create :taxon, name: 'first' }

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 'raises' do
expect {
rule.eligible?(order)
}.to raise_error('unexpected match policy: "invalid"')
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

0 comments on commit e0b6781

Please sign in to comment.