diff --git a/.circleci/config.yml b/.circleci/config.yml index b28ab6dde..14e4cb9bc 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: diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb index 01ed44807..f1424e10f 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 @@ -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 diff --git a/lib/spree/testing_support/auth_helpers.rb b/lib/spree/testing_support/auth_helpers.rb index 708d09aff..79cb5f730 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 @@ -9,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) @@ -22,20 +41,20 @@ def log_in(email:, password:, remember_me: true, locale: nil) expect(page).to have_content Spree.t(:logged_in_successfully) end - def log_out - show_user_menu + def log_out_via_frontend_user_menu + show_frontend_user_menu click_link logout_button expect(page).to have_content 'Signed out successfully' end - def show_user_menu + def show_frontend_user_menu find("button[aria-label='#{Spree.t('nav_bar.show_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/lib/spree/testing_support/checkout_helpers.rb b/lib/spree/testing_support/checkout_helpers.rb index 701dca5f5..4765c44ab 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/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb index ffff9d7c1..6c6361bb1 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/controllers/spree/admin/user_sessions_controller_spec.rb b/spec/controllers/spree/admin/user_sessions_controller_spec.rb index 07f7aa79a..12791ab5a 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/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 0ad79f062..d19653262 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 @@ -33,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 @@ -97,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 @@ -121,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 @@ -174,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 c28663986..b96d17cb8 100644 --- a/spec/controllers/spree/user_registrations_controller_spec.rb +++ b/spec/controllers/spree/user_registrations_controller_spec.rb @@ -1,6 +1,8 @@ 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) } @@ -14,15 +16,13 @@ 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') + 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 @@ -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 9262221ea..2ca447f94 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') @@ -14,7 +16,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 +25,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 +36,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 +45,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 @@ -72,7 +74,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 +87,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 +113,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,17 +146,17 @@ 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 expect(order.created_by_id).to eq user.id - end + end end 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 @@ -165,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 @@ -185,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 @@ -207,15 +209,15 @@ end 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 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 end diff --git a/spec/controllers/spree/users_controller_spec.rb b/spec/controllers/spree/users_controller_spec.rb index 0bfd6a938..c64bc51f1 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 } @@ -18,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 @@ -46,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/factories/confirmed_user.rb b/spec/factories/confirmed_user.rb index 704e2f3d8..80cfed0f6 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 diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index 6a0619241..0dcac666f 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 ef87d8a12..2140ed8e1 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -1,27 +1,27 @@ RSpec.feature 'Admin orders', type: :feature do - background do + before do user = create(:admin_user) log_in email: user.email, password: user.password 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 4371b4952..ad7dba510 100644 --- a/spec/features/admin/password_reset_spec.rb +++ b/spec/features/admin/password_reset_spec.rb @@ -1,9 +1,9 @@ RSpec.feature 'Admin - Reset Password', type: :feature do - background do + before do 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 0290557b3..b0a554b9f 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 711311b28..16badbe7e 100644 --- a/spec/features/admin/sign_in_spec.rb +++ b/spec/features/admin/sign_in_spec.rb @@ -1,68 +1,53 @@ RSpec.feature 'Admin - Sign In', type: :feature do - background do - @user = create(:user, email: 'email@person.com') - visit spree.admin_login_path - end + let(:user) { create(:admin_user) } - scenario '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 - scenario 'lets a user sign in successfully', js: true do - log_in(email: @user.email, password: 'secret') - show_user_menu + expect(page).not_to have_text 'Authorization Failure' + end + end - expect(page).not_to have_text login_button.upcase - expect(page).to have_text logout_button.upcase - expect(current_path).to eq '/account' + 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') + + assert_admin_login_success + end + end end 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 - - expect(page).not_to have_text login_button.upcase - expect(page).to have_text logout_button.upcase - expect(current_path).to eq '/fr/account' + describe 'admin login in french' do + it 'lets a user sign in successfully' do + admin_login(email: user.email, password: 'secret', locale: :fr) + + assert_admin_login_success(:fr) + end end end - scenario 'shows validation errors' do - fill_in 'Email', with: @user.email - fill_in 'Password', with: 'wrong_password' - click_button 'Login' + it 'shows validation errors' do + admin_login(email: user.email, password: 'wrong_password') expect(page).to have_text 'Invalid email or password' expect(page).to have_button 'Login' end - scenario '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 + it 'allows a user to access a restricted page after logging in' do + 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 c14af511b..3da3ac6d4 100644 --- a/spec/features/admin/sign_out_spec.rb +++ b/spec/features/admin/sign_out_spec.rb @@ -1,20 +1,17 @@ -RSpec.feature 'Admin - Sign Out', type: :feature, js: true do - given!(:user) do - create :user, email: 'email@person.com' - end +# frozen_string_literal: true + +RSpec.feature 'Admin - Sign Out', type: :feature, js: false do + let(:user) { create(:admin_user, email: 'email@person.com') } - background do - 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) + before do + admin_login(email: user.email, password: 'secret') end - scenario 'allows a signed in user to logout' do - log_out - visit spree.admin_login_path + 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_path + expect(page).to have_button Spree.t(:login) expect(page).not_to have_text Spree.t(:logout) end diff --git a/spec/features/admin_permissions_spec.rb b/spec/features/admin_permissions_spec.rb index 13590ae45..7a73e8c7e 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 @@ -11,32 +11,32 @@ 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 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) } - 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/change_email_spec.rb b/spec/features/change_email_spec.rb index e727eb3e3..62689e224 100644 --- a/spec/features/change_email_spec.rb +++ b/spec/features/change_email_spec.rb @@ -1,13 +1,16 @@ +# 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 + 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' diff --git a/spec/features/checkout_spec.rb b/spec/features/checkout_spec.rb index cf4d87ba5..5f2cc08be 100644 --- a/spec/features/checkout_spec.rb +++ b/spec/features/checkout_spec.rb @@ -1,19 +1,19 @@ 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') } - 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,13 +23,13 @@ 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) 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 1e15f5dec..c4c44b8ce 100644 --- a/spec/features/confirmation_spec.rb +++ b/spec/features/confirmation_spec.rb @@ -5,11 +5,11 @@ 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 - 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 1ef4a1e93..7ce3632b1 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 55809425c..81fc87210 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -1,10 +1,12 @@ +# 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 - 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') + 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?' fill_in 'Email', with: 'foobar@example.com' @@ -12,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 dfc7bc375..67f9160e8 100644 --- a/spec/features/sign_in_spec.rb +++ b/spec/features/sign_in_spec.rb @@ -1,24 +1,24 @@ 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 - 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 + show_frontend_user_menu expect(page).not_to have_text login_button.upcase expect(page).to have_text logout_button.upcase expect(current_path).to eq '/account' end - scenario 'show validation erros' 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 @@ -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,10 +67,10 @@ 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') - show_user_menu + log_in(email: @user.email, password: @user.password, locale: :fr) + 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 f3c10e147..db2ae6d74 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -1,20 +1,20 @@ RSpec.feature 'Sign Out', type: :feature, js: true do - given!(:user) do + let!(: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 + before do log_in(email: user.email, password: user.password) end - scenario 'allow a signed in user to logout' do - log_out + it 'allow a signed in user to logout' do + 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 @@ -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) diff --git a/spec/features/sign_up_spec.rb b/spec/features/sign_up_spec.rb index 5d7c10626..514f8bdf9 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' diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 0b96ccd97..b8030b3ed 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 } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6019cdcd4..2cd0bfd71 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) } 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 8466f7158..fa9aa9850 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}" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4e3e5f17..f717d3005 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,21 +1,25 @@ +# frozen_string_literal: true + # 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' # 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 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) diff --git a/spec/support/configuration_helpers.rb b/spec/support/configuration_helpers.rb index 042e86d6a..080821a28 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) diff --git a/spec/support/confirm_helpers.rb b/spec/support/confirm_helpers.rb index 0e4b87eea..e5ddc412e 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 diff --git a/spec/support/email.rb b/spec/support/email.rb index 8ca8bbc0e..aad550d5e 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 diff --git a/spree_auth_devise.gemspec b/spree_auth_devise.gemspec index dc718f4c4..cd49b42ef 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")