diff --git a/app/controllers/admin/tag_rules_controller.rb b/app/controllers/admin/tag_rules_controller.rb index d5112abf74..620de16ee3 100644 --- a/app/controllers/admin/tag_rules_controller.rb +++ b/app/controllers/admin/tag_rules_controller.rb @@ -57,7 +57,7 @@ module Admin TagRule.matching_variant_tag_rules_by_enterprises(params[:enterprise_id], params[:q]) @formatted_tag_rules = tag_rules.each_with_object({}) do |rule, mapping| - rule.preferred_customer_tags.split(",").each do |tag| + rule.preferred_variant_tags.split(",").each do |tag| if mapping[tag] mapping[tag][:rules] += 1 else diff --git a/app/models/tag_rule.rb b/app/models/tag_rule.rb index 93e72fa020..989952e363 100644 --- a/app/models/tag_rule.rb +++ b/app/models/tag_rule.rb @@ -27,7 +27,7 @@ class TagRule < ApplicationRecord return [] if rules.empty? - rules.select { |r| r.preferred_customer_tags =~ /#{tag}/ } + rules.select { |r| r.preferred_variant_tags =~ /#{tag}/ } end # The following method must be overriden in a concrete tagRule diff --git a/spec/controllers/admin/tag_rules_controller_spec.rb b/spec/controllers/admin/tag_rules_controller_spec.rb index c4e5f8c4c3..f1dccc2c4e 100644 --- a/spec/controllers/admin/tag_rules_controller_spec.rb +++ b/spec/controllers/admin/tag_rules_controller_spec.rb @@ -76,13 +76,20 @@ RSpec.describe Admin::TagRulesController do let(:enterprise) { create(:distributor_enterprise) } let(:q) { "" } let!(:rule1) { - create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "Tag-1" ) + create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "Tag-1", + preferred_variant_tags: "variant-tag-1" ) } let!(:rule2) { - create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "Tag-1" ) + create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "Tag-1", + preferred_variant_tags: "variant2-tag-1" ) } let!(:rule3) { - create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "organic" ) + create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "organic", + preferred_variant_tags: "variant-organic" ) + } + let!(:rule4) { + create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "organic", + preferred_variant_tags: "variant-tag-1" ) } before do @@ -93,8 +100,9 @@ RSpec.describe Admin::TagRulesController do spree_get(:variant_tag_rules, format: :html, enterprise_id: enterprise.id, q:) expect(response).to render_template :variant_tag_rules - expect(response.body).to include "Tag-1 has 2 rules" - expect(response.body).to include "organic has 1 rule" + expect(response.body).to include "variant-tag-1 has 2 rules" + expect(response.body).to include "variant2-tag-1 has 1 rule" + expect(response.body).to include "variant-organic has 1 rule" end context "with search string" do @@ -104,8 +112,9 @@ RSpec.describe Admin::TagRulesController do spree_get(:variant_tag_rules, format: :html, enterprise_id: enterprise.id, q:) expect(response).to render_template :variant_tag_rules - expect(response.body).not_to include "Tag-1 has 2 rules" - expect(response.body).to include "organic has 1 rule" + expect(response.body).not_to include "variant-tag-1 has 2 rules" + expect(response.body).not_to include "variant2-tag-1 has 1 rule" + expect(response.body).to include "variant-organic has 1 rule" end end end diff --git a/spec/models/tag_rule_spec.rb b/spec/models/tag_rule_spec.rb index a7c35b832c..eb27a088de 100644 --- a/spec/models/tag_rule_spec.rb +++ b/spec/models/tag_rule_spec.rb @@ -12,20 +12,20 @@ RSpec.describe TagRule do describe ".matching_variant_tag_rules_by_enterprises" do let(:enterprise) { create(:enterprise) } let!(:rule1) { - create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "filtered" ) + create(:filter_variants_tag_rule, enterprise:, preferred_variant_tags: "filtered" ) } let!(:rule2) { - create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "filtered" ) + create(:filter_variants_tag_rule, enterprise:, preferred_variant_tags: "filtered" ) } let!(:rule3) { create(:filter_variants_tag_rule, enterprise: create(:enterprise), - preferred_customer_tags: "filtered" ) + preferred_variant_tags: "filtered" ) } let!(:rule4) { - create(:filter_variants_tag_rule, enterprise:, preferred_customer_tags: "other-tag" ) + create(:filter_variants_tag_rule, enterprise:, preferred_variant_tags: "other-tag" ) } let!(:rule5) { - create(:filter_order_cycles_tag_rule, enterprise:, preferred_customer_tags: "filtered" ) + create(:filter_order_cycles_tag_rule, enterprise:, preferred_exchange_tags: "filtered" ) } it "returns a list of rule partially matching the tag" do