diff --git a/promotions/lib/solidus_promotions/testing_support/shared_examples.rb b/promotions/lib/solidus_promotions/testing_support/shared_examples.rb index ecf7b87a992..0b52a492f76 100644 --- a/promotions/lib/solidus_promotions/testing_support/shared_examples.rb +++ b/promotions/lib/solidus_promotions/testing_support/shared_examples.rb @@ -3,3 +3,4 @@ require "solidus_promotions/testing_support/shared_examples/product_condition" require "solidus_promotions/testing_support/shared_examples/taxon_condition" require "solidus_promotions/testing_support/shared_examples/option_value_condition" +require "solidus_promotions/testing_support/shared_examples/promotion_calculator" diff --git a/promotions/spec/shared_examples/calculator_shared_examples.rb b/promotions/lib/solidus_promotions/testing_support/shared_examples/promotion_calculator.rb similarity index 75% rename from promotions/spec/shared_examples/calculator_shared_examples.rb rename to promotions/lib/solidus_promotions/testing_support/shared_examples/promotion_calculator.rb index 0eb256ce669..bf7be5f0f2f 100644 --- a/promotions/spec/shared_examples/calculator_shared_examples.rb +++ b/promotions/lib/solidus_promotions/testing_support/shared_examples/promotion_calculator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.shared_examples_for "a calculator with a description" do +RSpec.shared_examples_for "a promotion calculator" do describe ".description" do subject { described_class.description } diff --git a/promotions/spec/models/solidus_promotions/calculators/distributed_amount_spec.rb b/promotions/spec/models/solidus_promotions/calculators/distributed_amount_spec.rb index 0fcafc3c088..c6fb62a0386 100644 --- a/promotions/spec/models/solidus_promotions/calculators/distributed_amount_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/distributed_amount_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "rails_helper" -require "shared_examples/calculator_shared_examples" RSpec.describe SolidusPromotions::Calculators::DistributedAmount, type: :model do let(:calculator) { described_class.new(preferred_amount: 15, preferred_currency: currency) } @@ -13,6 +12,8 @@ let(:order) { create(:order_with_line_items, line_items_attributes: line_items_attributes) } let(:currency) { "USD" } + it_behaves_like "a promotion calculator" + context "applied to an order" do let(:line_items_attributes) { [{ price: 20 }, { price: 30 }, { price: 100 }] } diff --git a/promotions/spec/models/solidus_promotions/calculators/flat_rate_spec.rb b/promotions/spec/models/solidus_promotions/calculators/flat_rate_spec.rb index d19cecdcc17..54cc8bef9b9 100644 --- a/promotions/spec/models/solidus_promotions/calculators/flat_rate_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/flat_rate_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "rails_helper" -require "shared_examples/calculator_shared_examples" RSpec.describe SolidusPromotions::Calculators::FlatRate, type: :model do subject { calculator.compute(discountable) } @@ -14,7 +13,7 @@ ) end - it_behaves_like "a calculator with a description" + it_behaves_like "a promotion calculator" context "compute_line_item" do let(:discountable) { mock_model(Spree::LineItem, order: order) } diff --git a/promotions/spec/models/solidus_promotions/calculators/flexi_rate_spec.rb b/promotions/spec/models/solidus_promotions/calculators/flexi_rate_spec.rb index d8112638378..15e62059328 100644 --- a/promotions/spec/models/solidus_promotions/calculators/flexi_rate_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/flexi_rate_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "rails_helper" -require "shared_examples/calculator_shared_examples" RSpec.describe SolidusPromotions::Calculators::FlexiRate, type: :model do let(:calculator) do @@ -26,7 +25,7 @@ ) end - it_behaves_like "a calculator with a description" + it_behaves_like "a promotion calculator" context "compute" do subject { calculator.compute(line_item) } diff --git a/promotions/spec/models/solidus_promotions/calculators/percent_spec.rb b/promotions/spec/models/solidus_promotions/calculators/percent_spec.rb index 27418c03d6a..305840882e9 100644 --- a/promotions/spec/models/solidus_promotions/calculators/percent_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/percent_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "rails_helper" -require "shared_examples/calculator_shared_examples" RSpec.describe SolidusPromotions::Calculators::Percent, type: :model do context "compute" do @@ -29,5 +28,5 @@ end end - it_behaves_like "a calculator with a description" + it_behaves_like "a promotion calculator" end diff --git a/promotions/spec/models/solidus_promotions/calculators/percent_with_cap_spec.rb b/promotions/spec/models/solidus_promotions/calculators/percent_with_cap_spec.rb index f68695ef502..c79f262adaf 100644 --- a/promotions/spec/models/solidus_promotions/calculators/percent_with_cap_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/percent_with_cap_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe SolidusPromotions::Calculators::PercentWithCap, type: :model do + it_behaves_like "a promotion calculator" + context "applied to an order" do let(:calculator) { described_class.new(preferred_percent: 15, preferred_max_amount: 50) } let(:promotion) do diff --git a/promotions/spec/models/solidus_promotions/calculators/tiered_flat_rate_spec.rb b/promotions/spec/models/solidus_promotions/calculators/tiered_flat_rate_spec.rb index 2b25edbf6f5..979b73dafd2 100644 --- a/promotions/spec/models/solidus_promotions/calculators/tiered_flat_rate_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/tiered_flat_rate_spec.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true require "rails_helper" -require "shared_examples/calculator_shared_examples" RSpec.describe SolidusPromotions::Calculators::TieredFlatRate, type: :model do let(:calculator) { described_class.new } - it_behaves_like "a calculator with a description" + it_behaves_like "a promotion calculator" describe "#valid?" do subject { calculator.valid? } diff --git a/promotions/spec/models/solidus_promotions/calculators/tiered_percent_on_eligible_item_quantity_spec.rb b/promotions/spec/models/solidus_promotions/calculators/tiered_percent_on_eligible_item_quantity_spec.rb index bf8fcf58d9c..80dbb20aa66 100644 --- a/promotions/spec/models/solidus_promotions/calculators/tiered_percent_on_eligible_item_quantity_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/tiered_percent_on_eligible_item_quantity_spec.rb @@ -27,6 +27,8 @@ subject { promotion.benefits.first.calculator.compute(item) } + it_behaves_like "a promotion calculator" + # 2 Shirts at 50, 100 USD. 10 % == 10 it { is_expected.to eq(10) } diff --git a/promotions/spec/models/solidus_promotions/calculators/tiered_percent_spec.rb b/promotions/spec/models/solidus_promotions/calculators/tiered_percent_spec.rb index 1e9e261dbb2..f9e44d6b1fc 100644 --- a/promotions/spec/models/solidus_promotions/calculators/tiered_percent_spec.rb +++ b/promotions/spec/models/solidus_promotions/calculators/tiered_percent_spec.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true require "rails_helper" -require "shared_examples/calculator_shared_examples" RSpec.describe SolidusPromotions::Calculators::TieredPercent, type: :model do let(:calculator) { described_class.new } - it_behaves_like "a calculator with a description" + it_behaves_like "a promotion calculator" describe "#valid?" do subject { calculator.valid? }