From 465a4d37e713de9df7f37feeee00c03d66113179 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 13:28:18 +0000 Subject: [PATCH 01/41] Test spec fix. --- spec/features/admin/sign_out_spec.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index c14af511..afdb5191 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -1,21 +1,26 @@ +# frozen_string_literal: true + RSpec.feature 'Admin - Sign Out', type: :feature, js: true do - given!(:user) do - create :user, email: 'email@person.com' - end + let(:user) { create(:user, email: 'email@person.com') } - background do + before do + I18n.locale = :en visit spree.admin_login_path + fill_in 'Email', with: user.email fill_in 'Password', with: 'secret' + # Regression test for #1257 check 'Remember me' click_button Spree.t(:login) end - scenario 'allows a signed in user to logout' do - log_out - visit spree.admin_login_path - expect(page).to have_button Spree.t(:login) - expect(page).not_to have_text Spree.t(:logout) + describe 'allows a signed in user to logout' do + it 'goes to the logout page' do + log_out + visit spree.admin_login_path + expect(page).to have_button Spree.t(:login) + expect(page).not_to have_text Spree.t(:logout) + end end end From bcdad52f2a49ac5c28874e6ff4ec7cc9db9e2ecc Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 13:48:31 +0000 Subject: [PATCH 02/41] Update rspec syntax --- spec/features/admin/sign_out_spec.rb | 3 ++- spec/features/change_email_spec.rb | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index afdb5191..d33510d4 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -16,8 +16,9 @@ end describe 'allows a signed in user to logout' do - it 'goes to the logout page' do + it 'shows the login page' do log_out + visit spree.admin_login_path expect(page).to have_button Spree.t(:login) expect(page).not_to have_text Spree.t(:logout) diff --git a/spec/features/change_email_spec.rb b/spec/features/change_email_spec.rb index e727eb3e..f05233b2 100644 --- a/spec/features/change_email_spec.rb +++ b/spec/features/change_email_spec.rb @@ -1,19 +1,24 @@ +# frozen_string_literal: true + RSpec.feature 'Change email', type: :feature do - background do + before do allow_bypass_sign_in + I18n.locale = :en user = create(:user, email: 'old@spree.com', password: 'secret') log_in(email: user.email, password: 'secret') visit spree.edit_account_path end - scenario 'work with correct password', js: true do - fill_in 'user_email', with: 'tests@example.com' - fill_in 'user_password', with: 'password' - fill_in 'user_password_confirmation', with: 'password' - click_button 'Update' + describe 'work with correct password', js: true do + it 'Updates account' do + fill_in 'user_email', with: 'tests@example.com' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' + click_button 'Update' - expect(page).to have_text 'Account updated' - expect(page).to have_text 'tests@example.com' + expect(page).to have_text 'Account updated' + expect(page).to have_text 'tests@example.com' + end end end From 2a8ad72261bcca5b6ec5161d31de780da5298f40 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 14:10:28 +0000 Subject: [PATCH 03/41] Use locale. --- spec/features/admin/sign_in_spec.rb | 2 +- spec/features/admin/sign_out_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/admin/sign_in_spec.rb b/spec/features/admin/sign_in_spec.rb index 711311b2..2ab6d052 100644 --- a/spec/features/admin/sign_in_spec.rb +++ b/spec/features/admin/sign_in_spec.rb @@ -30,7 +30,7 @@ scenario 'lets a user sign in successfully', js: true do log_in(email: @user.email, password: 'secret', locale: 'fr') show_user_menu - + expect(page).not_to have_text login_button.upcase expect(page).to have_text logout_button.upcase expect(current_path).to eq '/fr/account' diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index d33510d4..7e029fb1 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -7,8 +7,8 @@ I18n.locale = :en visit spree.admin_login_path - fill_in 'Email', with: user.email - fill_in 'Password', with: 'secret' + fill_in Spree.t(:email), with: user.email + fill_in Spree.t(:password), with: 'secret' # Regression test for #1257 check 'Remember me' From 020266ec105e593830a97292e2fba979e18b56ee Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 14:22:18 +0000 Subject: [PATCH 04/41] Reset locale after test. --- spec/controllers/spree/checkout_controller_spec.rb | 8 ++++++++ spec/features/admin/sign_out_spec.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 0ad79f06..e7e6baa9 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -16,6 +16,8 @@ Spree::Auth::Config.set(registration_step: true) end + after { I18n.locale = :en } + context 'when authenticated as registered user' do before { allow(controller).to receive(:spree_current_user) { user } } @@ -83,6 +85,8 @@ end end + after { I18n.locale = :en } + it 'redirects to the tokenized order view' do if Spree.version.to_f > 3.6 request.cookie_jar.signed[:token] = 'ABC' @@ -114,6 +118,8 @@ end end + after { I18n.locale = :en } + it 'redirects to the standard order view' do post :update, params: { state: 'confirm' } expect(response).to redirect_to spree.order_path(order) @@ -150,6 +156,8 @@ context '#update_registration' do let(:user) { build(:user) } + after { I18n.locale = :en } + it 'does not check registration' do controller.stub :check_authorization order.stub update: true diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 7e029fb1..88a9d787 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.feature 'Admin - Sign Out', type: :feature, js: true do +RSpec.feature 'Admin - Sign Out', type: :feature, js: false do let(:user) { create(:user, email: 'email@person.com') } before do From a27ec8a17845f6fa22b385788e3628325324dc96 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 15:27:11 +0000 Subject: [PATCH 05/41] Ensure locale is set to :en after tests. --- spec/controllers/spree/checkout_controller_spec.rb | 4 ++-- .../spree/user_registrations_controller_spec.rb | 4 ++-- spec/controllers/spree/user_sessions_controller_spec.rb | 8 ++++++-- spec/controllers/spree/users_controller_spec.rb | 2 ++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index e7e6baa9..a90a6f39 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -76,6 +76,8 @@ allow(order).to receive(:payment_required?) { false } end + after { I18n.locale = :en } + context 'with a token' do before do if Spree.version.to_f > 3.6 @@ -85,8 +87,6 @@ end end - after { I18n.locale = :en } - it 'redirects to the tokenized order view' do if Spree.version.to_f > 3.6 request.cookie_jar.signed[:token] = 'ABC' diff --git a/spec/controllers/spree/user_registrations_controller_spec.rb b/spec/controllers/spree/user_registrations_controller_spec.rb index c2866398..e2072120 100644 --- a/spec/controllers/spree/user_registrations_controller_spec.rb +++ b/spec/controllers/spree/user_registrations_controller_spec.rb @@ -4,6 +4,8 @@ context '#create' do before { allow(controller).to receive(:after_sign_up_path_for).and_return(spree.account_path) } + after { I18n.locale = :en } + it 'redirects to account_path' do post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } } expect(response).to redirect_to spree.account_path @@ -14,8 +16,6 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') end - after { I18n.locale = :en } - it 'redirects to account_path with locale' do post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }, locale: 'fr'} expect(response).to redirect_to spree.account_path(locale: 'fr') diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb index 9262221e..19b32227 100644 --- a/spec/controllers/spree/user_sessions_controller_spec.rb +++ b/spec/controllers/spree/user_sessions_controller_spec.rb @@ -149,7 +149,7 @@ order.reload expect(order.user_id).to eq user.id expect(order.created_by_id).to eq user.id - end + end end context "and html format is used" do @@ -163,6 +163,8 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') if Spree.version.to_f >= 4.2 end + after { I18n.locale = :en} + it 'redirects to localized account path after signing in' do skip if Spree.version.to_f < 4.2 post :create, params: { spree_user: { email: user.email, password: 'secret' }, locale: 'fr' } @@ -206,6 +208,8 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') end + after { I18n.locale = :en} + it "redirects to login page after signing out with default locale" do post :create, params: { spree_user: { email: user.email, password: 'secret' }} delete :destroy @@ -217,5 +221,5 @@ delete :destroy, params: { locale: 'fr' } expect(response).to redirect_to spree.login_path(locale: 'fr') end -end + end end diff --git a/spec/controllers/spree/users_controller_spec.rb b/spec/controllers/spree/users_controller_spec.rb index 0bfd6a93..14fcf525 100644 --- a/spec/controllers/spree/users_controller_spec.rb +++ b/spec/controllers/spree/users_controller_spec.rb @@ -8,6 +8,8 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') end + after { I18n.locale = :en} + context '#load_object' do it 'redirects to signup path if user is not found' do allow(controller).to receive(:spree_current_user) { nil } From f8b0e469f9f2f1af41b2f44184b70d1e386acf8f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 15:40:10 +0000 Subject: [PATCH 06/41] Test without spec --- spec/features/admin/sign_out_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 88a9d787..9c5999c5 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -4,10 +4,9 @@ let(:user) { create(:user, email: 'email@person.com') } before do - I18n.locale = :en visit spree.admin_login_path - fill_in Spree.t(:email), with: user.email + fill_in 'Email', with: user.email fill_in Spree.t(:password), with: 'secret' # Regression test for #1257 @@ -15,11 +14,12 @@ click_button Spree.t(:login) end - describe 'allows a signed in user to logout' do + xdescribe 'allows a signed in user to logout' do it 'shows the login page' do log_out visit spree.admin_login_path + expect(page).to have_button Spree.t(:login) expect(page).not_to have_text Spree.t(:logout) end From 8a0e2aaadb909927c73d3a931b947ddf380be948 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 15:47:10 +0000 Subject: [PATCH 07/41] Admin Test --- spec/features/admin/sign_out_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 9c5999c5..79e237d2 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.feature 'Admin - Sign Out', type: :feature, js: false do +RSpec.feature 'Admin - Sign Out', type: :feature, js: true do let(:user) { create(:user, email: 'email@person.com') } before do @@ -14,7 +14,7 @@ click_button Spree.t(:login) end - xdescribe 'allows a signed in user to logout' do + describe 'allows a signed in user to logout' do it 'shows the login page' do log_out From 9cc23ed0959fbfe99bff57be9eea0dae487b997f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 15:56:23 +0000 Subject: [PATCH 08/41] Lint file. --- .../spree/user_sessions_controller_spec.rb | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb index 19b32227..e5dbdc74 100644 --- a/spec/controllers/spree/user_sessions_controller_spec.rb +++ b/spec/controllers/spree/user_sessions_controller_spec.rb @@ -72,7 +72,7 @@ else order = create(:order, email: user.email, guest_token: 'ABC', user_id: nil, created_by_id: nil) end - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } order.reload expect(order.user_id).to eq user.id @@ -85,7 +85,7 @@ else order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil) end - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } order.reload expect(order.user_id).to eq user.id @@ -111,22 +111,22 @@ it 'does not assign orders with an existing user' do if Spree.version.to_f > 3.6 - order = create(:order, token: 'ABC', user_id: 200) + order = create(:order, token: 'ABC', user_id: 200) else - order = create(:order, guest_token: 'ABC', user_id: 200) + order = create(:order, guest_token: 'ABC', user_id: 200) end - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } expect(order.reload.user_id).to eq 200 end it 'does not assign orders with a different token' do if Spree.version.to_f > 3.6 - order = create(:order, token: 'DEF', user_id: nil, created_by_id: nil) + order = create(:order, token: 'DEF', user_id: nil, created_by_id: nil) else - order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil) + order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil) end - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } expect(order.reload.user_id).to be_nil end @@ -144,7 +144,7 @@ else order = create(:order, email: user.email, guest_token: 'ABC', user_id: nil, created_by_id: nil) end - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } order.reload expect(order.user_id).to eq user.id @@ -154,7 +154,7 @@ context "and html format is used" do it "redirects to account path after signing in" do - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } expect(response).to redirect_to spree.account_path end @@ -163,7 +163,7 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') if Spree.version.to_f >= 4.2 end - after { I18n.locale = :en} + after { I18n.locale = :en } it 'redirects to localized account path after signing in' do skip if Spree.version.to_f < 4.2 @@ -187,7 +187,7 @@ context "using incorrect login information" do context "and html format is used" do it "renders new template again with errors" do - post :create, params: { spree_user: { email: user.email, password: 'wrong' }} + post :create, params: { spree_user: { email: user.email, password: 'wrong' } } expect(response).to render_template('new') expect(flash[:error]).to eq I18n.t(:'devise.failure.invalid') end @@ -208,10 +208,10 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') end - after { I18n.locale = :en} + after { I18n.locale = :en } it "redirects to login page after signing out with default locale" do - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } delete :destroy expect(response).to redirect_to(spree.login_path) end From d8a53fd63bb30dc3c0f9538009059d1f524375d2 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 16:04:39 +0000 Subject: [PATCH 09/41] Lint file. --- .../controllers/spree/user_sessions_controller_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb index e5dbdc74..a8f06df2 100644 --- a/spec/controllers/spree/user_sessions_controller_spec.rb +++ b/spec/controllers/spree/user_sessions_controller_spec.rb @@ -14,7 +14,7 @@ it 'assigns orders with the correct token and no user present' do order = create(:order, email: user.email, token: 'ABC', user_id: nil, created_by_id: nil) - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } order.reload expect(order.user_id).to eq user.id @@ -23,7 +23,7 @@ it 'assigns orders with the correct token and no user or email present' do order = create(:order, token: 'ABC', user_id: nil, created_by_id: nil) - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } order.reload expect(order.user_id).to eq user.id @@ -34,7 +34,7 @@ order = create(:order, email: user.email, token: 'ABC', user_id: nil, created_by_id: nil, completed_at: 1.minute.ago) - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } order.reload expect(order.user_id).to be_nil @@ -43,14 +43,14 @@ it 'does not assign orders with an existing user' do order = create(:order, token: 'ABC', user_id: 200) - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } expect(order.reload.user_id).to eq 200 end it 'does not assign orders with a different token' do order = create(:order, token: 'DEF', user_id: nil, created_by_id: nil) - post :create, params: { spree_user: { email: user.email, password: 'secret' }} + post :create, params: { spree_user: { email: user.email, password: 'secret' } } expect(order.reload.user_id).to be_nil end From 32b48290a0488abdad2c68e2056311e4115e133c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 16:15:07 +0000 Subject: [PATCH 10/41] Store artifacts. --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b28ab6dd..14e4cb9b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,7 +51,7 @@ run_tests: &run_tests - store_test_results: path: ~/rspec - store_artifacts: - path: tmp/capybara + path: /tmp/test-artifacts run_tests_3_0: &run_tests_3_0 <<: *defaults_3_0 @@ -86,7 +86,7 @@ run_tests_3_0: &run_tests_3_0 - store_test_results: path: ~/rspec - store_artifacts: - path: tmp/capybara + path: /tmp/test-artifacts jobs: bundle: From b9c402200c43ba8468c3e50978f93325bfdd8bbb Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 16:21:48 +0000 Subject: [PATCH 11/41] Remove useless variable assignment. --- spec/features/password_reset_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb index 55809425..acb0b046 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -4,7 +4,7 @@ end scenario 'allow a user to supply an email for the password reset' do - user = create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret') + create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret') visit spree.login_path click_link 'Forgot password?' fill_in 'Email', with: 'foobar@example.com' From d1f78ac0c928489957cbe7bfd901ac970bba6def Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 16:27:34 +0000 Subject: [PATCH 12/41] Add # frozen_string_literal: true --- spec/features/password_reset_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb index acb0b046..d0c9c8a0 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.feature 'Reset Password', type: :feature do background do ActionMailer::Base.default_url_options[:host] = 'http://example.com' From 10a4c19b74441d1dc91a22f764d8bb3c2e76615d Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 16:33:49 +0000 Subject: [PATCH 13/41] Remove duplicate check. --- lib/spree/auth/engine.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb index 01ed4480..5928bc6e 100644 --- a/lib/spree/auth/engine.rb +++ b/lib/spree/auth/engine.rb @@ -60,10 +60,6 @@ def self.frontend_available? @@frontend_available ||= Gem::Specification.find_all_by_name('spree_frontend').any? end - def self.api_available? - @@api_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Api::Engine') - end - def self.emails_available? @@emails_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Emails::Engine') end From ab9af926708061849c529969f3e45d94a8e44175 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 16:48:06 +0000 Subject: [PATCH 14/41] Ensure I18n.locale = :en --- lib/spree/auth/engine.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 10 ++-------- .../spree/user_registrations_controller_spec.rb | 6 ++---- .../controllers/spree/user_sessions_controller_spec.rb | 6 ++---- spec/controllers/spree/users_controller_spec.rb | 2 +- spec/features/admin/sign_out_spec.rb | 2 ++ spec/spec_helper.rb | 4 +++- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb index 5928bc6e..f1424e10 100644 --- a/lib/spree/auth/engine.rb +++ b/lib/spree/auth/engine.rb @@ -31,7 +31,7 @@ def self.activate Rails.configuration.cache_classes ? require(c) : load(c) end if Spree::Auth::Engine.backend_available? - Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/*/*/*_decorator*.rb")) do |c| + Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/**/*_decorator*.rb")) do |c| Rails.configuration.cache_classes ? require(c) : load(c) end end diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index a90a6f39..9837cf1b 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -9,6 +9,8 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') if Spree.version.to_f >= 4.2 end + after { I18n.locale = :en } + context '#edit' do context 'when registration step enabled' do before do @@ -16,8 +18,6 @@ Spree::Auth::Config.set(registration_step: true) end - after { I18n.locale = :en } - context 'when authenticated as registered user' do before { allow(controller).to receive(:spree_current_user) { user } } @@ -76,8 +76,6 @@ allow(order).to receive(:payment_required?) { false } end - after { I18n.locale = :en } - context 'with a token' do before do if Spree.version.to_f > 3.6 @@ -118,8 +116,6 @@ end end - after { I18n.locale = :en } - it 'redirects to the standard order view' do post :update, params: { state: 'confirm' } expect(response).to redirect_to spree.order_path(order) @@ -156,8 +152,6 @@ context '#update_registration' do let(:user) { build(:user) } - after { I18n.locale = :en } - it 'does not check registration' do controller.stub :check_authorization order.stub update: true diff --git a/spec/controllers/spree/user_registrations_controller_spec.rb b/spec/controllers/spree/user_registrations_controller_spec.rb index e2072120..25b5507d 100644 --- a/spec/controllers/spree/user_registrations_controller_spec.rb +++ b/spec/controllers/spree/user_registrations_controller_spec.rb @@ -1,11 +1,11 @@ RSpec.describe Spree::UserRegistrationsController, type: :controller do before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] } + after { I18n.locale = :en } + context '#create' do before { allow(controller).to receive(:after_sign_up_path_for).and_return(spree.account_path) } - after { I18n.locale = :en } - it 'redirects to account_path' do post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } } expect(response).to redirect_to spree.account_path @@ -83,8 +83,6 @@ allow(Devise::Mapping).to receive(:find_scope!).and_return(:spree_user) end - after { I18n.locale = :en } - it 'redirects to sign in after timeout' do expect(controller.send(:after_inactive_sign_up_path_for, :user)).to eq(spree.login_path) end diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb index a8f06df2..f34469a7 100644 --- a/spec/controllers/spree/user_sessions_controller_spec.rb +++ b/spec/controllers/spree/user_sessions_controller_spec.rb @@ -3,6 +3,8 @@ before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] } + after { I18n.locale = :en } + context "#create" do context "using correct login information" do if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.7.0') @@ -163,8 +165,6 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') if Spree.version.to_f >= 4.2 end - after { I18n.locale = :en } - it 'redirects to localized account path after signing in' do skip if Spree.version.to_f < 4.2 post :create, params: { spree_user: { email: user.email, password: 'secret' }, locale: 'fr' } @@ -208,8 +208,6 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') end - after { I18n.locale = :en } - it "redirects to login page after signing out with default locale" do post :create, params: { spree_user: { email: user.email, password: 'secret' } } delete :destroy diff --git a/spec/controllers/spree/users_controller_spec.rb b/spec/controllers/spree/users_controller_spec.rb index 14fcf525..c9d72726 100644 --- a/spec/controllers/spree/users_controller_spec.rb +++ b/spec/controllers/spree/users_controller_spec.rb @@ -8,7 +8,7 @@ Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') end - after { I18n.locale = :en} + after { I18n.locale = :en } context '#load_object' do it 'redirects to signup path if user is not found' do diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 79e237d2..5abbd5d6 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -4,6 +4,8 @@ let(:user) { create(:user, email: 'email@person.com') } before do + I18n.locale = :en + visit spree.admin_login_path fill_in 'Email', with: user.email diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4e3e5f1..a5941dde 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Configure Rails Environment ENV['RAILS_ENV'] = 'test' @@ -6,7 +8,7 @@ require 'spree_dev_tools/rspec/spec_helper' # Requires supporting ruby files with custom matchers and macros, etc, -# in spec/support/ and its subdirectories. +# in spec/support/ and its sub-directories. Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].sort.each { |f| require f } require 'spree/testing_support/locale_helpers' if Spree.version.to_f >= 4.2 From f0b8c503b92d442b29852bec39b721b9c804c30b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 16:59:21 +0000 Subject: [PATCH 15/41] Ensure en local is used. --- spec/features/admin/sign_out_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 5abbd5d6..3d75b52e 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -20,7 +20,7 @@ it 'shows the login page' do log_out - visit spree.admin_login_path + visit spree.admin_login_path(locale: 'en') expect(page).to have_button Spree.t(:login) expect(page).not_to have_text Spree.t(:logout) From de426ee05ac43d39c64a09783d9152de52ccd2b3 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 17:05:14 +0000 Subject: [PATCH 16/41] Lint file --- spec/support/confirm_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/support/confirm_helpers.rb b/spec/support/confirm_helpers.rb index 0e4b87ee..e5ddc412 100644 --- a/spec/support/confirm_helpers.rb +++ b/spec/support/confirm_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.configure do |config| config.around do |example| if example.metadata.key?(:confirmable) @@ -19,7 +21,7 @@ Spree::Auth::Config[:confirmable] = example.metadata[:confirmable] Spree.send(:remove_const, :User) - load File.expand_path('../../../app/models/spree/user.rb', __FILE__) + load File.expand_path('../../app/models/spree/user.rb', __dir__) end end end From 0d62f2e7bff44da5f39adc2861d1653641805ea3 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 17:10:26 +0000 Subject: [PATCH 17/41] Lint file. --- spec/spec_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a5941dde..f717d300 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,7 @@ # Configure Rails Environment ENV['RAILS_ENV'] = 'test' -require File.expand_path('../dummy/config/environment.rb', __FILE__) +require File.expand_path('dummy/config/environment.rb', __dir__) require 'spree_dev_tools/rspec/spec_helper' @@ -15,9 +15,11 @@ RSpec.configure do |config| config.before(:each) do - allow(RSpec::Rails::ViewRendering::EmptyTemplateHandler) - .to receive(:call) - .and_return(%("")) if Rails.gem_version >= Gem::Version.new('6.0.0.beta1') + if Rails.gem_version >= Gem::Version.new('6.0.0.beta1') + allow(RSpec::Rails::ViewRendering::EmptyTemplateHandler) + .to receive(:call) + .and_return(%("")) + end end config.include Spree::TestingSupport::LocaleHelpers if defined?(Spree::TestingSupport::LocaleHelpers) From 2b1c9058f72fe16a8639c75e691574e2a841e06f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 17:15:40 +0000 Subject: [PATCH 18/41] Lint file. --- spec/support/configuration_helpers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/configuration_helpers.rb b/spec/support/configuration_helpers.rb index 042e86d6..080821a2 100644 --- a/spec/support/configuration_helpers.rb +++ b/spec/support/configuration_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ConfigurationHelpers def allow_bypass_sign_in Spree::Auth::Config.set(signout_after_password_change: false) From 5d8301551cc5f50dde1fccffb414754906727f45 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 17:28:39 +0000 Subject: [PATCH 19/41] Use css id --- spec/features/admin/sign_out_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 3d75b52e..ae2c984b 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -8,7 +8,7 @@ visit spree.admin_login_path - fill_in 'Email', with: user.email + fill_in id: 'spree_user_email', with: user.email fill_in Spree.t(:password), with: 'secret' # Regression test for #1257 From 655e7122eb3761314dc140ef27ba291cc9dd2a2f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 17:30:05 +0000 Subject: [PATCH 20/41] Use spree.admin_login_path(locale: 'en') --- spec/features/admin/sign_out_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index ae2c984b..cccc970f 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -6,7 +6,7 @@ before do I18n.locale = :en - visit spree.admin_login_path + visit spree.admin_login_path(locale: 'en') fill_in id: 'spree_user_email', with: user.email fill_in Spree.t(:password), with: 'secret' From d76835df7855aad4b60f4b1ac6db41db1ace2e38 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 17:44:09 +0000 Subject: [PATCH 21/41] Add current store --- spec/controllers/spree/admin/orders_controller_spec.rb | 2 ++ spec/features/admin/sign_out_spec.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb index ffff9d7c..6c6361bb 100644 --- a/spec/controllers/spree/admin/orders_controller_spec.rb +++ b/spec/controllers/spree/admin/orders_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree module Admin RSpec.describe OrdersController, type: :controller do diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index cccc970f..dc1ccd2c 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -4,6 +4,7 @@ let(:user) { create(:user, email: 'email@person.com') } before do + let(:current_store) { create(:store) } I18n.locale = :en visit spree.admin_login_path(locale: 'en') From 94b383b425fe2adabd8452e369845760b7c2f631 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 17:50:05 +0000 Subject: [PATCH 22/41] Fix current_store --- spec/features/admin/sign_out_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index dc1ccd2c..3ad3094b 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true RSpec.feature 'Admin - Sign Out', type: :feature, js: true do + let(:current_store) { create(:store) } let(:user) { create(:user, email: 'email@person.com') } before do - let(:current_store) { create(:store) } I18n.locale = :en visit spree.admin_login_path(locale: 'en') From 1dc4594e5c9d4b6f2193f8ed15230891d6266feb Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 18:53:29 +0000 Subject: [PATCH 23/41] Lint code. --- spec/models/user_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6019cdcd..2cd0bfd7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Spree::User, type: :model do before(:all) { Spree::Role.create name: 'admin' } let!(:store) { create(:store) } From 78f9a7e0d67a5473c2015b280c6b9a2e5e55173a Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 18:58:30 +0000 Subject: [PATCH 24/41] Lint files. --- spec/factories/confirmed_user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/confirmed_user.rb b/spec/factories/confirmed_user.rb index 704e2f3d..80cfed0f 100644 --- a/spec/factories/confirmed_user.rb +++ b/spec/factories/confirmed_user.rb @@ -2,6 +2,6 @@ factory :confirmed_user, parent: :user do confirmed_at { Time.now } confirmation_sent_at { Time.now } - confirmation_token "12345" + confirmation_token { "12345" } end end From 27244b2f450710b1d80e1d042dac0009c6ffe0f9 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 19:01:36 +0000 Subject: [PATCH 25/41] set default store. --- spec/features/admin/sign_out_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 3ad3094b..2e9345f6 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.feature 'Admin - Sign Out', type: :feature, js: true do - let(:current_store) { create(:store) } + let(:current_store) { create(:store, default: true) } let(:user) { create(:user, email: 'email@person.com') } before do From 1bd4a867c657493c403c69867ea2b9a5d7c0c570 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 23:33:48 +0000 Subject: [PATCH 26/41] use describe it --- spec/features/admin/sign_in_spec.rb | 16 ++++++++++------ spec/features/admin/sign_out_spec.rb | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/spec/features/admin/sign_in_spec.rb b/spec/features/admin/sign_in_spec.rb index 2ab6d052..24d14f93 100644 --- a/spec/features/admin/sign_in_spec.rb +++ b/spec/features/admin/sign_in_spec.rb @@ -21,19 +21,23 @@ context 'with non default locale' do before do add_french_locales + Spree::Store.default.update(default_locale: 'en', supported_locales: 'en,fr') I18n.locale = :fr end after { I18n.locale = :en } - scenario 'lets a user sign in successfully', js: true do - log_in(email: @user.email, password: 'secret', locale: 'fr') - show_user_menu + describe 'admin login in french', js: true do + it 'lets a user sign in successfully' do + log_in(email: @user.email, password: 'secret', locale: 'fr') + + show_user_menu - expect(page).not_to have_text login_button.upcase - expect(page).to have_text logout_button.upcase - expect(current_path).to eq '/fr/account' + expect(page).not_to have_text login_button.upcase + expect(page).to have_text logout_button.upcase + expect(current_path).to eq '/fr/account' + end end end diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 2e9345f6..1e8dff4b 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -7,7 +7,7 @@ before do I18n.locale = :en - visit spree.admin_login_path(locale: 'en') + visit spree.admin_login_path(locale: :en) fill_in id: 'spree_user_email', with: user.email fill_in Spree.t(:password), with: 'secret' @@ -21,7 +21,7 @@ it 'shows the login page' do log_out - visit spree.admin_login_path(locale: 'en') + visit spree.admin_login_path(locale: :en) expect(page).to have_button Spree.t(:login) expect(page).not_to have_text Spree.t(:logout) From 3c621ca8013a88a6ca965e8f031c9b1cbcb72b8b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 23:45:09 +0000 Subject: [PATCH 27/41] Replace it --- .../spree/checkout_controller_spec.rb | 16 ++++++++-------- .../spree/user_registrations_controller_spec.rb | 6 +++--- .../spree/user_sessions_controller_spec.rb | 10 +++++----- spec/controllers/spree/users_controller_spec.rb | 8 ++++---- spec/features/admin/sign_in_spec.rb | 2 +- spec/features/sign_in_spec.rb | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 9837cf1b..d1965326 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -35,8 +35,8 @@ context 'non default locale' do it 'redirects to registration step with non default locale' do - get :edit, params: { state: 'address', locale: 'fr' } - expect(response).to redirect_to spree.checkout_registration_path(locale: 'fr') + get :edit, params: { state: 'address', locale: :fr } + expect(response).to redirect_to spree.checkout_registration_path(locale: :fr) end end end @@ -99,8 +99,8 @@ it 'redirects to the tokenized order view with a non default locale' do # spree version higher than 3.6 required for test to work correctly request.cookie_jar.signed[:token] = 'ABC' - post :update, params: { state: 'confirm', locale: 'fr' } - expect(response).to redirect_to spree.order_path(order, locale: 'fr') + post :update, params: { state: 'confirm', locale: :fr } + expect(response).to redirect_to spree.order_path(order, locale: :fr) end end end @@ -123,8 +123,8 @@ context 'non default locale' do it 'redirects to the standard order view with a non default locale' do - post :update, params: { state: 'confirm', locale: 'fr' } - expect(response).to redirect_to spree.order_path(order, locale: 'fr') + post :update, params: { state: 'confirm', locale: :fr } + expect(response).to redirect_to spree.order_path(order, locale: :fr) end end end @@ -176,8 +176,8 @@ context 'non default locale' do it 'redirects to the checkout_path after saving with non default locale' do allow(controller).to receive(:check_authorization) - put :update_registration, params: { order: { email: 'jobs@spreecommerce.com' }, locale: 'fr' } - expect(response).to redirect_to spree.checkout_state_path(:address, locale: 'fr') + put :update_registration, params: { order: { email: 'jobs@spreecommerce.com' }, locale: :fr } + expect(response).to redirect_to spree.checkout_state_path(:address, locale: :fr) end end diff --git a/spec/controllers/spree/user_registrations_controller_spec.rb b/spec/controllers/spree/user_registrations_controller_spec.rb index 25b5507d..b96d17cb 100644 --- a/spec/controllers/spree/user_registrations_controller_spec.rb +++ b/spec/controllers/spree/user_registrations_controller_spec.rb @@ -17,12 +17,12 @@ end it 'redirects to account_path with locale' do - post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }, locale: 'fr'} - expect(response).to redirect_to spree.account_path(locale: 'fr') + post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }, locale: :fr} + expect(response).to redirect_to spree.account_path(locale: :fr) end it 'saves locale in user' do - post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }, locale: 'fr'} + post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }, locale: :fr} user = Spree.user_class.find_by_email('foobar@example.com') expect(user.selected_locale).to eq('fr') end diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb index f34469a7..2ca447f9 100644 --- a/spec/controllers/spree/user_sessions_controller_spec.rb +++ b/spec/controllers/spree/user_sessions_controller_spec.rb @@ -167,8 +167,8 @@ it 'redirects to localized account path after signing in' do skip if Spree.version.to_f < 4.2 - post :create, params: { spree_user: { email: user.email, password: 'secret' }, locale: 'fr' } - expect(response).to redirect_to spree.account_path(locale: 'fr') + post :create, params: { spree_user: { email: user.email, password: 'secret' }, locale: :fr } + expect(response).to redirect_to spree.account_path(locale: :fr) end end end @@ -215,9 +215,9 @@ end it "persists fr locale when redirecting to login page after signing out" do - post :create, params: { spree_user: { email: user.email, password: 'secret' }, locale: 'fr' } - delete :destroy, params: { locale: 'fr' } - expect(response).to redirect_to spree.login_path(locale: 'fr') + post :create, params: { spree_user: { email: user.email, password: 'secret' }, locale: :fr } + delete :destroy, params: { locale: :fr } + expect(response).to redirect_to spree.login_path(locale: :fr) end end end diff --git a/spec/controllers/spree/users_controller_spec.rb b/spec/controllers/spree/users_controller_spec.rb index c9d72726..c64bc51f 100644 --- a/spec/controllers/spree/users_controller_spec.rb +++ b/spec/controllers/spree/users_controller_spec.rb @@ -20,8 +20,8 @@ context "non default locale" do it 'redirects to signup path with non default locale if user is not found' do allow(controller).to receive(:spree_current_user) { nil } - put :update, params: { user: { email: 'foobar@example.com' }, locale: 'fr' } - expect(response).to redirect_to spree.login_path(locale: 'fr') + put :update, params: { user: { email: 'foobar@example.com' }, locale: :fr } + expect(response).to redirect_to spree.login_path(locale: :fr) end end end @@ -48,14 +48,14 @@ end context 'non default locale' do - before { put :update, params: { user: { email: 'mynew@email-address.com' }, locale: 'fr' } } + before { put :update, params: { user: { email: 'mynew@email-address.com' }, locale: :fr } } it 'performs update of email' do expect(assigns[:user].email).to eq 'mynew@email-address.com' end it 'persists locale when redirecting to account' do - expect(response).to redirect_to spree.account_path(locale: 'fr') + expect(response).to redirect_to spree.account_path(locale: :fr) end end diff --git a/spec/features/admin/sign_in_spec.rb b/spec/features/admin/sign_in_spec.rb index 24d14f93..880eb7c9 100644 --- a/spec/features/admin/sign_in_spec.rb +++ b/spec/features/admin/sign_in_spec.rb @@ -30,7 +30,7 @@ describe 'admin login in french', js: true do it 'lets a user sign in successfully' do - log_in(email: @user.email, password: 'secret', locale: 'fr') + log_in(email: @user.email, password: 'secret', locale: :fr) show_user_menu diff --git a/spec/features/sign_in_spec.rb b/spec/features/sign_in_spec.rb index dfc7bc37..36ca7672 100644 --- a/spec/features/sign_in_spec.rb +++ b/spec/features/sign_in_spec.rb @@ -18,7 +18,7 @@ expect(current_path).to eq '/account' end - scenario 'show validation erros' do + scenario 'show validation errors' do fill_in 'Email', with: @user.email fill_in 'Password', with: 'wrong_password' click_button login_button @@ -56,7 +56,7 @@ expect(current_path).to eq '/account' end - context 'localized' do + context 'localized', js: true do before do if Spree.version.to_f >= 4.2 add_french_locales @@ -67,9 +67,9 @@ after { I18n.locale = :en } - scenario 'let a user sign in successfully', js: true do + it 'let a user sign in successfully' do skip if Spree.version.to_f < 4.2 - log_in(email: @user.email, password: @user.password, locale: 'fr') + log_in(email: @user.email, password: @user.password, locale: :fr) show_user_menu expect(page).not_to have_text Spree.t(:login).upcase From 6407863da4eff7acf17e5cc907ce714ac85d0c31 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 26 Dec 2022 23:50:50 +0000 Subject: [PATCH 28/41] Lint file. --- spec/support/email.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/email.rb b/spec/support/email.rb index 8ca8bbc0..aad550d5 100644 --- a/spec/support/email.rb +++ b/spec/support/email.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.configure do |config| config.before do ActionMailer::Base.deliveries.clear From f7f3f2beb2eca8ce65c685fbba804a78f3c5518c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 00:04:42 +0000 Subject: [PATCH 29/41] Lint file. --- .../spree/api/v2/storefront/account_confirmation_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb b/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb index 8466f715..fa9aa985 100644 --- a/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +++ b/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Storefront API v2 Account Confirmation spec', type: :request do describe 'account_confirmations#show' do - before do Spree::User.stub(:confirm_by_token, confirmation_token: confirmation_token).and_return user get "/api/v2/storefront/account_confirmations/#{confirmation_token}" From 4b7651a4b7a6ce7e8bed0bebb789482ec0591e49 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 20:28:39 +0000 Subject: [PATCH 30/41] Fix admin sign out spec. --- spec/features/admin/sign_out_spec.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 1e8dff4b..717b1561 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -1,30 +1,26 @@ # frozen_string_literal: true -RSpec.feature 'Admin - Sign Out', type: :feature, js: true do - let(:current_store) { create(:store, default: true) } - let(:user) { create(:user, email: 'email@person.com') } +RSpec.feature 'Admin - Sign Out', type: :feature, js: false do + let(:user) { create(:admin_user, email: 'email@person.com') } before do - I18n.locale = :en - - visit spree.admin_login_path(locale: :en) + visit spree.admin_root_path fill_in id: 'spree_user_email', with: user.email fill_in Spree.t(:password), with: 'secret' # Regression test for #1257 check 'Remember me' + click_button Spree.t(:login) end - describe 'allows a signed in user to logout' do - it 'shows the login page' do - log_out + it 'allows a signed in user to logout' do + find(:xpath, "/html/body/header/nav/div[3]/div/div/a[3]").click - visit spree.admin_login_path(locale: :en) + visit spree.admin_root_path - expect(page).to have_button Spree.t(:login) - expect(page).not_to have_text Spree.t(:logout) - end + expect(page).to have_button Spree.t(:login) + expect(page).not_to have_text Spree.t(:logout) end end From dc77e6f116f5cb4f0dd4eb849c75f583bcf555de Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 20:38:41 +0000 Subject: [PATCH 31/41] Use admin Path --- spec/features/admin/sign_out_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 717b1561..840bf1f3 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -4,7 +4,7 @@ let(:user) { create(:admin_user, email: 'email@person.com') } before do - visit spree.admin_root_path + visit spree.admin_path fill_in id: 'spree_user_email', with: user.email fill_in Spree.t(:password), with: 'secret' @@ -18,7 +18,7 @@ it 'allows a signed in user to logout' do find(:xpath, "/html/body/header/nav/div[3]/div/div/a[3]").click - visit spree.admin_root_path + visit spree.admin_path expect(page).to have_button Spree.t(:login) expect(page).not_to have_text Spree.t(:logout) From 401744e0072ce904bb1a19a3d5893cb0227b3d85 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 20:46:39 +0000 Subject: [PATCH 32/41] More descriptive log_out method. --- lib/spree/testing_support/auth_helpers.rb | 4 +++- spec/features/sign_out_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/spree/testing_support/auth_helpers.rb b/lib/spree/testing_support/auth_helpers.rb index 708d09af..d63b8327 100644 --- a/lib/spree/testing_support/auth_helpers.rb +++ b/lib/spree/testing_support/auth_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree module TestingSupport module AuthHelpers @@ -22,7 +24,7 @@ def log_in(email:, password:, remember_me: true, locale: nil) expect(page).to have_content Spree.t(:logged_in_successfully) end - def log_out + def log_out_via_frontend_user_menu show_user_menu click_link logout_button diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index f3c10e14..9f11e3d9 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -11,7 +11,7 @@ end scenario 'allow a signed in user to logout' do - log_out + log_out_via_frontend_user_menu visit spree.root_path show_user_menu @@ -28,7 +28,7 @@ it 'clears token cookies' do add_to_cart(mug) - log_out + log_out_via_frontend_user_menu find('#link-to-cart').click expect(page).to have_text Spree.t(:your_cart_is_empty) From 55095f89056241da89f494e6348dc4ffaafc5f4e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 20:50:53 +0000 Subject: [PATCH 33/41] Lint file. --- spec/features/sign_out_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index 9f11e3d9..d27f7eb4 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -1,9 +1,9 @@ RSpec.feature 'Sign Out', type: :feature, js: true do given!(:user) do create(:user, - email: 'email@person.com', - password: 'secret', - password_confirmation: 'secret') + email: 'email@person.com', + password: 'secret', + password_confirmation: 'secret') end background do From a95279e420cc910093e9752498aa1a7880a0b07f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 20:57:23 +0000 Subject: [PATCH 34/41] Lint files. --- spec/controllers/spree/admin/user_sessions_controller_spec.rb | 2 ++ spec/models/order_spec.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/spec/controllers/spree/admin/user_sessions_controller_spec.rb b/spec/controllers/spree/admin/user_sessions_controller_spec.rb index 07f7aa79..12791ab5 100644 --- a/spec/controllers/spree/admin/user_sessions_controller_spec.rb +++ b/spec/controllers/spree/admin/user_sessions_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Spree::Admin::UserSessionsController, type: :controller do before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] } diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 0b96ccd9..b8030b3e 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Spree::Order, type: :model do let(:order) { described_class.new } From 89aef7c696a6930e9c5d317ec050ee760b774bfb Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 21:03:18 +0000 Subject: [PATCH 35/41] Us it not scenario. --- spec/features/change_email_spec.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spec/features/change_email_spec.rb b/spec/features/change_email_spec.rb index f05233b2..62689e22 100644 --- a/spec/features/change_email_spec.rb +++ b/spec/features/change_email_spec.rb @@ -10,15 +10,13 @@ visit spree.edit_account_path end - describe 'work with correct password', js: true do - it 'Updates account' do - fill_in 'user_email', with: 'tests@example.com' - fill_in 'user_password', with: 'password' - fill_in 'user_password_confirmation', with: 'password' - click_button 'Update' + it 'work with correct password', js: true do + fill_in 'user_email', with: 'tests@example.com' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' + click_button 'Update' - expect(page).to have_text 'Account updated' - expect(page).to have_text 'tests@example.com' - end + expect(page).to have_text 'Account updated' + expect(page).to have_text 'tests@example.com' end end From c0ce1129118dcae0f5d382333df605719d970d5f Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 22:55:20 +0000 Subject: [PATCH 36/41] Update Rspec syntax (Replace background with before) --- spec/features/admin/orders_spec.rb | 2 +- spec/features/admin/password_reset_spec.rb | 2 +- spec/features/admin/sign_in_spec.rb | 2 +- spec/features/admin_permissions_spec.rb | 2 +- spec/features/checkout_spec.rb | 4 ++-- spec/features/confirmation_spec.rb | 2 +- spec/features/password_reset_spec.rb | 2 +- spec/features/sign_in_spec.rb | 2 +- spec/features/sign_out_spec.rb | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index ef87d8a1..e321d19c 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -1,5 +1,5 @@ RSpec.feature 'Admin orders', type: :feature do - background do + before do user = create(:admin_user) log_in email: user.email, password: user.password end diff --git a/spec/features/admin/password_reset_spec.rb b/spec/features/admin/password_reset_spec.rb index 4371b495..1354a16d 100644 --- a/spec/features/admin/password_reset_spec.rb +++ b/spec/features/admin/password_reset_spec.rb @@ -1,5 +1,5 @@ RSpec.feature 'Admin - Reset Password', type: :feature do - background do + before do ActionMailer::Base.default_url_options[:host] = 'http://example.com' end diff --git a/spec/features/admin/sign_in_spec.rb b/spec/features/admin/sign_in_spec.rb index 880eb7c9..e4973e3b 100644 --- a/spec/features/admin/sign_in_spec.rb +++ b/spec/features/admin/sign_in_spec.rb @@ -1,5 +1,5 @@ RSpec.feature 'Admin - Sign In', type: :feature do - background do + before do @user = create(:user, email: 'email@person.com') visit spree.admin_login_path end diff --git a/spec/features/admin_permissions_spec.rb b/spec/features/admin_permissions_spec.rb index 13590ae4..65fe67d9 100644 --- a/spec/features/admin_permissions_spec.rb +++ b/spec/features/admin_permissions_spec.rb @@ -1,6 +1,6 @@ RSpec.feature 'Admin Permissions', type: :feature do context 'orders' do - background do + before do user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password') Spree::Ability.register_ability(AbilityDecorator) visit spree.login_path diff --git a/spec/features/checkout_spec.rb b/spec/features/checkout_spec.rb index cf4d87ba..54c801c3 100644 --- a/spec/features/checkout_spec.rb +++ b/spec/features/checkout_spec.rb @@ -13,7 +13,7 @@ given!(:address) { create(:address, state: state, country: country) } given!(:mug) { create(:product, name: 'RoR Mug') } - background do + before do mug.master.stock_items.first.update_column(:count_on_hand, 1) # Bypass gateway error on checkout | ..or stub a gateway @@ -23,7 +23,7 @@ end context 'without payment being required' do - background do + before do # So that we don't have to setup payment methods just for the sake of it allow_any_instance_of(Spree::Order).to receive(:has_available_payment).and_return(true) allow_any_instance_of(Spree::Order).to receive(:payment_required?).and_return(false) diff --git a/spec/features/confirmation_spec.rb b/spec/features/confirmation_spec.rb index 1e15f5de..f88c06d9 100644 --- a/spec/features/confirmation_spec.rb +++ b/spec/features/confirmation_spec.rb @@ -5,7 +5,7 @@ expect(Spree::UserMailer).to receive(:confirmation_instructions).with(anything, anything, { current_store_id: Spree::Store.default.id }).and_return(double(deliver: true)) end - background do + before do ActionMailer::Base.default_url_options[:host] = 'http://example.com' end diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb index d0c9c8a0..0e264851 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.feature 'Reset Password', type: :feature do - background do + before do ActionMailer::Base.default_url_options[:host] = 'http://example.com' end diff --git a/spec/features/sign_in_spec.rb b/spec/features/sign_in_spec.rb index 36ca7672..67a4f63b 100644 --- a/spec/features/sign_in_spec.rb +++ b/spec/features/sign_in_spec.rb @@ -1,5 +1,5 @@ RSpec.feature 'Sign In', type: :feature do - background do + before do @user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret') visit spree.login_path end diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index d27f7eb4..baefcb8e 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -6,7 +6,7 @@ password_confirmation: 'secret') end - background do + before do log_in(email: user.email, password: user.password) end From c57960f02c5ff8fca4fbf6105cf9e6cb996f36e2 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 23:02:19 +0000 Subject: [PATCH 37/41] Update Rspec syntax (replace 'scenario' with 'it') --- spec/features/account_spec.rb | 6 +++--- spec/features/admin/orders_spec.rb | 8 ++++---- spec/features/admin/password_reset_spec.rb | 4 ++-- spec/features/admin/products_spec.rb | 2 +- spec/features/admin/sign_in_spec.rb | 8 ++++---- spec/features/admin_permissions_spec.rb | 10 +++++----- spec/features/checkout_spec.rb | 8 ++++---- spec/features/confirmation_spec.rb | 2 +- spec/features/order_spec.rb | 4 ++-- spec/features/password_reset_spec.rb | 4 ++-- spec/features/sign_in_spec.rb | 8 ++++---- spec/features/sign_out_spec.rb | 2 +- spec/features/sign_up_spec.rb | 4 ++-- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index 6a061924..0dcac666 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -4,7 +4,7 @@ allow_bypass_sign_in end - scenario 'can edit an admin user' do + it 'can edit an admin user' do user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password') visit spree.login_path @@ -16,7 +16,7 @@ expect(page).to have_text 'admin@person.com' end - scenario 'can edit a new user' do + it 'can edit a new user' do visit spree.signup_path fill_in 'Email', with: 'email@person.com' @@ -38,7 +38,7 @@ expect(page).to have_text 'Account updated' end - scenario 'can edit an existing user account' do + it 'can edit an existing user account' do user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret') visit spree.login_path diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index e321d19c..2140ed8e 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -5,23 +5,23 @@ end # Regression #203 - scenario 'can list orders' do + it 'can list orders' do expect { visit spree.admin_orders_path }.not_to raise_error end # Regression #203 - scenario 'can new orders' do + it 'can new orders' do expect { visit spree.new_admin_order_path }.not_to raise_error end # Regression #203 - scenario 'can not edit orders' do + it 'can not edit orders' do visit spree.edit_admin_order_path('nodata') expect(page).to have_text('Order is not found') end # Regression #203 - scenario 'can edit orders' do + it 'can edit orders' do create(:order, number: 'R123') visit spree.edit_admin_order_path('R123') expect(page).not_to have_text 'Authorization Failure' diff --git a/spec/features/admin/password_reset_spec.rb b/spec/features/admin/password_reset_spec.rb index 1354a16d..ad7dba51 100644 --- a/spec/features/admin/password_reset_spec.rb +++ b/spec/features/admin/password_reset_spec.rb @@ -3,7 +3,7 @@ ActionMailer::Base.default_url_options[:host] = 'http://example.com' end - scenario 'allows a user to supply an email for the password reset' do + it 'allows a user to supply an email for the password reset' do user = create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret') visit spree.admin_login_path click_link 'Forgot password?' @@ -12,7 +12,7 @@ expect(page).to have_text 'You will receive an email with instructions' end - scenario 'shows errors if no email is supplied' do + it 'shows errors if no email is supplied' do visit spree.admin_login_path click_link 'Forgot password?' click_button 'Reset my password' diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 0290557b..b0a554b9 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -1,7 +1,7 @@ RSpec.feature 'Admin products', type: :feature do context 'as anonymous user' do # Regression test for #1250 - scenario 'redirects to login page when attempting to access product listing' do + it 'redirects to login page when attempting to access product listing' do expect { visit spree.admin_products_path }.not_to raise_error end end diff --git a/spec/features/admin/sign_in_spec.rb b/spec/features/admin/sign_in_spec.rb index e4973e3b..6054e1d8 100644 --- a/spec/features/admin/sign_in_spec.rb +++ b/spec/features/admin/sign_in_spec.rb @@ -4,12 +4,12 @@ visit spree.admin_login_path end - scenario 'asks user to sign in' do + it 'asks user to sign in' do visit spree.admin_path expect(page).not_to have_text 'Authorization Failure' end - scenario 'lets a user sign in successfully', js: true do + it 'lets a user sign in successfully', js: true do log_in(email: @user.email, password: 'secret') show_user_menu @@ -41,7 +41,7 @@ end end - scenario 'shows validation errors' do + it 'shows validation errors' do fill_in 'Email', with: @user.email fill_in 'Password', with: 'wrong_password' click_button 'Login' @@ -50,7 +50,7 @@ expect(page).to have_button 'Login' end - scenario 'allows a user to access a restricted page after logging in' do + it 'allows a user to access a restricted page after logging in' do user = create(:admin_user, email: 'admin@person.com') visit spree.admin_path diff --git a/spec/features/admin_permissions_spec.rb b/spec/features/admin_permissions_spec.rb index 65fe67d9..1bc3c6f6 100644 --- a/spec/features/admin_permissions_spec.rb +++ b/spec/features/admin_permissions_spec.rb @@ -11,18 +11,18 @@ end context 'admin is restricted from accessing orders' do - scenario 'can not list orders' do + it 'can not list orders' do visit spree.admin_orders_path expect(page).to have_text 'Authorization Failure' end - scenario 'can not edit orders' do + it 'can not edit orders' do create(:order, number: 'R123') visit spree.edit_admin_order_path('R123') expect(page).to have_text 'Authorization Failure' end - scenario 'can not new orders' do + it 'can not new orders' do visit spree.new_admin_order_path expect(page).to have_text 'Authorization Failure' end @@ -31,12 +31,12 @@ context "admin is restricted from accessing an order's customer details" do given(:order) { create(:order_with_totals) } - scenario 'can not list customer details for an order' do + it 'can not list customer details for an order' do visit spree.admin_order_customer_path(order) expect(page).to have_text 'Authorization Failure' end - scenario "can not edit an order's customer details" do + it "can not edit an order's customer details" do visit spree.edit_admin_order_customer_path(order) expect(page).to have_text 'Authorization Failure' end diff --git a/spec/features/checkout_spec.rb b/spec/features/checkout_spec.rb index 54c801c3..a99e3be8 100644 --- a/spec/features/checkout_spec.rb +++ b/spec/features/checkout_spec.rb @@ -29,7 +29,7 @@ allow_any_instance_of(Spree::Order).to receive(:payment_required?).and_return(false) end - scenario 'allow a visitor to checkout as guest, without registration' do + it 'allow a visitor to checkout as guest, without registration' do Spree::Auth::Config.set(registration_step: true) add_to_cart(mug) click_link 'checkout' @@ -49,7 +49,7 @@ expect(page).to have_text 'Order placed successfully' end - scenario 'associate an uncompleted guest order with user after logging in' do + it 'associate an uncompleted guest order with user after logging in' do add_to_cart(mug) visit spree.login_path @@ -73,7 +73,7 @@ end # Regression test for #890 - xscenario 'associate an incomplete guest order with user after successful password reset' do + xit 'associate an incomplete guest order with user after successful password reset' do add_to_cart(mug) visit spree.login_path @@ -106,7 +106,7 @@ ActiveJob::Base.queue_adapter = :test end - scenario 'allow a user to register during checkout' do + it 'allow a user to register during checkout' do add_to_cart(mug) click_link 'checkout' diff --git a/spec/features/confirmation_spec.rb b/spec/features/confirmation_spec.rb index f88c06d9..c4c44b8c 100644 --- a/spec/features/confirmation_spec.rb +++ b/spec/features/confirmation_spec.rb @@ -9,7 +9,7 @@ ActionMailer::Base.default_url_options[:host] = 'http://example.com' end - scenario 'create a new user' do + it 'create a new user' do visit spree.signup_path fill_in 'Email', with: 'email@person.com' diff --git a/spec/features/order_spec.rb b/spec/features/order_spec.rb index 1ef4a1e9..7ce3632b 100644 --- a/spec/features/order_spec.rb +++ b/spec/features/order_spec.rb @@ -1,11 +1,11 @@ RSpec.feature 'Orders', :js, type: :feature do - scenario 'allow a user to view their cart at any time' do + it 'allow a user to view their cart at any time' do visit spree.cart_path expect(page).to have_text 'Your cart is empty' end # regression test for spree/spree#1687 - scenario 'merge incomplete orders from different sessions' do + it 'merge incomplete orders from different sessions' do ror_mug = create(:product, name: 'RoR Mug') ror_shirt = create(:product, name: 'RoR Shirt') diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb index 0e264851..81fc8721 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -5,7 +5,7 @@ ActionMailer::Base.default_url_options[:host] = 'http://example.com' end - scenario 'allow a user to supply an email for the password reset' do + it 'allow a user to supply an email for the password reset' do create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret') visit spree.login_path click_link 'Forgot password?' @@ -14,7 +14,7 @@ expect(page).to have_text 'You will receive an email with instructions' end - scenario 'shows errors if no email is supplied' do + it 'shows errors if no email is supplied' do visit spree.login_path click_link 'Forgot password?' click_button 'Reset my password' diff --git a/spec/features/sign_in_spec.rb b/spec/features/sign_in_spec.rb index 67a4f63b..8d58bf7e 100644 --- a/spec/features/sign_in_spec.rb +++ b/spec/features/sign_in_spec.rb @@ -4,12 +4,12 @@ visit spree.login_path end - scenario 'ask user to sign in' do + it 'ask user to sign in' do visit spree.admin_path expect(page).not_to have_text 'Authorization Failure' end - scenario 'let a user sign in successfully', js: true do + it 'let a user sign in successfully', js: true do log_in(email: @user.email, password: @user.password) show_user_menu @@ -18,7 +18,7 @@ expect(current_path).to eq '/account' end - scenario 'show validation errors' do + it 'show validation errors' do fill_in 'Email', with: @user.email fill_in 'Password', with: 'wrong_password' click_button login_button @@ -27,7 +27,7 @@ expect(page).to have_text 'Log in' end - scenario 'allow a user to access a restricted page after logging in' do + it 'allow a user to access a restricted page after logging in' do user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password') visit spree.admin_path diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index baefcb8e..ca2bd267 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -10,7 +10,7 @@ log_in(email: user.email, password: user.password) end - scenario 'allow a signed in user to logout' do + it 'allow a signed in user to logout' do log_out_via_frontend_user_menu visit spree.root_path diff --git a/spec/features/sign_up_spec.rb b/spec/features/sign_up_spec.rb index 5d7c1062..514f8bdf 100644 --- a/spec/features/sign_up_spec.rb +++ b/spec/features/sign_up_spec.rb @@ -1,6 +1,6 @@ RSpec.feature 'Sign Up', type: :feature do context 'with valid data' do - scenario 'create a new user' do + it 'create a new user' do visit spree.signup_path fill_in 'Email', with: 'email@person.com' @@ -15,7 +15,7 @@ end context 'with invalid data' do - scenario 'does not create a new user' do + it 'does not create a new user' do visit spree.signup_path fill_in 'Email', with: 'email@person.com' From 1bd22358aeb5ffa18906a1e2969ccc86d1e8ff19 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 23:07:56 +0000 Subject: [PATCH 38/41] Update Rspec syntax (replace 'given' with 'let') --- spec/features/admin_permissions_spec.rb | 2 +- spec/features/checkout_spec.rb | 14 +++++++------- spec/features/sign_out_spec.rb | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/features/admin_permissions_spec.rb b/spec/features/admin_permissions_spec.rb index 1bc3c6f6..7a73e8c7 100644 --- a/spec/features/admin_permissions_spec.rb +++ b/spec/features/admin_permissions_spec.rb @@ -29,7 +29,7 @@ end context "admin is restricted from accessing an order's customer details" do - given(:order) { create(:order_with_totals) } + let(:order) { create(:order_with_totals) } it 'can not list customer details for an order' do visit spree.admin_order_customer_path(order) diff --git a/spec/features/checkout_spec.rb b/spec/features/checkout_spec.rb index a99e3be8..5f2cc08b 100644 --- a/spec/features/checkout_spec.rb +++ b/spec/features/checkout_spec.rb @@ -1,17 +1,17 @@ RSpec.feature 'Checkout', :js, type: :feature do - given!(:country) { create(:country, name: 'United States', states_required: true) } - given!(:state) { create(:state, name: 'Maryland', country: country) } - given!(:shipping_method) do + let!(:country) { create(:country, name: 'United States', states_required: true) } + let!(:state) { create(:state, name: 'Maryland', country: country) } + let!(:shipping_method) do shipping_method = create(:shipping_method) calculator = Spree::Calculator::Shipping::PerItem.create!(calculable: shipping_method, preferred_amount: 10) shipping_method.calculator = calculator shipping_method.tap(&:save) end - given!(:user) { create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password') } - given!(:zone) { create(:zone) } - given!(:address) { create(:address, state: state, country: country) } - given!(:mug) { create(:product, name: 'RoR Mug') } + let!(:user) { create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password') } + let!(:zone) { create(:zone) } + let!(:address) { create(:address, state: state, country: country) } + let!(:mug) { create(:product, name: 'RoR Mug') } before do mug.master.stock_items.first.update_column(:count_on_hand, 1) diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index ca2bd267..44ac1667 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -1,5 +1,5 @@ RSpec.feature 'Sign Out', type: :feature, js: true do - given!(:user) do + let!(:user) do create(:user, email: 'email@person.com', password: 'secret', From dcc04cd729341adc62dc7f039b41e527b3ac5d10 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 27 Dec 2022 23:14:21 +0000 Subject: [PATCH 39/41] Rubocop lint files. --- lib/spree/testing_support/checkout_helpers.rb | 2 ++ spree_auth_devise.gemspec | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/spree/testing_support/checkout_helpers.rb b/lib/spree/testing_support/checkout_helpers.rb index 701dca5f..4765c44a 100644 --- a/lib/spree/testing_support/checkout_helpers.rb +++ b/lib/spree/testing_support/checkout_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree module TestingSupport module CheckoutHelpers diff --git a/spree_auth_devise.gemspec b/spree_auth_devise.gemspec index dc718f4c..cd49b42e 100644 --- a/spree_auth_devise.gemspec +++ b/spree_auth_devise.gemspec @@ -1,5 +1,6 @@ -# encoding: UTF-8 -lib = File.expand_path('../lib/', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) require 'spree/auth/version' @@ -19,10 +20,10 @@ Gem::Specification.new do |s| s.license = 'BSD-3-Clause' s.metadata = { - "bug_tracker_uri" => "https://github.com/spree/spree_auth_devise/issues", - "changelog_uri" => "https://github.com/spree/spree_auth_devise/releases/tag/v#{s.version}", - "documentation_uri" => "https://guides.spreecommerce.org/", - "source_code_uri" => "https://github.com/spree/spree_auth_devise/tree/v#{s.version}", + 'bug_tracker_uri' => 'https://github.com/spree/spree_auth_devise/issues', + 'changelog_uri' => "https://github.com/spree/spree_auth_devise/releases/tag/v#{s.version}", + 'documentation_uri' => 'https://guides.spreecommerce.org/', + 'source_code_uri' => "https://github.com/spree/spree_auth_devise/tree/v#{s.version}" } s.files = `git ls-files`.split("\n") From ae20ad9b22177bf7a0de7d4474c849ec7c7527be Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 28 Dec 2022 00:53:28 +0000 Subject: [PATCH 40/41] Differentiate between admin and storefront test helpers --- lib/spree/testing_support/auth_helpers.rb | 25 ++++++++-- spec/features/admin/sign_in_spec.rb | 61 ++++++++--------------- spec/features/admin/sign_out_spec.rb | 10 +--- spec/features/sign_in_spec.rb | 4 +- spec/features/sign_out_spec.rb | 2 +- 5 files changed, 46 insertions(+), 56 deletions(-) diff --git a/lib/spree/testing_support/auth_helpers.rb b/lib/spree/testing_support/auth_helpers.rb index d63b8327..abd158c4 100644 --- a/lib/spree/testing_support/auth_helpers.rb +++ b/lib/spree/testing_support/auth_helpers.rb @@ -11,6 +11,23 @@ def logout_button Spree.version.to_f == 4.1 ? Spree.t('nav_bar.log_out') : Spree.t(:logout).upcase end + def admin_login(email:, password:, remember_me: true, locale: nil) + visit spree.admin_path(locale: locale) + + fill_in id: 'spree_user_email', with: email + fill_in id: 'spree_user_password', with: password + + first('label', text: Spree.t(:remember_me)).click if remember_me + + click_button login_button + end + + def assert_admin_login_success(locale = :en) + expect(page).to have_css('.admin') + expect(current_path).to eq '/admin' + expect(page).to have_css("html[lang='#{locale.to_s}']") + end + def log_in(email:, password:, remember_me: true, locale: nil) visit spree.login_path(locale: locale) @@ -25,19 +42,19 @@ def log_in(email:, password:, remember_me: true, locale: nil) end def log_out_via_frontend_user_menu - show_user_menu + show_frontend_user_menu click_link logout_button expect(page).to have_content 'Signed out successfully' end - def show_user_menu - find("button[aria-label='#{Spree.t('nav_bar.show_user_menu')}']").click + def show_frontend_user_menu + find("button[aria-label='#{Spree.t('nav_bar.show_frontend_user_menu')}']").click end def show_user_account within '#nav-bar' do - show_user_menu + show_frontend_user_menu click_link Spree.t(:my_account).upcase end end diff --git a/spec/features/admin/sign_in_spec.rb b/spec/features/admin/sign_in_spec.rb index 6054e1d8..16badbe7 100644 --- a/spec/features/admin/sign_in_spec.rb +++ b/spec/features/admin/sign_in_spec.rb @@ -1,21 +1,22 @@ RSpec.feature 'Admin - Sign In', type: :feature do - before do - @user = create(:user, email: 'email@person.com') - visit spree.admin_login_path - end + let(:user) { create(:admin_user) } - it 'asks user to sign in' do - visit spree.admin_path - expect(page).not_to have_text 'Authorization Failure' - end + context 'when a user visits the admin_path' do + describe 'when the user is not signed in' do + it 'asks the user to sign in' do + visit spree.admin_path + + expect(page).not_to have_text 'Authorization Failure' + end + end - it 'lets a user sign in successfully', js: true do - log_in(email: @user.email, password: 'secret') - show_user_menu + describe 'when the user is signed in' do + it 'lets a user sign in successfully and access the admin UI' do + admin_login(email: user.email, password: 'secret') - expect(page).not_to have_text login_button.upcase - expect(page).to have_text logout_button.upcase - expect(current_path).to eq '/account' + assert_admin_login_success + end + end end context 'with non default locale' do @@ -28,45 +29,25 @@ after { I18n.locale = :en } - describe 'admin login in french', js: true do + describe 'admin login in french' do it 'lets a user sign in successfully' do - log_in(email: @user.email, password: 'secret', locale: :fr) - - show_user_menu + admin_login(email: user.email, password: 'secret', locale: :fr) - expect(page).not_to have_text login_button.upcase - expect(page).to have_text logout_button.upcase - expect(current_path).to eq '/fr/account' + assert_admin_login_success(:fr) end end end it 'shows validation errors' do - fill_in 'Email', with: @user.email - fill_in 'Password', with: 'wrong_password' - click_button 'Login' + admin_login(email: user.email, password: 'wrong_password') expect(page).to have_text 'Invalid email or password' expect(page).to have_button 'Login' end it 'allows a user to access a restricted page after logging in' do - user = create(:admin_user, email: 'admin@person.com') - visit spree.admin_path - - fill_in 'Email', with: user.email - fill_in 'Password', with: 'secret' - click_button login_button + admin_login(email: user.email, password: 'secret') - if Spree.version.to_f > 4.1 - within '.navbar .dropdown-menu-right' do - expect(page).to have_text 'admin@person.com' - end - else - within '.user-menu' do - expect(page).to have_text 'admin@person.com' - end - end - expect(current_path).to match('/admin') + assert_admin_login_success end end diff --git a/spec/features/admin/sign_out_spec.rb b/spec/features/admin/sign_out_spec.rb index 840bf1f3..3da3ac6d 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -4,15 +4,7 @@ let(:user) { create(:admin_user, email: 'email@person.com') } before do - visit spree.admin_path - - fill_in id: 'spree_user_email', with: user.email - fill_in Spree.t(:password), with: 'secret' - - # Regression test for #1257 - check 'Remember me' - - click_button Spree.t(:login) + admin_login(email: user.email, password: 'secret') end it 'allows a signed in user to logout' do diff --git a/spec/features/sign_in_spec.rb b/spec/features/sign_in_spec.rb index 8d58bf7e..67f9160e 100644 --- a/spec/features/sign_in_spec.rb +++ b/spec/features/sign_in_spec.rb @@ -11,7 +11,7 @@ it 'let a user sign in successfully', js: true do log_in(email: @user.email, password: @user.password) - show_user_menu + show_frontend_user_menu expect(page).not_to have_text login_button.upcase expect(page).to have_text logout_button.upcase @@ -70,7 +70,7 @@ it 'let a user sign in successfully' do skip if Spree.version.to_f < 4.2 log_in(email: @user.email, password: @user.password, locale: :fr) - show_user_menu + show_frontend_user_menu expect(page).not_to have_text Spree.t(:login).upcase expect(page).to have_text Spree.t(:logout).upcase diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index 44ac1667..db2ae6d7 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -14,7 +14,7 @@ log_out_via_frontend_user_menu visit spree.root_path - show_user_menu + show_frontend_user_menu expect(page).to have_link login_button.upcase expect(page).not_to have_link logout_button.upcase From a9ec2289eb8b03ff3a14586eb0f59815df79c4f9 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 28 Dec 2022 09:38:51 +0000 Subject: [PATCH 41/41] Fix target. --- lib/spree/testing_support/auth_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spree/testing_support/auth_helpers.rb b/lib/spree/testing_support/auth_helpers.rb index abd158c4..79cb5f73 100644 --- a/lib/spree/testing_support/auth_helpers.rb +++ b/lib/spree/testing_support/auth_helpers.rb @@ -49,7 +49,7 @@ def log_out_via_frontend_user_menu end def show_frontend_user_menu - find("button[aria-label='#{Spree.t('nav_bar.show_frontend_user_menu')}']").click + find("button[aria-label='#{Spree.t('nav_bar.show_user_menu')}']").click end def show_user_account