Skip to content

Commit f692dbb

Browse files
committed
Add ControllerLocaleHelper to devise controllers
Now login/sign up/password recover pages form solidus_auth_devise are translated.
1 parent 67b61b2 commit f692dbb

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

Diff for: Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ source "https://rubygems.org"
33
branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
44
gem "solidus", github: "solidusio/solidus", branch: branch
55

6+
# Provides basic authentication functionality for testing parts of your engine
7+
gem 'solidus_auth_devise', '~> 1.0'
8+
69
if branch == 'master' || branch >= "v2.0"
710
gem "rails-controller-testing", group: :test
811
else
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
begin
2+
Spree::UserPasswordsController.include SolidusI18n::ControllerLocaleHelper
3+
Spree::UserRegistrationsController.include SolidusI18n::ControllerLocaleHelper
4+
Spree::UserSessionsController.include SolidusI18n::ControllerLocaleHelper
5+
Spree::Admin::UserSessionsController.include SolidusI18n::ControllerLocaleHelper
6+
rescue NameError
7+
# App is not using solidus_auth_devise
8+
end

Diff for: config/locales/it.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ it:
604604
add: Nuovo credito
605605
back_to_user_list: Lista utenti
606606
select_reason: Motivo
607-
admin_login: Login
607+
admin_login: Login amministratore
608608
administration: Amministrazione
609609
advertise: Promuovi
610610
agree_to_privacy_policy: Accetta Politica di Privacy
@@ -708,6 +708,7 @@ it:
708708
other: Subtotale (%{count} articoli)
709709
categories: Categorie
710710
category: Categoria
711+
change_my_password: Cambia la mia password
711712
charged: Addebitato
712713
check_for_spree_alerts: Visualizza le segnalazioni di Spree
713714
checkout: Checkout

Diff for: spec/features/admin/translations_spec.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper'
22

3-
RSpec.feature 'Translations', :js do
3+
RSpec.feature 'Admin translations', :js do
44
stub_authorization!
55

66
given!(:store) { create(:store) }
@@ -31,4 +31,17 @@
3131
expect(SolidusI18n::Config.available_locales).to include(:fr)
3232
end
3333
end
34+
35+
context 'solidus_auth_devise pages translation' do
36+
let(:locale) { :it }
37+
38+
background do
39+
SolidusI18n::Config.available_locales = [:en, :it]
40+
end
41+
42+
scenario 'the login page is translated' do
43+
visit spree.admin_login_path(locale: locale)
44+
expect(page).to have_content(/#{Spree.t(:admin_login, locale: locale)}/i)
45+
end
46+
end
3447
end

Diff for: spec/features/translations_spec.rb

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# encoding: utf-8
22
require 'spec_helper'
33

4-
RSpec.feature 'Translations', :js do
4+
RSpec.feature 'Frontend translations', :js do
55
given(:language) { Spree.t(:this_file_language, scope: 'i18n', locale: 'pt-BR') }
66

77
background do
88
reset_spree_preferences
9-
SolidusI18n::Config.available_locales = [:en, :'pt-BR']
9+
SolidusI18n::Config.available_locales = [:en, :'pt-BR', :it]
1010
end
1111

1212
context 'page' do
@@ -25,4 +25,28 @@
2525
end
2626
end
2727
end
28+
29+
context 'solidus_auth_devise pages translation' do
30+
let(:locale) { :it }
31+
32+
scenario 'the login page is translated' do
33+
visit spree.login_path(locale: locale)
34+
expect(page).to have_content(/#{Spree.t(:login_as_existing, locale: locale)}/i)
35+
end
36+
37+
scenario 'the signup page is translated' do
38+
visit spree.signup_path(locale: locale)
39+
expect(page).to have_content(/#{Spree.t(:new_customer, locale: locale)}/i)
40+
end
41+
42+
scenario 'the forgot password page is translated' do
43+
visit spree.recover_password_path(locale: locale)
44+
expect(page).to have_content(/#{Spree.t(:forgot_password, locale: locale)}/i)
45+
end
46+
47+
scenario 'the change password page is translated' do
48+
visit spree.edit_password_path(locale: locale, reset_password_token: "123")
49+
expect(page).to have_content(/#{Spree.t(:change_my_password, locale: locale)}/i)
50+
end
51+
end
2852
end

Diff for: spec/spec_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
config.expect_with :rspec do |expectations|
2727
expectations.syntax = :expect
2828
end
29+
30+
config.include Devise::Test::ControllerHelpers, type: :controller
2931
end
3032

3133
Dir[File.join(File.dirname(__FILE__), '/support/**/*.rb')].each { |file| require file }

0 commit comments

Comments
 (0)