Skip to content

Commit

Permalink
Add ControllerLocaleHelper to devise controllers
Browse files Browse the repository at this point in the history
Now login/sign up/password recover pages form solidus_auth_devise are
translated.
  • Loading branch information
alepore committed Feb 9, 2018
1 parent 67b61b2 commit f692dbb
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/spree/devise_controllers_decorator.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion spec/features/admin/translations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.feature 'Translations', :js do
RSpec.feature 'Admin translations', :js do
stub_authorization!

given!(:store) { create(:store) }
Expand Down Expand Up @@ -31,4 +31,17 @@
expect(SolidusI18n::Config.available_locales).to include(:fr)
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
28 changes: 26 additions & 2 deletions spec/features/translations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# encoding: utf-8
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') }

background do
reset_spree_preferences
SolidusI18n::Config.available_locales = [:en, :'pt-BR']
SolidusI18n::Config.available_locales = [:en, :'pt-BR', :it]
end

context 'page' do
Expand All @@ -25,4 +25,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
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit f692dbb

Please sign in to comment.