Skip to content

Commit

Permalink
Deprecate .calculators
Browse files Browse the repository at this point in the history
There are almost no reasonable reasons why these should be called
through the class models the way they are, near as I can tell they're
only ever used for display/form purposes in the backend.
  • Loading branch information
Clarke Brunsdon committed Sep 11, 2017
1 parent ef1cc79 commit 8dfedd2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Spree::Admin::PromotionActionsController < Spree::Admin::BaseController
before_action :validate_promotion_action_type, only: :create

def create
@calculators = Spree::Promotion::Actions::CreateAdjustment.calculators
@calculators = Rails.application.config.spree.calculators.promotion_actions_create_adjustments
@promotion_action = @promotion_action_type.new(params[:promotion_action])
@promotion_action.promotion = @promotion
if @promotion_action.save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def location_after_save
def load_data
@available_zones = Spree::Zone.order(:name)
@tax_categories = Spree::TaxCategory.order(:name)
@calculators = Spree::ShippingMethod.calculators.sort_by(&:name)
@calculators = Rails.application.config.spree.calculators.shipping_methods
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TaxRatesController < ResourceController
def load_data
@available_zones = Spree::Zone.order(:name)
@available_categories = Spree::TaxCategory.order(:name)
@calculators = Spree::TaxRate.calculators.sort_by(&:name)
@calculators = Rails.application.config.spree.calculators.tax_rates
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= render(
"spree/admin/promotions/actions/promotion_calculators_with_custom_fields",
calculators: Spree::Promotion::Actions::CreateItemAdjustments.calculators,
calculators: Rails.application.config.spree.calculators.promotion_actions_create_item_adjustments,
promotion_action: promotion_action,
param_prefix: param_prefix
) %>
2 changes: 2 additions & 0 deletions core/app/models/concerns/spree/calculated_adjustments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module CalculatedAdjustments

class_methods do
def calculators
Spree::Deprecation.warn("Calling .calculators is deprecated. Please access through Rails.application.config.spree.calculators")

spree_calculators.send model_name_without_spree_namespace
end

Expand Down
2 changes: 2 additions & 0 deletions core/app/models/spree/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def self.description

# Returns all calculators applicable for kind of work
def self.calculators
Spree::Deprecation.warn("Calling .calculators is deprecated. Please access through Rails.application.config.spree.calculators")

Rails.application.config.spree.calculators
end

Expand Down
10 changes: 10 additions & 0 deletions core/spec/models/spree/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ def compute_simple_computable(_line_item)
class SimpleComputable
end

describe "#calculators" do
subject { Spree::Calculator.calculators }

it 'returns the (deprecated) calculator step' do
Spree::Deprecation.silence do
expect(subject).to be_a Spree::Core::Environment::Calculators
end
end
end

context "with computable" do
let(:calculator) { SimpleCalculator.new }
let(:computable) { SimpleComputable.new }
Expand Down

0 comments on commit 8dfedd2

Please sign in to comment.