Skip to content

Commit

Permalink
Add deprecated version of display_on
Browse files Browse the repository at this point in the history
This allows any existing code which used display_on to continue working.
It's likely that specs will be using this.
  • Loading branch information
John Hawthorn committed Nov 15, 2016
1 parent fa94154 commit bd4e841
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
23 changes: 23 additions & 0 deletions core/app/models/spree/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ def payment_source_class
raise ::NotImplementedError, "You must implement payment_source_class method for #{self.class}."
end

# @deprecated Use {#available_to_users=} and {#available_to_admin=} instead
def display_on=(value)
Spree::Deprecation.warn "Spree::PaymentMethod#display_on= is deprecated."\
"Please use #available_to_users= and #available_to_admin= instead."
self.available_to_users = value.blank? || value == 'front_end'
self.available_to_admin = value.blank? || value == 'back_end'
end

# @deprecated Use {#available_to_users} and {#available_to_admin} instead
def display_on
Spree::Deprecation.warn "Spree::PaymentMethod#display_on is deprecated."\
"Please use #available_to_users and #available_to_admin instead."
if available_to_users? && available_to_admin?
''
elsif available_to_users?
'front_end'
elsif available_to_admin?
'back_end'
else
'none'
end
end

def self.available(display_on=nil, store: nil)
Spree::Deprecation.warn "Spree::PaymentMethod.available is deprecated."\
"Please use .active, .available_to_users, and .available_to_admin scopes instead."\
Expand Down
73 changes: 73 additions & 0 deletions core/spec/models/spree/payment_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,77 @@ def provider_class
end
end
end

describe "display_on=" do
around do |example|
Spree::Deprecation.silence do
example.run
end
end
let(:payment) { described_class.new(display_on: display_on) }

context 'with empty string' do
let(:display_on) { "" }

it "should be available to admins" do
expect(payment.available_to_admin).to be true
end

it "should be available to users" do
expect(payment.available_to_users).to be true
end

it "should have the same value for display_on" do
expect(payment.display_on).to eq ""
end
end

context 'with "back_end"' do
let(:display_on) { "back_end" }

it "should be available to admins" do
expect(payment.available_to_admin).to be true
end

it "should not be available to users" do
expect(payment.available_to_users).to be false
end

it "should have the same value for display_on" do
expect(payment.display_on).to eq "back_end"
end
end

context 'with "front_end"' do
let(:display_on) { "front_end" }

it "should be available to admins" do
expect(payment.available_to_admin).to be false
end

it "should not be available to users" do
expect(payment.available_to_users).to be true
end

it "should have the same value for display_on" do
expect(payment.display_on).to eq "front_end"
end
end

context 'with any other string' do
let(:display_on) { "foobar" }

it "should be available to admins" do
expect(payment.available_to_admin).to be false
end

it "should not be available to users" do
expect(payment.available_to_users).to be false
end

it "should have none for display_on" do
expect(payment.display_on).to eq "none"
end
end
end
end

0 comments on commit bd4e841

Please sign in to comment.