From 6284e5a6570522abecd6c5ca01ef9becb6c3a282 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 11:06:16 -0700 Subject: [PATCH 01/18] Use ActiveModel::Naming for FlatPercentItemTotal --- core/app/models/spree/calculator/flat_percent_item_total.rb | 4 ---- core/config/locales/en.yml | 2 ++ .../models/spree/calculator/flat_percent_item_total_spec.rb | 5 +++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/flat_percent_item_total.rb b/core/app/models/spree/calculator/flat_percent_item_total.rb index 3c58fe9ee4a..5b0173ef69f 100644 --- a/core/app/models/spree/calculator/flat_percent_item_total.rb +++ b/core/app/models/spree/calculator/flat_percent_item_total.rb @@ -4,10 +4,6 @@ module Spree class Calculator::FlatPercentItemTotal < Calculator preference :flat_percent, :decimal, default: 0 - def self.description - Spree.t(:flat_percent) - end - def compute(object) computed_amount = (object.amount * preferred_flat_percent / 100).round(2) diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 58ba097c954..6b058a794d1 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -362,6 +362,8 @@ en: spree/calculator/default_tax: one: Default Tax other: Default Tax + spree/calculator/flat_percent_item_total: + one: Flat Percent spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb b/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb index 65e21f48270..5c8bd1c6d03 100644 --- a/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb +++ b/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb @@ -4,6 +4,11 @@ let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new } let(:line_item) { mock_model Spree::LineItem } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Flat Percent") } + end + before { allow(calculator).to receive_messages preferred_flat_percent: 10 } context "compute" do From 01955de408c01191c03b7abe727716177234a815 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 11:12:34 -0700 Subject: [PATCH 02/18] Use ActiveModel::Naming for FlatRate --- core/app/models/spree/calculator/flat_rate.rb | 4 ---- core/config/locales/en.yml | 4 ++++ core/spec/models/spree/calculator/flat_rate_spec.rb | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/flat_rate.rb b/core/app/models/spree/calculator/flat_rate.rb index 503112d400c..992af63c7f8 100644 --- a/core/app/models/spree/calculator/flat_rate.rb +++ b/core/app/models/spree/calculator/flat_rate.rb @@ -5,10 +5,6 @@ class Calculator::FlatRate < Calculator preference :amount, :decimal, default: 0 preference :currency, :string, default: ->{ Spree::Config[:currency] } - def self.description - Spree.t(:flat_rate_per_order) - end - def compute(object = nil) if object && preferred_currency.casecmp(object.currency).zero? preferred_amount diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 6b058a794d1..3d7b372eefb 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -364,6 +364,10 @@ en: other: Default Tax spree/calculator/flat_percent_item_total: one: Flat Percent + other: Flat Percent + spree/calculator/flat_rate: + one: Flat Rate + other: Flat Rate spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/flat_rate_spec.rb b/core/spec/models/spree/calculator/flat_rate_spec.rb index 40bb97e8ef8..f3fe78e4676 100644 --- a/core/spec/models/spree/calculator/flat_rate_spec.rb +++ b/core/spec/models/spree/calculator/flat_rate_spec.rb @@ -3,6 +3,11 @@ describe Spree::Calculator::FlatRate, type: :model do let(:calculator) { Spree::Calculator::FlatRate.new } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Flat Rate") } + end + let(:order) do mock_model( Spree::Order, quantity: 10, currency: "USD" From 0de5be70ba7d02284f4b6fbade24abb47b5782af Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 11:18:18 -0700 Subject: [PATCH 03/18] Use ActiveModel::Naming for TieredPercent --- core/app/models/spree/calculator/tiered_percent.rb | 4 ---- core/config/locales/en.yml | 3 +++ core/spec/models/spree/calculator/tiered_percent_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/tiered_percent.rb b/core/app/models/spree/calculator/tiered_percent.rb index ae159ccc036..981f7be3f60 100644 --- a/core/app/models/spree/calculator/tiered_percent.rb +++ b/core/app/models/spree/calculator/tiered_percent.rb @@ -18,10 +18,6 @@ class Calculator::TieredPercent < Calculator } validate :preferred_tiers_content - def self.description - Spree.t(:tiered_percent) - end - def compute(object) order = object.is_a?(Order) ? object : object.order _base, percent = preferred_tiers.sort.reverse.detect{ |b, _| order.item_total >= b } diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 3d7b372eefb..775bc416e9e 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -368,6 +368,9 @@ en: spree/calculator/flat_rate: one: Flat Rate other: Flat Rate + spree/calculator/tiered_percent: + one: Tiered Percent + other: Tiered Percent spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/tiered_percent_spec.rb b/core/spec/models/spree/calculator/tiered_percent_spec.rb index 917b9401043..ee4287e887b 100644 --- a/core/spec/models/spree/calculator/tiered_percent_spec.rb +++ b/core/spec/models/spree/calculator/tiered_percent_spec.rb @@ -3,6 +3,11 @@ describe Spree::Calculator::TieredPercent, type: :model do let(:calculator) { Spree::Calculator::TieredPercent.new } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Tiered Percent") } + end + describe "#valid?" do subject { calculator.valid? } context "when base percent is less than zero" do From efc4b93a9fe18e731f6880bc1ac8b9970713c07d Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 11:21:06 -0700 Subject: [PATCH 04/18] Use ActiveModel::Naming for TieredFlatRate --- core/app/models/spree/calculator/tiered_flat_rate.rb | 4 ---- core/config/locales/en.yml | 3 +++ core/spec/models/spree/calculator/tiered_flat_rate_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/tiered_flat_rate.rb b/core/app/models/spree/calculator/tiered_flat_rate.rb index 10f206f30dc..1f9b0e30a67 100644 --- a/core/app/models/spree/calculator/tiered_flat_rate.rb +++ b/core/app/models/spree/calculator/tiered_flat_rate.rb @@ -14,10 +14,6 @@ class Calculator::TieredFlatRate < Calculator validate :preferred_tiers_content - def self.description - Spree.t(:tiered_flat_rate) - end - def compute(object) _base, amount = preferred_tiers.sort.reverse.detect{ |b, _| object.amount >= b } amount || preferred_base_amount diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 775bc416e9e..f3ab86db541 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -371,6 +371,9 @@ en: spree/calculator/tiered_percent: one: Tiered Percent other: Tiered Percent + spree/calculator/tiered_flat_rate: + one: Tiered Flat Rate + other: Tiered Flat Rate spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb b/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb index e8422e2b50f..cb38867a94b 100644 --- a/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb +++ b/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb @@ -3,6 +3,11 @@ describe Spree::Calculator::TieredFlatRate, type: :model do let(:calculator) { Spree::Calculator::TieredFlatRate.new } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Tiered Flat Rate") } + end + describe "#valid?" do subject { calculator.valid? } context "when tiers is a hash" do From a37f6101525dc702b09d3123a13fcb193b4dbe25 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 11:50:56 -0700 Subject: [PATCH 05/18] Use ActiveModel::Naming for PercentOnLineItem --- .../spree/calculator/percent_on_line_item.rb | 4 ---- core/config/locales/en.yml | 3 +++ .../spree/calculator/percent_on_line_item_spec.rb | 15 +++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/app/models/spree/calculator/percent_on_line_item.rb b/core/app/models/spree/calculator/percent_on_line_item.rb index e4f0076b744..bedb5a14392 100644 --- a/core/app/models/spree/calculator/percent_on_line_item.rb +++ b/core/app/models/spree/calculator/percent_on_line_item.rb @@ -3,10 +3,6 @@ class Calculator class PercentOnLineItem < Calculator preference :percent, :decimal, default: 0 - def self.description - Spree.t(:percent_per_item) - end - def compute(object) (object.amount * preferred_percent) / 100 end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index f3ab86db541..1959236d154 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -374,6 +374,9 @@ en: spree/calculator/tiered_flat_rate: one: Tiered Flat Rate other: Tiered Flat Rate + spree/calculator/percent_on_line_item: + one: Percent Per Item + other: Percent Per Item spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/percent_on_line_item_spec.rb b/core/spec/models/spree/calculator/percent_on_line_item_spec.rb index 0a47c2c75cf..826124e0efa 100644 --- a/core/spec/models/spree/calculator/percent_on_line_item_spec.rb +++ b/core/spec/models/spree/calculator/percent_on_line_item_spec.rb @@ -3,12 +3,19 @@ module Spree class Calculator describe PercentOnLineItem, type: :model do - let(:line_item) { double("LineItem", amount: 100) } + context "compute" do + let(:line_item) { double("LineItem", amount: 100) } - before { subject.preferred_percent = 15 } + before { subject.preferred_percent = 15 } - it "computes based on item price and quantity" do - expect(subject.compute(line_item)).to eq 15 + it "computes based on item price and quantity" do + expect(subject.compute(line_item)).to eq 15 + end + end + + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Percent Per Item") } end end end From 9600b9bef01df56ca1d655988e9d963e752e6b6a Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 11:59:40 -0700 Subject: [PATCH 06/18] Use ActiveModel::Naming for FreeShipping --- core/app/models/spree/calculator/free_shipping.rb | 3 --- core/config/locales/en.yml | 3 +++ core/spec/models/spree/calculator/free_shipping_spec.rb | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 core/spec/models/spree/calculator/free_shipping_spec.rb diff --git a/core/app/models/spree/calculator/free_shipping.rb b/core/app/models/spree/calculator/free_shipping.rb index 5a70acba8a1..928b4b69590 100644 --- a/core/app/models/spree/calculator/free_shipping.rb +++ b/core/app/models/spree/calculator/free_shipping.rb @@ -3,9 +3,6 @@ module Spree # The only case where it was used was for Free Shipping Promotions. There is # now a Promotion Action which deals with these types of promotions instead. class Calculator::FreeShipping < Calculator - def self.description - Spree.t(:free_shipping) - end def compute(object) if object.is_a?(Array) diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 1959236d154..838511db3cb 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -377,6 +377,9 @@ en: spree/calculator/percent_on_line_item: one: Percent Per Item other: Percent Per Item + spree/calculator/free_shipping: + one: Free Shipping + other: Free Shipping spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/free_shipping_spec.rb b/core/spec/models/spree/calculator/free_shipping_spec.rb new file mode 100644 index 00000000000..9cba4bddab0 --- /dev/null +++ b/core/spec/models/spree/calculator/free_shipping_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +describe Spree::Calculator::FreeShipping, type: :model do + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Free Shipping") } + end +end From 309ca02e3f7737aab53238a027bc90a93ed669ca Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 12:16:25 -0700 Subject: [PATCH 07/18] Change model tested to correct model Change model tested from Spree::Calculator::PriceSack to Spree::Calculator::Shipping::PriceSack. --- core/spec/models/spree/calculator/shipping/price_sack_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/spec/models/spree/calculator/shipping/price_sack_spec.rb b/core/spec/models/spree/calculator/shipping/price_sack_spec.rb index a769959c47d..e631343ac9e 100644 --- a/core/spec/models/spree/calculator/shipping/price_sack_spec.rb +++ b/core/spec/models/spree/calculator/shipping/price_sack_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Spree::Calculator::PriceSack, type: :model do +describe Spree::Calculator::Shipping::PriceSack, type: :model do let(:calculator) do calculator = Spree::Calculator::PriceSack.new calculator.preferred_minimal_amount = 5 From 5048554d472b826e473fb3e7760f22b83d0dd0f3 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 12:18:33 -0700 Subject: [PATCH 08/18] Use ActiveModel::Naming for Shipping::PriceSack --- core/app/models/spree/calculator/shipping/price_sack.rb | 4 ---- core/config/locales/en.yml | 3 +++ .../spec/models/spree/calculator/shipping/price_sack_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/shipping/price_sack.rb b/core/app/models/spree/calculator/shipping/price_sack.rb index 59fa87dd381..e9c5d77ad19 100644 --- a/core/app/models/spree/calculator/shipping/price_sack.rb +++ b/core/app/models/spree/calculator/shipping/price_sack.rb @@ -8,10 +8,6 @@ class PriceSack < ShippingCalculator preference :discount_amount, :decimal, default: 0 preference :currency, :string, default: ->{ Spree::Config[:currency] } - def self.description - Spree.t(:shipping_price_sack) - end - def compute_package(package) compute_from_price(total(package.contents)) end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 838511db3cb..9a85b92855e 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -380,6 +380,9 @@ en: spree/calculator/free_shipping: one: Free Shipping other: Free Shipping + spree/calculator/shipping/price_sack: + one: Price sack + other: Price sack spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/shipping/price_sack_spec.rb b/core/spec/models/spree/calculator/shipping/price_sack_spec.rb index e631343ac9e..f4b1c11da08 100644 --- a/core/spec/models/spree/calculator/shipping/price_sack_spec.rb +++ b/core/spec/models/spree/calculator/shipping/price_sack_spec.rb @@ -9,6 +9,11 @@ calculator end + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Price sack") } + end + let(:order) { stub_model(Spree::Order) } let(:shipment) { stub_model(Spree::Shipment, amount: 10) } From 2360bc28af2f0daaa79ea1988256e6ae25712db4 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:10:24 -0700 Subject: [PATCH 09/18] Use ActiveModel::Naming for Shipping::PerItem --- core/app/models/spree/calculator/shipping/per_item.rb | 4 ---- core/config/locales/en.yml | 2 ++ core/spec/models/spree/calculator/shipping/per_item_spec.rb | 5 +++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/shipping/per_item.rb b/core/app/models/spree/calculator/shipping/per_item.rb index f50b22065bb..3ca2e1f13b3 100644 --- a/core/app/models/spree/calculator/shipping/per_item.rb +++ b/core/app/models/spree/calculator/shipping/per_item.rb @@ -6,10 +6,6 @@ class PerItem < ShippingCalculator preference :amount, :decimal, default: 0 preference :currency, :string, default: ->{ Spree::Config[:currency] } - def self.description - Spree.t(:shipping_flat_rate_per_item) - end - def compute_package(package) compute_from_quantity(package.contents.sum(&:quantity)) end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 9a85b92855e..4e4b6f34242 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -383,6 +383,8 @@ en: spree/calculator/shipping/price_sack: one: Price sack other: Price sack + spree/calculator/shipping/per_item: + one: Flat rate per package item spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/shipping/per_item_spec.rb b/core/spec/models/spree/calculator/shipping/per_item_spec.rb index 3cf1d751437..9051d3688e3 100644 --- a/core/spec/models/spree/calculator/shipping/per_item_spec.rb +++ b/core/spec/models/spree/calculator/shipping/per_item_spec.rb @@ -6,6 +6,11 @@ module Calculator::Shipping let(:variant1) { build(:variant) } let(:variant2) { build(:variant) } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Flat rate per package item") } + end + let(:package) do build(:stock_package, variants_contents: { variant1 => 5, variant2 => 3 }) end From d00bee9e7f37cbcecdb72e4577130e2b06e9427e Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:12:55 -0700 Subject: [PATCH 10/18] Use ActiveModel::Naming for FlexiRate --- core/app/models/spree/calculator/flexi_rate.rb | 4 ---- core/config/locales/en.yml | 4 ++++ core/spec/models/spree/calculator/flexi_rate_spec.rb | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/flexi_rate.rb b/core/app/models/spree/calculator/flexi_rate.rb index 79c04582b69..b4f19a6dae3 100644 --- a/core/app/models/spree/calculator/flexi_rate.rb +++ b/core/app/models/spree/calculator/flexi_rate.rb @@ -7,10 +7,6 @@ class Calculator::FlexiRate < Calculator preference :max_items, :integer, default: 0 preference :currency, :string, default: ->{ Spree::Config[:currency] } - def self.description - Spree.t(:flexible_rate) - end - def self.available?(_object) true end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 4e4b6f34242..d73ad8d22b1 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -385,6 +385,10 @@ en: other: Price sack spree/calculator/shipping/per_item: one: Flat rate per package item + other: Flat rate per package item + spree/calculator/flexi_rate: + one: Flexible Rate + other: Flexible Rate spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/flexi_rate_spec.rb b/core/spec/models/spree/calculator/flexi_rate_spec.rb index 2587e039b8f..2aec7fd5bc2 100644 --- a/core/spec/models/spree/calculator/flexi_rate_spec.rb +++ b/core/spec/models/spree/calculator/flexi_rate_spec.rb @@ -3,6 +3,11 @@ describe Spree::Calculator::FlexiRate, type: :model do let(:calculator) { Spree::Calculator::FlexiRate.new } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Flexible Rate") } + end + let(:order) do mock_model( Spree::Order, quantity: 10 From 15fcc2a79cfc8a0619e009e19dcf42cb2794bd19 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:18:42 -0700 Subject: [PATCH 11/18] Use ActiveModel::Naming for PercentPerItem --- core/app/models/spree/calculator/percent_per_item.rb | 4 ---- core/config/locales/en.yml | 3 +++ .../models/spree/calculator/percent_per_item_spec.rb | 12 ++++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 core/spec/models/spree/calculator/percent_per_item_spec.rb diff --git a/core/app/models/spree/calculator/percent_per_item.rb b/core/app/models/spree/calculator/percent_per_item.rb index e33d5de9056..b44216f36de 100644 --- a/core/app/models/spree/calculator/percent_per_item.rb +++ b/core/app/models/spree/calculator/percent_per_item.rb @@ -10,10 +10,6 @@ module Spree class Calculator::PercentPerItem < Calculator preference :percent, :decimal, default: 0 - def self.description - Spree.t(:percent_per_item) - end - def compute(object = nil) return 0 if object.nil? object.line_items.map { |line_item| diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index d73ad8d22b1..7878f09edbb 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -389,6 +389,9 @@ en: spree/calculator/flexi_rate: one: Flexible Rate other: Flexible Rate + spree/calculator/percent_per_item: + one: Percent Per Item + other: Percent Per Item spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/percent_per_item_spec.rb b/core/spec/models/spree/calculator/percent_per_item_spec.rb new file mode 100644 index 00000000000..cd2906c9a10 --- /dev/null +++ b/core/spec/models/spree/calculator/percent_per_item_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +module Spree + class Calculator + describe PercentPerItem, type: :model do + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Percent Per Item") } + end + end + end +end From fa6f603c8be0645da660a104021a2a23e18c3928 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:22:59 -0700 Subject: [PATCH 12/18] Use ActiveModel::Naming for PriceSack --- core/app/models/spree/calculator/price_sack.rb | 4 ---- core/config/locales/en.yml | 3 +++ core/spec/models/spree/calculator/price_sack_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/price_sack.rb b/core/app/models/spree/calculator/price_sack.rb index dc0206dd408..39b0170748d 100644 --- a/core/app/models/spree/calculator/price_sack.rb +++ b/core/app/models/spree/calculator/price_sack.rb @@ -7,10 +7,6 @@ class Calculator::PriceSack < Calculator preference :discount_amount, :decimal, default: 0 preference :currency, :string, default: ->{ Spree::Config[:currency] } - def self.description - Spree.t(:price_sack) - end - # as object we always get line items, as calculable we have Coupon, ShippingMethod def compute(object) if object.is_a?(Array) diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 7878f09edbb..0c23e1a2b3d 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -392,6 +392,9 @@ en: spree/calculator/percent_per_item: one: Percent Per Item other: Percent Per Item + spree/calculator/price_sack: + one: Price Sack + other: Price Sack spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/price_sack_spec.rb b/core/spec/models/spree/calculator/price_sack_spec.rb index a769959c47d..260bf3747f0 100644 --- a/core/spec/models/spree/calculator/price_sack_spec.rb +++ b/core/spec/models/spree/calculator/price_sack_spec.rb @@ -9,6 +9,11 @@ calculator end + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Price Sack") } + end + let(:order) { stub_model(Spree::Order) } let(:shipment) { stub_model(Spree::Shipment, amount: 10) } From 46c15d7dfd58cba9de8da80ed0b3d541111190ee Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:30:42 -0700 Subject: [PATCH 13/18] Use ActiveModel::Naming for Returns::DefaultRefundAmount --- .../models/spree/calculator/returns/default_refund_amount.rb | 3 --- core/config/locales/en.yml | 3 +++ .../spree/calculator/refunds/default_refund_amount_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/app/models/spree/calculator/returns/default_refund_amount.rb b/core/app/models/spree/calculator/returns/default_refund_amount.rb index 013ff4c9e10..f3dd8680c52 100644 --- a/core/app/models/spree/calculator/returns/default_refund_amount.rb +++ b/core/app/models/spree/calculator/returns/default_refund_amount.rb @@ -3,9 +3,6 @@ module Spree module Calculator::Returns class DefaultRefundAmount < ReturnsCalculator - def self.description - Spree.t(:default_refund_amount) - end def compute(return_item) return 0.0.to_d if return_item.part_of_exchange? diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 0c23e1a2b3d..fb9b51c2754 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -395,6 +395,9 @@ en: spree/calculator/price_sack: one: Price Sack other: Price Sack + spree/calculator/returns/default_refund_amount: + one: Default Refund Amount + other: Default Refund Amount spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb b/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb index 9431231438d..a7d87baee8a 100644 --- a/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +++ b/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb @@ -9,6 +9,11 @@ let(:calculator) { Spree::Calculator::Returns::DefaultRefundAmount.new } let(:order) { line_item.order } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Default Refund Amount") } + end + subject { calculator.compute(return_item) } context "not an exchange" do From 9026a30e43e54a9b42ae477cea3bc1aebab46cc4 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:33:42 -0700 Subject: [PATCH 14/18] Use ActiveModel::Naming for Shipping::FlatPercentItemTotal --- .../spree/calculator/shipping/flat_percent_item_total.rb | 4 ---- core/config/locales/en.yml | 3 +++ .../calculator/shipping/flat_percent_item_total_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/shipping/flat_percent_item_total.rb b/core/app/models/spree/calculator/shipping/flat_percent_item_total.rb index aef369d19f4..1af0e665017 100644 --- a/core/app/models/spree/calculator/shipping/flat_percent_item_total.rb +++ b/core/app/models/spree/calculator/shipping/flat_percent_item_total.rb @@ -5,10 +5,6 @@ module Calculator::Shipping class FlatPercentItemTotal < ShippingCalculator preference :flat_percent, :decimal, default: 0 - def self.description - Spree.t(:flat_percent) - end - def compute_package(package) compute_from_price(total(package.contents)) end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index fb9b51c2754..13e5814531c 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -398,6 +398,9 @@ en: spree/calculator/returns/default_refund_amount: one: Default Refund Amount other: Default Refund Amount + spree/calculator/shipping/flat_percent_item_total: + one: Flat Percent + other: Flat Percent spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb b/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb index 0b14c9ee833..18826027f36 100644 --- a/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +++ b/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb @@ -6,6 +6,11 @@ module Calculator::Shipping let(:variant1) { build(:variant, price: 10.11) } let(:variant2) { build(:variant, price: 20.2222) } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Flat Percent") } + end + let(:line_item1) { build(:line_item, variant: variant1) } let(:line_item2) { build(:line_item, variant: variant2) } From fceb8fb18623c634d43d11d7ee342fbd6496fffc Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:36:57 -0700 Subject: [PATCH 15/18] Use ActiveModel::Naming for Shipping::FlatRate --- core/app/models/spree/calculator/shipping/flat_rate.rb | 4 ---- core/config/locales/en.yml | 3 +++ core/spec/models/spree/calculator/shipping/flat_rate_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/shipping/flat_rate.rb b/core/app/models/spree/calculator/shipping/flat_rate.rb index 838b8513c70..1e76dd24675 100644 --- a/core/app/models/spree/calculator/shipping/flat_rate.rb +++ b/core/app/models/spree/calculator/shipping/flat_rate.rb @@ -6,10 +6,6 @@ class FlatRate < ShippingCalculator preference :amount, :decimal, default: 0 preference :currency, :string, default: ->{ Spree::Config[:currency] } - def self.description - Spree.t(:shipping_flat_rate_per_order) - end - def compute_package(_package) preferred_amount end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 13e5814531c..249ef73f935 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -401,6 +401,9 @@ en: spree/calculator/shipping/flat_percent_item_total: one: Flat Percent other: Flat Percent + spree/calculator/shipping/flat_rate: + one: Flat rate + other: Flat rate spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb b/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb index 280679564d3..716b9e81497 100644 --- a/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb +++ b/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb @@ -5,6 +5,11 @@ module Calculator::Shipping describe FlatRate, type: :model do subject { Calculator::Shipping::FlatRate.new(preferred_amount: 4.00) } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Flat rate") } + end + it 'always returns the same rate' do expect(subject.compute(build(:stock_package_fulfilled))).to eql 4.00 end From e1e19d63ce289d5176b9e455831d4c6d4b6b9bcf Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:39:39 -0700 Subject: [PATCH 16/18] Use ActiveModel::Naming for Shipping::FlexiRate --- core/app/models/spree/calculator/shipping/flexi_rate.rb | 4 ---- core/config/locales/en.yml | 3 +++ .../spec/models/spree/calculator/shipping/flexi_rate_spec.rb | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/calculator/shipping/flexi_rate.rb b/core/app/models/spree/calculator/shipping/flexi_rate.rb index 21b208a4293..1f20a57385a 100644 --- a/core/app/models/spree/calculator/shipping/flexi_rate.rb +++ b/core/app/models/spree/calculator/shipping/flexi_rate.rb @@ -8,10 +8,6 @@ class FlexiRate < ShippingCalculator preference :max_items, :integer, default: 0 preference :currency, :string, default: ->{ Spree::Config[:currency] } - def self.description - Spree.t(:shipping_flexible_rate) - end - def compute_package(package) compute_from_quantity(package.contents.sum(&:quantity)) end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 249ef73f935..1c31ee49e64 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -404,6 +404,9 @@ en: spree/calculator/shipping/flat_rate: one: Flat rate other: Flat rate + spree/calculator/shipping/flexi_rate: + one: Flexible Rate per package item + other: Flexible Rate per package item spree/country: one: Country other: Countries diff --git a/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb b/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb index a65b42ce678..e7ee9f319c6 100644 --- a/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +++ b/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb @@ -6,6 +6,11 @@ module Calculator::Shipping let(:variant1) { build(:variant, price: 10) } let(:variant2) { build(:variant, price: 20) } + describe ".description" do + subject { described_class.description } + it { is_expected.to eq("Flexible Rate per package item") } + end + let(:package) do build(:stock_package, variants_contents: { variant1 => 4, variant2 => 6 }) end From fe403257e126b358afe269bab1eac575aaff63d5 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Thu, 20 Oct 2016 13:57:16 -0700 Subject: [PATCH 17/18] Sort calculator i18n alphabetically --- core/config/locales/en.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 1c31ee49e64..20019be21bf 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -368,33 +368,27 @@ en: spree/calculator/flat_rate: one: Flat Rate other: Flat Rate - spree/calculator/tiered_percent: - one: Tiered Percent - other: Tiered Percent - spree/calculator/tiered_flat_rate: - one: Tiered Flat Rate - other: Tiered Flat Rate - spree/calculator/percent_on_line_item: - one: Percent Per Item - other: Percent Per Item - spree/calculator/free_shipping: - one: Free Shipping - other: Free Shipping - spree/calculator/shipping/price_sack: - one: Price sack - other: Price sack - spree/calculator/shipping/per_item: - one: Flat rate per package item - other: Flat rate per package item spree/calculator/flexi_rate: one: Flexible Rate other: Flexible Rate + spree/calculator/free_shipping: + one: Free Shipping + other: Free Shipping + spree/calculator/percent_on_line_item: + one: Percent Per Item + other: Percent Per Item spree/calculator/percent_per_item: one: Percent Per Item other: Percent Per Item spree/calculator/price_sack: one: Price Sack other: Price Sack + spree/calculator/tiered_percent: + one: Tiered Percent + other: Tiered Percent + spree/calculator/tiered_flat_rate: + one: Tiered Flat Rate + other: Tiered Flat Rate spree/calculator/returns/default_refund_amount: one: Default Refund Amount other: Default Refund Amount @@ -407,6 +401,12 @@ en: spree/calculator/shipping/flexi_rate: one: Flexible Rate per package item other: Flexible Rate per package item + spree/calculator/shipping/per_item: + one: Flat rate per package item + other: Flat rate per package item + spree/calculator/shipping/price_sack: + one: Price sack + other: Price sack spree/country: one: Country other: Countries From aa1bfdffeedc8058227e4ab4da8f58791b6946e7 Mon Sep 17 00:00:00 2001 From: Graeme Nathan Date: Fri, 21 Oct 2016 17:24:16 -0700 Subject: [PATCH 18/18] Add shared example for calculator.description --- core/spec/models/spree/calculator/default_tax_spec.rb | 6 ++---- .../spree/calculator/flat_percent_item_total_spec.rb | 6 ++---- core/spec/models/spree/calculator/flat_rate_spec.rb | 6 ++---- core/spec/models/spree/calculator/flexi_rate_spec.rb | 6 ++---- core/spec/models/spree/calculator/free_shipping_spec.rb | 6 ++---- .../models/spree/calculator/percent_on_line_item_spec.rb | 6 ++---- .../spec/models/spree/calculator/percent_per_item_spec.rb | 6 ++---- core/spec/models/spree/calculator/price_sack_spec.rb | 6 ++---- .../calculator/refunds/default_refund_amount_spec.rb | 6 ++---- .../calculator/shipping/flat_percent_item_total_spec.rb | 6 ++---- .../models/spree/calculator/shipping/flat_rate_spec.rb | 6 ++---- .../models/spree/calculator/shipping/flexi_rate_spec.rb | 6 ++---- .../models/spree/calculator/shipping/per_item_spec.rb | 6 ++---- .../models/spree/calculator/shipping/price_sack_spec.rb | 6 ++---- .../spec/models/spree/calculator/tiered_flat_rate_spec.rb | 6 ++---- core/spec/models/spree/calculator/tiered_percent_spec.rb | 6 ++---- core/spec/shared_examples/calculator_shared_examples.rb | 8 ++++++++ 17 files changed, 40 insertions(+), 64 deletions(-) create mode 100644 core/spec/shared_examples/calculator_shared_examples.rb diff --git a/core/spec/models/spree/calculator/default_tax_spec.rb b/core/spec/models/spree/calculator/default_tax_spec.rb index f314d9ed90a..9d509efaff4 100644 --- a/core/spec/models/spree/calculator/default_tax_spec.rb +++ b/core/spec/models/spree/calculator/default_tax_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::DefaultTax, type: :model do let(:address) { create(:address) } @@ -9,10 +10,7 @@ let(:included_in_price) { false } subject(:calculator) { Spree::Calculator::DefaultTax.new(calculable: rate ) } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Default Tax") } - end + it_behaves_like 'a calculator with a description' context "#compute" do context "when given an order" do diff --git a/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb b/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb index 5c8bd1c6d03..8d572db14e1 100644 --- a/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb +++ b/core/spec/models/spree/calculator/flat_percent_item_total_spec.rb @@ -1,13 +1,11 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::FlatPercentItemTotal, type: :model do let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new } let(:line_item) { mock_model Spree::LineItem } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Flat Percent") } - end + it_behaves_like 'a calculator with a description' before { allow(calculator).to receive_messages preferred_flat_percent: 10 } diff --git a/core/spec/models/spree/calculator/flat_rate_spec.rb b/core/spec/models/spree/calculator/flat_rate_spec.rb index f3fe78e4676..0f4bfce8d2d 100644 --- a/core/spec/models/spree/calculator/flat_rate_spec.rb +++ b/core/spec/models/spree/calculator/flat_rate_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::FlatRate, type: :model do let(:calculator) { Spree::Calculator::FlatRate.new } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Flat Rate") } - end + it_behaves_like 'a calculator with a description' let(:order) do mock_model( diff --git a/core/spec/models/spree/calculator/flexi_rate_spec.rb b/core/spec/models/spree/calculator/flexi_rate_spec.rb index 2aec7fd5bc2..3b38d26b664 100644 --- a/core/spec/models/spree/calculator/flexi_rate_spec.rb +++ b/core/spec/models/spree/calculator/flexi_rate_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::FlexiRate, type: :model do let(:calculator) { Spree::Calculator::FlexiRate.new } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Flexible Rate") } - end + it_behaves_like 'a calculator with a description' let(:order) do mock_model( diff --git a/core/spec/models/spree/calculator/free_shipping_spec.rb b/core/spec/models/spree/calculator/free_shipping_spec.rb index 9cba4bddab0..f84c705f6e0 100644 --- a/core/spec/models/spree/calculator/free_shipping_spec.rb +++ b/core/spec/models/spree/calculator/free_shipping_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::FreeShipping, type: :model do - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Free Shipping") } - end + it_behaves_like 'a calculator with a description' end diff --git a/core/spec/models/spree/calculator/percent_on_line_item_spec.rb b/core/spec/models/spree/calculator/percent_on_line_item_spec.rb index 826124e0efa..d01e739801f 100644 --- a/core/spec/models/spree/calculator/percent_on_line_item_spec.rb +++ b/core/spec/models/spree/calculator/percent_on_line_item_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' module Spree class Calculator @@ -13,10 +14,7 @@ class Calculator end end - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Percent Per Item") } - end + it_behaves_like 'a calculator with a description' end end end diff --git a/core/spec/models/spree/calculator/percent_per_item_spec.rb b/core/spec/models/spree/calculator/percent_per_item_spec.rb index cd2906c9a10..0ef781f7169 100644 --- a/core/spec/models/spree/calculator/percent_per_item_spec.rb +++ b/core/spec/models/spree/calculator/percent_per_item_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' module Spree class Calculator describe PercentPerItem, type: :model do - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Percent Per Item") } - end + it_behaves_like 'a calculator with a description' end end end diff --git a/core/spec/models/spree/calculator/price_sack_spec.rb b/core/spec/models/spree/calculator/price_sack_spec.rb index 260bf3747f0..e12796197f9 100644 --- a/core/spec/models/spree/calculator/price_sack_spec.rb +++ b/core/spec/models/spree/calculator/price_sack_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::PriceSack, type: :model do let(:calculator) do @@ -9,10 +10,7 @@ calculator end - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Price Sack") } - end + it_behaves_like 'a calculator with a description' let(:order) { stub_model(Spree::Order) } let(:shipment) { stub_model(Spree::Shipment, amount: 10) } diff --git a/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb b/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb index a7d87baee8a..7397724b187 100644 --- a/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +++ b/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::Returns::DefaultRefundAmount, type: :model do let(:line_item_quantity) { 2 } @@ -9,10 +10,7 @@ let(:calculator) { Spree::Calculator::Returns::DefaultRefundAmount.new } let(:order) { line_item.order } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Default Refund Amount") } - end + it_behaves_like 'a calculator with a description' subject { calculator.compute(return_item) } diff --git a/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb b/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb index 18826027f36..c7dfd1faace 100644 --- a/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +++ b/core/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' module Spree module Calculator::Shipping @@ -6,10 +7,7 @@ module Calculator::Shipping let(:variant1) { build(:variant, price: 10.11) } let(:variant2) { build(:variant, price: 20.2222) } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Flat Percent") } - end + it_behaves_like 'a calculator with a description' let(:line_item1) { build(:line_item, variant: variant1) } let(:line_item2) { build(:line_item, variant: variant2) } diff --git a/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb b/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb index 716b9e81497..560d62a8ab3 100644 --- a/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb +++ b/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb @@ -1,14 +1,12 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' module Spree module Calculator::Shipping describe FlatRate, type: :model do subject { Calculator::Shipping::FlatRate.new(preferred_amount: 4.00) } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Flat rate") } - end + it_behaves_like 'a calculator with a description' it 'always returns the same rate' do expect(subject.compute(build(:stock_package_fulfilled))).to eql 4.00 diff --git a/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb b/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb index e7ee9f319c6..83e2c8588b9 100644 --- a/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +++ b/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' module Spree module Calculator::Shipping @@ -6,10 +7,7 @@ module Calculator::Shipping let(:variant1) { build(:variant, price: 10) } let(:variant2) { build(:variant, price: 20) } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Flexible Rate per package item") } - end + it_behaves_like 'a calculator with a description' let(:package) do build(:stock_package, variants_contents: { variant1 => 4, variant2 => 6 }) diff --git a/core/spec/models/spree/calculator/shipping/per_item_spec.rb b/core/spec/models/spree/calculator/shipping/per_item_spec.rb index 9051d3688e3..efd8e440df9 100644 --- a/core/spec/models/spree/calculator/shipping/per_item_spec.rb +++ b/core/spec/models/spree/calculator/shipping/per_item_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' module Spree module Calculator::Shipping @@ -6,10 +7,7 @@ module Calculator::Shipping let(:variant1) { build(:variant) } let(:variant2) { build(:variant) } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Flat rate per package item") } - end + it_behaves_like 'a calculator with a description' let(:package) do build(:stock_package, variants_contents: { variant1 => 5, variant2 => 3 }) diff --git a/core/spec/models/spree/calculator/shipping/price_sack_spec.rb b/core/spec/models/spree/calculator/shipping/price_sack_spec.rb index f4b1c11da08..8611133789a 100644 --- a/core/spec/models/spree/calculator/shipping/price_sack_spec.rb +++ b/core/spec/models/spree/calculator/shipping/price_sack_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::Shipping::PriceSack, type: :model do let(:calculator) do @@ -9,10 +10,7 @@ calculator end - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Price sack") } - end + it_behaves_like 'a calculator with a description' let(:order) { stub_model(Spree::Order) } let(:shipment) { stub_model(Spree::Shipment, amount: 10) } diff --git a/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb b/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb index cb38867a94b..fb25a164a51 100644 --- a/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb +++ b/core/spec/models/spree/calculator/tiered_flat_rate_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::TieredFlatRate, type: :model do let(:calculator) { Spree::Calculator::TieredFlatRate.new } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Tiered Flat Rate") } - end + it_behaves_like 'a calculator with a description' describe "#valid?" do subject { calculator.valid? } diff --git a/core/spec/models/spree/calculator/tiered_percent_spec.rb b/core/spec/models/spree/calculator/tiered_percent_spec.rb index ee4287e887b..10efe34f59f 100644 --- a/core/spec/models/spree/calculator/tiered_percent_spec.rb +++ b/core/spec/models/spree/calculator/tiered_percent_spec.rb @@ -1,12 +1,10 @@ require 'spec_helper' +require 'shared_examples/calculator_shared_examples' describe Spree::Calculator::TieredPercent, type: :model do let(:calculator) { Spree::Calculator::TieredPercent.new } - describe ".description" do - subject { described_class.description } - it { is_expected.to eq("Tiered Percent") } - end + it_behaves_like 'a calculator with a description' describe "#valid?" do subject { calculator.valid? } diff --git a/core/spec/shared_examples/calculator_shared_examples.rb b/core/spec/shared_examples/calculator_shared_examples.rb new file mode 100644 index 00000000000..ffc40f1316c --- /dev/null +++ b/core/spec/shared_examples/calculator_shared_examples.rb @@ -0,0 +1,8 @@ +shared_examples_for 'a calculator with a description' do + describe ".description" do + subject { described_class.description } + it "has a description" do + expect(subject.size).to be > 0 + end + end +end