diff --git a/spec/models/tag_rule/filter_order_cycles_spec.rb b/spec/models/tag_rule/filter_order_cycles_spec.rb index 7616453cdd..0e84242b8f 100644 --- a/spec/models/tag_rule/filter_order_cycles_spec.rb +++ b/spec/models/tag_rule/filter_order_cycles_spec.rb @@ -3,56 +3,68 @@ require 'spec_helper' RSpec.describe TagRule::FilterOrderCycles do - let!(:tag_rule) { build_stubbed(:filter_order_cycles_tag_rule) } + let(:tag_rule) { + build(:filter_order_cycles_tag_rule, preferred_exchange_tags: order_cycle_tags, enterprise:) + } + let(:order_cycle_tags) { "" } + let(:enterprise) { build(:enterprise) } describe "#tags" do - it "return the exchange tags" do - tag_rule = create(:filter_order_cycles_tag_rule, preferred_exchange_tags: "my_tag") + let(:order_cycle_tags) { "my_tag" } + it "return the exchange tags" do expect(tag_rule.tags).to eq("my_tag") end end - describe "determining whether tags match for a given exchange" do + describe "#reject_matched?" do context "when the exchange is nil" do before do allow(tag_rule).to receive(:exchange_for) { nil } end it "returns false" do - expect(tag_rule.__send__(:tags_match?, nil)).to be false + expect(tag_rule.tags_match?(nil)).to be false end end context "when the exchange is not nil" do - let(:exchange_object) { double(:exchange, tag_list: ["member", "local", "volunteer"]) } + let(:order_cycle) { create(:simple_order_cycle, distributors: [enterprise]) } before do - allow(tag_rule).to receive(:exchange_for) { exchange_object } + exchange = order_cycle.exchanges.outgoing.first + exchange.tag_list = "member,local,volunteer" end context "when the rule has no preferred exchange tags specified" do - before { allow(tag_rule).to receive(:preferred_exchange_tags) { "" } } - it { expect(tag_rule.__send__(:tags_match?, exchange_object)).to be false } + it { expect(tag_rule.tags_match?(order_cycle)).to be false } end context "when the rule has preferred exchange tags specified that match ANY exchange tags" do - before { - allow(tag_rule).to receive(:preferred_exchange_tags) { - "wholesale,some_tag,member" - } - } - it { expect(tag_rule.__send__(:tags_match?, exchange_object)).to be true } + let(:order_cycle_tags) { "wholesale,some_tag,member" } + + it { expect(tag_rule.tags_match?(order_cycle)).to be true } end context "when the rule has preferred exchange tags specified that match NO exchange tags" do - before { - allow(tag_rule).to receive(:preferred_exchange_tags) { - "wholesale,some_tag,some_other_tag" - } - } - it { expect(tag_rule.__send__(:tags_match?, exchange_object)).to be false } + let(:order_cycle_tags) { "wholesale,some_tag,some_other_tag" } + + it { expect(tag_rule.tags_match?(order_cycle)).to be false } end end end + + describe "#reject_matched?" do + it "return false with default visibility (visible)" do + expect(tag_rule.reject_matched?).to be false + end + + context "when visiblity is set to hidden" do + let(:tag_rule) { + build(:filter_order_cycles_tag_rule, preferred_matched_order_cycles_visibility: "hidden") + } + + it { expect(tag_rule.reject_matched?).to be true } + end + end end diff --git a/spec/models/tag_rule/filter_payment_methods_spec.rb b/spec/models/tag_rule/filter_payment_methods_spec.rb index a846c5d618..f9776d4d36 100644 --- a/spec/models/tag_rule/filter_payment_methods_spec.rb +++ b/spec/models/tag_rule/filter_payment_methods_spec.rb @@ -3,48 +3,59 @@ require 'spec_helper' RSpec.describe TagRule::FilterPaymentMethods do - let!(:tag_rule) { build_stubbed(:filter_payment_methods_tag_rule) } + let(:tag_rule) { + build(:filter_payment_methods_tag_rule, preferred_payment_method_tags: payment_method_tags) + } + let(:payment_method_tags) { "" } describe "#tags" do - it "return the payment method tags" do - tag_rule = create(:filter_payment_methods_tag_rule, preferred_payment_method_tags: "my_tag") + let(:payment_method_tags) { "my_tag" } + it "return the payment method tags" do expect(tag_rule.tags).to eq("my_tag") end end - describe "determining whether tags match for a given payment method" do + describe "#tag_match?" do context "when the payment method is nil" do it "returns false" do - expect(tag_rule.__send__(:tags_match?, nil)).to be false + expect(tag_rule.tags_match?(nil)).to be false end end context "when the payment method is not nil" do - let(:payment_method) { create(:payment_method, tag_list: ["member", "local", "volunteer"]) } + let(:payment_method) { build(:payment_method, tag_list: ["member", "local", "volunteer"]) } context "when the rule has no preferred payment method tags specified" do - before { allow(tag_rule).to receive(:preferred_payment_method_tags) { "" } } - it { expect(tag_rule.__send__(:tags_match?, payment_method)).to be false } + it { expect(tag_rule.tags_match?(payment_method)).to be false } end context "when the rule has preferred customer tags specified that match ANY customer tags" do - before { - allow(tag_rule).to receive(:preferred_payment_method_tags) { - "wholesale,some_tag,member" - } - } - it { expect(tag_rule.__send__(:tags_match?, payment_method)).to be true } + let(:payment_method_tags) { "wholesale,some_tag,member" } + + it { expect(tag_rule.tags_match?(payment_method)).to be true } end context "when the rule has preferred customer tags specified that match NO customer tags" do - before { - allow(tag_rule).to receive(:preferred_payment_method_tags) { - "wholesale,some_tag,some_other_tag" - } - } - it { expect(tag_rule.__send__(:tags_match?, payment_method)).to be false } + let(:payment_method_tags) { "wholesale,some_tag,some_other_tag" } + + it { expect(tag_rule.tags_match?(payment_method)).to be false } end end end + + describe "#reject_matched?" do + it "return false with default visibility (visible)" do + expect(tag_rule.reject_matched?).to be false + end + + context "when visiblity is set to hidden" do + let(:tag_rule) { + build(:filter_payment_methods_tag_rule, + preferred_matched_payment_methods_visibility: "hidden") + } + + it { expect(tag_rule.reject_matched?).to be true } + end + end end diff --git a/spec/models/tag_rule/filter_products_spec.rb b/spec/models/tag_rule/filter_products_spec.rb index 41bfbaeba9..0595e6e0e3 100644 --- a/spec/models/tag_rule/filter_products_spec.rb +++ b/spec/models/tag_rule/filter_products_spec.rb @@ -3,20 +3,23 @@ require 'spec_helper' RSpec.describe TagRule::FilterProducts do - let!(:tag_rule) { build_stubbed(:filter_products_tag_rule, preferred_variant_tags: "my_tag") } + let(:tag_rule) { build(:filter_products_tag_rule, preferred_variant_tags: variant_tags) } + let(:variant_tags) { "" } describe "#tags" do - it "return the variants tags" do - tag_rule = create(:filter_products_tag_rule, preferred_variant_tags: "my_tag") + let(:variant_tags) { "my_tag" } + it "return the variants tags" do expect(tag_rule.tags).to eq("my_tag") end end describe "determining whether tags match for a given variant" do + let(:variant_tags) { "my_tag" } + context "when the variant is nil" do it "returns false" do - expect(tag_rule.__send__(:tags_match?, nil)).to be false + expect(tag_rule.tags_match?(nil)).to be false end end @@ -24,27 +27,34 @@ RSpec.describe TagRule::FilterProducts do let(:variant_object) { { "tag_list" => ["member", "local", "volunteer"] } } context "when the rule has no preferred variant tags specified" do - before { allow(tag_rule).to receive(:preferred_variant_tags) { "" } } - it { expect(tag_rule.__send__(:tags_match?, variant_object)).to be false } + it { expect(tag_rule.tags_match?(variant_object)).to be false } end context "when the rule has preferred variant tags specified that match ANY variant tags" do - before { - allow(tag_rule).to receive(:preferred_variant_tags) { - "wholesale,some_tag,member" - } - } - it { expect(tag_rule.__send__(:tags_match?, variant_object)).to be true } + let(:variant_tags) { "wholesale,some_tag,member" } + + it { expect(tag_rule.tags_match?(variant_object)).to be true } end context "when the rule has preferred variant tags specified that match NO variant tags" do - before { - allow(tag_rule).to receive(:preferred_variant_tags) { - "wholesale,some_tag,some_other_tag" - } - } - it { expect(tag_rule.__send__(:tags_match?, variant_object)).to be false } + let(:variant_tags) { "wholesale,some_tag,some_other_tag" } + + it { expect(tag_rule.tags_match?(variant_object)).to be false } end end end + + describe "#reject_matched?" do + it "return false with default visibility (visible)" do + expect(tag_rule.reject_matched?).to be false + end + + context "when visiblity is set to hidden" do + let(:tag_rule) { + build(:filter_products_tag_rule, preferred_matched_variants_visibility: "hidden") + } + + it { expect(tag_rule.reject_matched?).to be true } + end + end end diff --git a/spec/models/tag_rule/filter_shipping_methods_spec.rb b/spec/models/tag_rule/filter_shipping_methods_spec.rb index 0222507fcd..ffae35cf15 100644 --- a/spec/models/tag_rule/filter_shipping_methods_spec.rb +++ b/spec/models/tag_rule/filter_shipping_methods_spec.rb @@ -3,50 +3,61 @@ require 'spec_helper' RSpec.describe TagRule::FilterShippingMethods do - let!(:tag_rule) { build_stubbed(:filter_shipping_methods_tag_rule) } + let(:tag_rule) { + build(:filter_shipping_methods_tag_rule, preferred_shipping_method_tags: shipping_method_tags) + } + let(:shipping_method_tags) { "" } describe "#tags" do - it "return the shipping method tags" do - tag_rule = create(:filter_shipping_methods_tag_rule, preferred_shipping_method_tags: "my_tag") + let(:shipping_method_tags) { "my_tag" } + it "return the shipping method tags" do expect(tag_rule.tags).to eq("my_tag") end end - describe "determining whether tags match for a given shipping method" do + describe "#tag_match?" do context "when the shipping method is nil" do it "returns false" do - expect(tag_rule.__send__(:tags_match?, nil)).to be false + expect(tag_rule.tags_match?(nil)).to be false end end context "when the shipping method is not nil" do let(:shipping_method) { - build_stubbed(:shipping_method, tag_list: ["member", "local", "volunteer"]) + build(:shipping_method, tag_list: ["member", "local", "volunteer"]) } context "when the rule has no preferred shipping method tags specified" do - before { allow(tag_rule).to receive(:preferred_shipping_method_tags) { "" } } - it { expect(tag_rule.__send__(:tags_match?, shipping_method)).to be false } + it { expect(tag_rule.tags_match?(shipping_method)).to be false } end context "when rule has preferred customer tags specified that match ANY customer tags" do - before { - allow(tag_rule).to receive(:preferred_shipping_method_tags) { - "wholesale,some_tag,member" - } - } - it { expect(tag_rule.__send__(:tags_match?, shipping_method)).to be true } + let(:shipping_method_tags) { "wholesale,some_tag,member" } + + it { expect(tag_rule.tags_match?(shipping_method)).to be true } end context "when rule has preferred customer tags specified that match NO customer tags" do - before { - allow(tag_rule).to receive(:preferred_shipping_method_tags) { - "wholesale,some_tag,some_other_tag" - } - } - it { expect(tag_rule.__send__(:tags_match?, shipping_method)).to be false } + let(:shipping_method_tags) { "wholesale,some_tag,some_other_tag" } + + it { expect(tag_rule.tags_match?(shipping_method)).to be false } end end end + + describe "#reject_matched?" do + it "return false with default visibility (visible)" do + expect(tag_rule.reject_matched?).to be false + end + + context "when visiblity is set to hidden" do + let(:tag_rule) { + build(:filter_shipping_methods_tag_rule, + preferred_matched_shipping_methods_visibility: "hidden") + } + + it { expect(tag_rule.reject_matched?).to be true } + end + end end