From 24345008df2dcf4a4198e4b8c129f414a96fee16 Mon Sep 17 00:00:00 2001 From: Alessandro Lepore Date: Tue, 23 May 2017 10:31:19 +0100 Subject: [PATCH 1/3] Add ControllerLocaleHelper to devise controllers Now login/sign up/password recover pages form solidus_auth_devise are translated. --- Gemfile | 3 ++ .../spree/devise_controllers_decorator.rb | 8 ++++++ config/locales/it.yml | 3 +- spec/features/admin/translations_spec.rb | 15 +++++++++- spec/features/translations_spec.rb | 28 +++++++++++++++++-- spec/spec_helper.rb | 2 ++ 6 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 app/controllers/spree/devise_controllers_decorator.rb diff --git a/Gemfile b/Gemfile index b831a074..8a91390b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,9 @@ source "https://rubygems.org" branch = ENV.fetch('SOLIDUS_BRANCH', 'master') gem "solidus", github: "solidusio/solidus", branch: branch +# Provides basic authentication functionality for testing parts of your engine +gem 'solidus_auth_devise', '~> 1.0' + if branch == 'master' || branch >= "v2.0" gem "rails-controller-testing", group: :test else diff --git a/app/controllers/spree/devise_controllers_decorator.rb b/app/controllers/spree/devise_controllers_decorator.rb new file mode 100644 index 00000000..7d72260b --- /dev/null +++ b/app/controllers/spree/devise_controllers_decorator.rb @@ -0,0 +1,8 @@ +begin + Spree::UserPasswordsController.include SolidusI18n::ControllerLocaleHelper + Spree::UserRegistrationsController.include SolidusI18n::ControllerLocaleHelper + Spree::UserSessionsController.include SolidusI18n::ControllerLocaleHelper + Spree::Admin::UserSessionsController.include SolidusI18n::ControllerLocaleHelper +rescue NameError + # App is not using solidus_auth_devise +end diff --git a/config/locales/it.yml b/config/locales/it.yml index 4797877c..290c1676 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -604,7 +604,7 @@ it: add: Nuovo credito back_to_user_list: Lista utenti select_reason: Motivo - admin_login: Login + admin_login: Login amministratore administration: Amministrazione advertise: Promuovi agree_to_privacy_policy: Accetta Politica di Privacy @@ -708,6 +708,7 @@ it: other: Subtotale (%{count} articoli) categories: Categorie category: Categoria + change_my_password: Cambia la mia password charged: Addebitato check_for_spree_alerts: Visualizza le segnalazioni di Spree checkout: Checkout diff --git a/spec/features/admin/translations_spec.rb b/spec/features/admin/translations_spec.rb index 07c6d276..6fa49a2d 100644 --- a/spec/features/admin/translations_spec.rb +++ b/spec/features/admin/translations_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -RSpec.feature 'Translations', :js do +RSpec.feature 'Admin translations', :js do stub_authorization! given!(:store) { create(:store) } @@ -53,4 +53,17 @@ end end end + + context 'solidus_auth_devise pages translation' do + let(:locale) { :it } + + background do + SolidusI18n::Config.available_locales = [:en, :it] + end + + scenario 'the login page is translated' do + visit spree.admin_login_path(locale: locale) + expect(page).to have_content(/#{Spree.t(:admin_login, locale: locale)}/i) + end + end end diff --git a/spec/features/translations_spec.rb b/spec/features/translations_spec.rb index 1d3793b5..272d80cc 100644 --- a/spec/features/translations_spec.rb +++ b/spec/features/translations_spec.rb @@ -2,13 +2,13 @@ require 'spec_helper' -RSpec.feature 'Translations', :js do +RSpec.feature 'Frontend translations', :js do given(:language) { Spree.t(:this_file_language, scope: 'i18n', locale: 'pt-BR') } given(:store) { create(:store) } background do reset_spree_preferences - store.update_attributes(preferred_available_locales: %i[en pt-BR]) + store.update_attributes(preferred_available_locales: %i[en pt-BR it]) end context 'page' do @@ -27,4 +27,28 @@ end end end + + context 'solidus_auth_devise pages translation' do + let(:locale) { :it } + + scenario 'the login page is translated' do + visit spree.login_path(locale: locale) + expect(page).to have_content(/#{Spree.t(:login_as_existing, locale: locale)}/i) + end + + scenario 'the signup page is translated' do + visit spree.signup_path(locale: locale) + expect(page).to have_content(/#{Spree.t(:new_customer, locale: locale)}/i) + end + + scenario 'the forgot password page is translated' do + visit spree.recover_password_path(locale: locale) + expect(page).to have_content(/#{Spree.t(:forgot_password, locale: locale)}/i) + end + + scenario 'the change password page is translated' do + visit spree.edit_password_path(locale: locale, reset_password_token: "123") + expect(page).to have_content(/#{Spree.t(:change_my_password, locale: locale)}/i) + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1d03c34f..e45b71c8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,6 +26,8 @@ config.expect_with :rspec do |expectations| expectations.syntax = :expect end + + config.include Devise::Test::ControllerHelpers, type: :controller end Dir[File.join(File.dirname(__FILE__), '/support/**/*.rb')].each { |file| require file } From 546904d6f33ad306ff56f554d45862b7454cd8fc Mon Sep 17 00:00:00 2001 From: Alessandro Lepore Date: Wed, 21 Mar 2018 21:34:26 +0100 Subject: [PATCH 2/3] Update spec to use the store preference --- .bundle/config | 1 + spec/features/admin/translations_spec.rb | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) create mode 100644 .bundle/config diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 00000000..2fbf0ffd --- /dev/null +++ b/.bundle/config @@ -0,0 +1 @@ +--- {} diff --git a/spec/features/admin/translations_spec.rb b/spec/features/admin/translations_spec.rb index 6fa49a2d..ea1b36bf 100644 --- a/spec/features/admin/translations_spec.rb +++ b/spec/features/admin/translations_spec.rb @@ -55,15 +55,13 @@ end context 'solidus_auth_devise pages translation' do - let(:locale) { :it } - background do - SolidusI18n::Config.available_locales = [:en, :it] + store.update_attributes(preferred_available_locales: [:en, :it]) end scenario 'the login page is translated' do - visit spree.admin_login_path(locale: locale) - expect(page).to have_content(/#{Spree.t(:admin_login, locale: locale)}/i) + visit spree.admin_login_path(locale: "it") + expect(page).to have_content(/#{Spree.t(:admin_login, locale: :it)}/i) end end end From 7df24efd61b663b09ce2e146dd8e152107876e81 Mon Sep 17 00:00:00 2001 From: Alessandro Lepore Date: Tue, 27 Mar 2018 22:03:44 +0200 Subject: [PATCH 3/3] Remove solidus_auth_devise version lock v2.x is required for Solidus 2.5+ --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 8a91390b..57090d6f 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ branch = ENV.fetch('SOLIDUS_BRANCH', 'master') gem "solidus", github: "solidusio/solidus", branch: branch # Provides basic authentication functionality for testing parts of your engine -gem 'solidus_auth_devise', '~> 1.0' +gem 'solidus_auth_devise' if branch == 'master' || branch >= "v2.0" gem "rails-controller-testing", group: :test