Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/views/shared/_email_languages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ locals:
),
),
collection: I18n.available_locales.map do |locale|
label = locale == I18n.locale ?
t('account.email_language.default', language: t("i18n.locale.#{locale}")) :
t("i18n.locale.#{locale}")

[
content_tag(
:span,
locale == I18n.locale ?
t('account.email_language.default', language: t("i18n.locale.#{locale}")) :
t("i18n.locale.#{locale}"),
label,
lang: locale,
aria: { hidden: true },
),
locale,
checked: selection ? selection.to_s == locale.to_s : I18n.locale.to_s == locale.to_s,
lang: locale,
aria: { label: label },
]
end,
) %>
45 changes: 45 additions & 0 deletions spec/features/visitors/email_language_preference_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'rails_helper'

describe 'visitor signs up with email language preference' do
it 'defaults to the current locale' do
visit sign_up_email_path

field = page.find_field(
t('account.email_language.default', language: t("i18n.locale.#{I18n.default_locale}")),
)
expect(field).to be_present
expect(field[:lang]).to eq(I18n.default_locale.to_s)
(I18n.available_locales - [I18n.default_locale]).each do |locale|
field = page.find_field(t("i18n.locale.#{locale}"))
expect(field).to be_present
expect(field[:lang]).to eq(locale.to_s)
end

visit sign_up_email_path(:es)

field = page.find_field(t('account.email_language.default', language: t('i18n.locale.es')))
expect(field).to be_present
expect(field[:lang]).to eq('es')
(I18n.available_locales - [:es]).each do |locale|
field = page.find_field(t("i18n.locale.#{locale}"))
expect(field).to be_present
expect(field[:lang]).to eq(locale.to_s)
end
end

it 'sends emails in the selected language' do
email = 'test@example.com'

visit sign_up_email_path
choose t('i18n.locale.es')
check t('sign_up.terms', app_name: APP_NAME)
fill_in t('forms.registration.labels.email'), with: email
click_button t('forms.buttons.submit.default')

emails = unread_emails_for(email)

expect(emails.last.subject).to eq(
t('user_mailer.email_confirmation_instructions.subject', locale: :es),
)
end
end