From 3e39f3e7499e4b3c3c9ad9d8ae7204c8159a2c7c Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 8 Oct 2018 23:06:54 +0100 Subject: [PATCH 1/3] Disable logout on password change --- config/initializers/spree.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 9b62e3ad6e..e63d21bde9 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -22,6 +22,9 @@ Spree.config do |config| #config.override_actionmailer_config = false end +# Don't log users out when setting a new password +Spree::Auth::Config[:signout_after_password_change] = false + # TODO Work out why this is necessary # Seems like classes within OFN module become 'uninitialized' when server reloads # unless the empty module is explicity 'registered' here. Something to do with autoloading? From 55411af3fa09db906a3723bac36977a03f78b9b9 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 8 Oct 2018 23:55:28 +0100 Subject: [PATCH 2/3] Improve user account spec --- .../consumer/account/settings_spec.rb | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb index 383d03a4be..e9001f177c 100644 --- a/spec/features/consumer/account/settings_spec.rb +++ b/spec/features/consumer/account/settings_spec.rb @@ -4,18 +4,22 @@ feature "Account Settings", js: true do include AuthenticationWorkflow describe "as a logged in user" do - let(:user) { create(:user, email: 'old@email.com') } + let(:user) do + create(:user, + email: 'old@email.com', + password: 'OriginalPassword', + password_confirmation: 'OriginalPassword') + end before do create(:mail_method) quick_login_as user - end - - it "allows me to update my account details" do visit "/account" - click_link I18n.t('spree.users.show.tabs.settings') expect(page).to have_content I18n.t('spree.users.form.account_settings') + end + + it "allows the user to update their email address" do fill_in 'user_email', with: 'new@email.com' click_button I18n.t(:update) @@ -27,5 +31,18 @@ feature "Account Settings", js: true do click_link I18n.t('spree.users.show.tabs.settings') expect(page).to have_content I18n.t('spree.users.show.unconfirmed_email', unconfirmed_email: 'new@email.com') end + + it "allows the user to change their password" do + allow(Spree::Auth::Config).to receive(:[]).with(:signout_after_password_change).and_return(false) + initial_password = user.encrypted_password + + fill_in 'user_password', with: 'NewPassword' + fill_in 'user_password_confirmation', with: 'NewPassword' + + click_button I18n.t(:update) + expect(find(".alert-box.success").text.strip).to eq "#{I18n.t(:account_updated)} ×" + + expect(user.reload.encrypted_password).to_not eq initial_password + end end end From 4760ebb80c908b70a9fd5a0d184a57a49d2b36b3 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Oct 2018 09:04:37 +0100 Subject: [PATCH 3/3] Use global config --- spec/features/consumer/account/settings_spec.rb | 1 - spec/spec_helper.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb index e9001f177c..32dc8d3534 100644 --- a/spec/features/consumer/account/settings_spec.rb +++ b/spec/features/consumer/account/settings_spec.rb @@ -33,7 +33,6 @@ feature "Account Settings", js: true do end it "allows the user to change their password" do - allow(Spree::Auth::Config).to receive(:[]).with(:signout_after_password_change).and_return(false) initial_password = user.encrypted_password fill_in 'user_password', with: 'NewPassword' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 328c2aaac3..6b73d23fb0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -120,6 +120,7 @@ RSpec.configure do |config| spree_config.allow_backorders = false end + Spree::Auth::Config[:signout_after_password_change] = false Spree::Api::Config[:requires_authentication] = true end