From 78eb0f58c10a3d8dcc3dbe766b7973a11fb70e1d Mon Sep 17 00:00:00 2001 From: Connor Ferguson <68167430+cpfergus1@users.noreply.github.com> Date: Fri, 2 Sep 2022 13:47:15 -0600 Subject: [PATCH 1/2] Deprecate #redirect_to_or_default Devise has a nearly identical method for storing a user's location and returning a path to navigate to. Deprecating to simplify the code base. --- core/lib/spree/core/controller_helpers/auth.rb | 6 ++++++ core/spec/lib/spree/core/controller_helpers/auth_spec.rb | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/lib/spree/core/controller_helpers/auth.rb b/core/lib/spree/core/controller_helpers/auth.rb index 21125053918..a8207d22e4c 100644 --- a/core/lib/spree/core/controller_helpers/auth.rb +++ b/core/lib/spree/core/controller_helpers/auth.rb @@ -37,6 +37,12 @@ def current_ability end def redirect_back_or_default(default) + Spree::Deprecation.warn <<~MSG + 'Please use #stored_spree_user_location_or when using solidus_auth_devise. + Otherwise, please utilize #redirect_back provided in Rails 5+ or + #redirect_back_or_to in Rails 7+ instead' + MSG + redirect_to(session["spree_user_return_to"] || default) session["spree_user_return_to"] = nil end diff --git a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb index 9a127472c83..93bdbe078f3 100644 --- a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb +++ b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb @@ -17,7 +17,7 @@ def index; render plain: 'index'; end describe '#redirect_back_or_default' do before do def controller.index - redirect_back_or_default('/') + Spree::Deprecation.silence { redirect_back_or_default('/') } end end @@ -30,6 +30,11 @@ def controller.index get :index expect(response).to redirect_to('/') end + + it 'is deprecated' do + expect(Spree::Deprecation).to receive(:warn) + get :index + end end describe '#set_guest_token' do From a6de90edccd0605b3143785b093d291b3134a611 Mon Sep 17 00:00:00 2001 From: Connor Ferguson <68167430+cpfergus1@users.noreply.github.com> Date: Fri, 2 Sep 2022 13:54:12 -0600 Subject: [PATCH 2/2] Deprecate Spree::UserLastUrlStorer We can safely eliminate the class when #redirect_back_or_default is removed. This commit also deprecates #store_location which is the only method that utilizes this class. --- core/app/models/spree/user_last_url_storer.rb | 1 + core/lib/spree/core/controller_helpers/auth.rb | 5 +++++ core/spec/lib/spree/core/controller_helpers/auth_spec.rb | 2 +- core/spec/models/spree/user_last_url_storer_spec.rb | 9 +++++++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/app/models/spree/user_last_url_storer.rb b/core/app/models/spree/user_last_url_storer.rb index 01cbb1bd37c..8aa7644b36c 100644 --- a/core/app/models/spree/user_last_url_storer.rb +++ b/core/app/models/spree/user_last_url_storer.rb @@ -26,6 +26,7 @@ def self.rules # or its subclasses. The controller will be passed to each rule for matching. def initialize(controller) @controller = controller + Spree::Deprecation.warn("This class will be removed without replacement on the release of Solidus 4.0") end # Stores into session[:spree_user_return_to] the request full path for diff --git a/core/lib/spree/core/controller_helpers/auth.rb b/core/lib/spree/core/controller_helpers/auth.rb index a8207d22e4c..35afa14534d 100644 --- a/core/lib/spree/core/controller_helpers/auth.rb +++ b/core/lib/spree/core/controller_helpers/auth.rb @@ -57,6 +57,11 @@ def set_guest_token end def store_location + Spree::Deprecation.warn <<~MSG + store_location is being deprecated in solidus 4.0 + without replacement + MSG + Spree::UserLastUrlStorer.new(self).store_location end diff --git a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb index 93bdbe078f3..5087a0878ed 100644 --- a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb +++ b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb @@ -74,7 +74,7 @@ def controller.index describe '#store_location' do it 'sets session return url' do allow(controller).to receive_messages(request: double(fullpath: '/redirect')) - controller.store_location + Spree::Deprecation.silence { controller.store_location } expect(session[:spree_user_return_to]).to eq '/redirect' end end diff --git a/core/spec/models/spree/user_last_url_storer_spec.rb b/core/spec/models/spree/user_last_url_storer_spec.rb index aa3c7794583..8e0ad252947 100644 --- a/core/spec/models/spree/user_last_url_storer_spec.rb +++ b/core/spec/models/spree/user_last_url_storer_spec.rb @@ -27,6 +27,11 @@ def self.match?(_controller) described_class.rules.delete('CustomRule') end + it 'is deprecated' do + expect(Spree::Deprecation).to receive(:warn) + described_class.new(controller) + end + describe '::rules' do it 'includes default rules' do rule = Spree::UserLastUrlStorer::Rules::AuthenticationRule @@ -43,7 +48,7 @@ def self.match?(_controller) context 'when at least one rule matches' do it 'does not set the path value into the session' do described_class.rules << CustomRule - subject.store_location + Spree::Deprecation.silence { subject.store_location } expect(session[:spree_user_return_to]).to be_nil end end @@ -52,7 +57,7 @@ def self.match?(_controller) it 'sets the path value into the session' do described_class.rules << CustomRule described_class.rules.delete('CustomRule') - subject.store_location + Spree::Deprecation.silence { subject.store_location } expect(session[:spree_user_return_to]).to eql fullpath end end