Fix taxon

This commit is contained in:
Gaetan Craig-Riou
2024-03-05 10:43:44 +11:00
parent 95ed806370
commit ef298e3b62
2 changed files with 6 additions and 3 deletions

View File

@@ -57,7 +57,7 @@ module Spree
taxons = {}
Spree::Taxon.
joins(products: :supplier).
joins(products: { variants: :supplier }).
select('spree_taxons.*, enterprises.id AS enterprise_id').
each do |t|
taxons[t.enterprise_id.to_i] ||= Set.new

View File

@@ -11,7 +11,9 @@ module Spree
let(:t2) { create(:taxon) }
describe "finding all supplied taxons" do
let!(:p1) { create(:simple_product, supplier: e, primary_taxon_id: t1.id) }
let!(:p1) {
create(:simple_product, primary_taxon_id: t1.id, supplier_id: e.id)
}
it "finds taxons" do
expect(Taxon.supplied_taxons).to eq(e.id => Set.new([t1.id]))
@@ -40,9 +42,10 @@ module Spree
describe "touches" do
let!(:taxon1) { create(:taxon) }
let!(:taxon2) { create(:taxon) }
let!(:product) { create(:simple_product, primary_taxon: taxon1) }
let!(:product) { create(:simple_product, primary_taxon_id: taxon1.id) }
let(:variant) { product.variants.first }
it "is touched when assignment of primary_taxon on a variant changes" do
expect do
variant.update(primary_taxon: taxon2)