Skip to content

Commit

Permalink
Deprecate ShippingMethod#display_on
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Nov 24, 2016
1 parent fd7da43 commit 58ab9eb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

let(:country) { create(:country, name: "Kangaland") }
let(:state) { create(:state, name: "Alabama", country: country) }
let!(:shipping_method) { create(:shipping_method, display_on: "front_end") }
let!(:shipping_method) { create(:shipping_method) }
let!(:order) { create(:order, ship_address: ship_address, bill_address: bill_address, state: 'complete', completed_at: "2011-02-01 12:36:15") }
let!(:product) { create(:product_in_stock) }

Expand Down
5 changes: 4 additions & 1 deletion core/app/models/spree/shipping_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ def display_on
"back_end"
end
end
deprecate display_on: :available_to_users?, deprecator: Spree::Deprecation

def display_on=(value)
self.available_to_users = (value != "back_end")
end
deprecate 'display_on=': :available_to_users=, deprecator: Spree::Deprecation

# Some shipping methods are only meant to be set via backend
def frontend?
display_on != "back_end"
available_to_users?
end
deprecate frontend?: :available_to_users?, deprecator: Spree::Deprecation

private

Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/stock/estimator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def shipping_rates(package, frontend_only = true)
raise OrderRequired if package.shipment.order.nil?

rates = calculate_shipping_rates(package)
rates.select! { |rate| rate.shipping_method.frontend? } if frontend_only
rates.select! { |rate| rate.shipping_method.available_to_users? } if frontend_only
choose_default_shipping_rate(rates)
Spree::Config.shipping_rate_sorter_class.new(rates).sort
end
Expand Down
8 changes: 6 additions & 2 deletions core/spec/models/spree/shipping_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def matching(categories)

describe "display_on=" do
subject do
described_class.new(display_on: display_on).available_to_users
Spree::Deprecation.silence do
described_class.new(display_on: display_on).available_to_users
end
end

context "with 'back_end'" do
Expand All @@ -234,7 +236,9 @@ def matching(categories)

describe "display_on" do
subject do
described_class.new(available_to_users: available_to_users).display_on
Spree::Deprecation.silence do
described_class.new(available_to_users: available_to_users).display_on
end
end

context "when available_to_users is true" do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/stock/estimator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module Stock

context "involves backend only shipping methods" do
before{ Spree::ShippingMethod.destroy_all }
let!(:backend_method) { create(:shipping_method, display_on: "back_end", cost: 0.00) }
let!(:backend_method) { create(:shipping_method, available_to_users: false, cost: 0.00) }
let!(:generic_method) { create(:shipping_method, cost: 5.00) }

it "does not return backend rates at all" do
Expand Down

0 comments on commit 58ab9eb

Please sign in to comment.