From 868a998b374b646e7c6405c461c0e19c18d25df8 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 26 Mar 2018 16:25:23 -0700 Subject: [PATCH 1/5] Fix yard docs for PaymentMethod --- core/app/models/spree/payment_method.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb index 8ef52c85eef..eb7bc3f6c1f 100644 --- a/core/app/models/spree/payment_method.rb +++ b/core/app/models/spree/payment_method.rb @@ -145,7 +145,7 @@ 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 + # @deprecated Use {Spree::PaymentMethod#available_to_users=} and {Spree::PaymentMethod#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." @@ -153,7 +153,7 @@ def display_on=(value) self.available_to_admin = value.blank? || value == 'back_end' end - # @deprecated Use {#available_to_users} and {#available_to_admin} instead + # @deprecated Use {Spree::PaymentMethod#available_to_users} and {Spree::PaymentMethod#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." @@ -210,8 +210,8 @@ def source_required? true end - # Custom gateways should redefine this method. See Gateway implementation - # as an example + # Custom gateways can redefine this method to return reusable sources for an order. + # See {Spree::PaymentMethod::CreditCard#reusable_sources} as an example def reusable_sources(_order) [] end From 9ed30e770b39b0d00561abaa3d9978976d368a34 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Tue, 27 Mar 2018 13:26:54 -0700 Subject: [PATCH 2/5] Stop using PaymentMethod.find_with_destroyed We were only using it from a helper, which is unnecessary now that the payment.payment_method association includes deleted payment methods. --- backend/app/helpers/spree/admin/payments_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/app/helpers/spree/admin/payments_helper.rb b/backend/app/helpers/spree/admin/payments_helper.rb index 3b3f11679eb..0c2d8305d70 100644 --- a/backend/app/helpers/spree/admin/payments_helper.rb +++ b/backend/app/helpers/spree/admin/payments_helper.rb @@ -4,9 +4,7 @@ module Spree module Admin module PaymentsHelper def payment_method_name(payment) - # HACK: to allow us to retrieve the name of a "deleted" payment method - id = payment.payment_method_id - Spree::PaymentMethod.find_with_destroyed(id).name + payment.payment_method.name end end end From aa5b3f77d6bd2ab8ddcda5d2cb80cda41e1828aa Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 26 Mar 2018 16:33:21 -0700 Subject: [PATCH 3/5] Deprecate PaymentMethod.find_with_destroyed --- core/app/models/spree/payment_method.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb index eb7bc3f6c1f..51cc082be3f 100644 --- a/core/app/models/spree/payment_method.rb +++ b/core/app/models/spree/payment_method.rb @@ -99,7 +99,9 @@ def active? where(type: to_s, active: true).count > 0 end + # @deprecated Use .with_deleted.find instead def find_with_destroyed(*args) + Spree::Deprecation.warn "#{self}.find_with_destroyed is deprecated. Use #{self}.with_deleted.find instead" unscoped { find(*args) } end end From 3015d2d6c20bed9b0d2c461df09fe4befb2adb0d Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 26 Mar 2018 16:33:53 -0700 Subject: [PATCH 4/5] Deprecate PaymentMethod.active? --- core/app/models/spree/payment_method.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb index 51cc082be3f..40cd41fd46b 100644 --- a/core/app/models/spree/payment_method.rb +++ b/core/app/models/spree/payment_method.rb @@ -95,7 +95,9 @@ def model_name ModelName.new(self, Spree) end + # @deprecated Use .active.any? instead def active? + Spree::Deprecation.warn "#{self}.active? is deprecated. Use #{self}.active.any? instead" where(type: to_s, active: true).count > 0 end From aaed1ec0f296523765773d21c4adea8067c812ad Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 26 Mar 2018 16:49:38 -0700 Subject: [PATCH 5/5] Deprecate PaymentMethod::DISPLAY --- core/app/models/spree/payment_method.rb | 12 +++++++++++- core/spec/models/spree/payment_method_spec.rb | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb index 40cd41fd46b..5ab5f97cc31 100644 --- a/core/app/models/spree/payment_method.rb +++ b/core/app/models/spree/payment_method.rb @@ -25,7 +25,15 @@ class PaymentMethod < Spree::Base self.discard_column = :deleted_at acts_as_list - DISPLAY = [:both, :front_end, :back_end] + + # @private + def self.const_missing(name) + if name == :DISPLAY + const_set(:DISPLAY, [:both, :front_end, :back_end]) + else + super + end + end validates :name, :type, presence: true @@ -63,12 +71,14 @@ def human(options = {}) end class << self + # @deprecated Use Spree::Config.environment.payment_methods instead def providers Spree::Deprecation.warn 'Spree::PaymentMethod.providers is deprecated and will be deleted in Solidus 3.0. ' \ 'Please use Rails.application.config.spree.payment_methods instead' Spree::Config.environment.payment_methods end + # @deprecated Use {.active}, {.available_to_users}, and {.available_to_admin} scopes instead. def 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."\ diff --git a/core/spec/models/spree/payment_method_spec.rb b/core/spec/models/spree/payment_method_spec.rb index dfc70d214d9..6f2b0ff9213 100644 --- a/core/spec/models/spree/payment_method_spec.rb +++ b/core/spec/models/spree/payment_method_spec.rb @@ -393,4 +393,16 @@ def gateway_class end end end + + describe "::DISPLAY" do + it "returns [:both, :front_end, :back_end]" do + # Emits deprecation warning on first reference + Spree::Deprecation.silence do + expect(Spree::PaymentMethod::DISPLAY).to eq([:both, :front_end, :back_end]) + end + + # but not subsequent + expect(Spree::PaymentMethod::DISPLAY).to eq([:both, :front_end, :back_end]) + end + end end