From e4f595a3298f16b11b1b4af47654a68cedd682d4 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 14 May 2023 16:37:53 +0200 Subject: [PATCH] Fix translations and enable i18n testing --- app/helpers/application_helper.rb | 2 +- app/views/layouts/application.html.erb | 5 +-- app/views/users/passwords/edit.html.erb | 6 ++-- app/views/users/registrations/edit.html.erb | 6 ++-- app/views/users/registrations/new.html.erb | 2 +- app/views/users/sessions/new.html.erb | 2 +- config/environments/test.rb | 2 +- config/locales/en.yml | 3 +- test/system/users_test.rb | 38 ++++++++++----------- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 655bf9b..9216a50 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -73,7 +73,7 @@ module ApplicationHelper content_tag :div, class: "right" do if current_user.at_least(:admin) - image_link_to t('.users'), "account-multiple-outline", users_path, class: "tab", + image_link_to t(".users"), "account-multiple-outline", users_path, class: "tab", current: :active end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 69b2716..14fde5e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,9 +13,10 @@
<% if user_signed_in? %> <% if current_user_disguised? %> - <%= image_button_to t(:revert), "incognito-off", revert_users_path %> + <%= image_button_to t(".revert"), "incognito-off", revert_users_path %> <% else %> - <%= image_button_to t(:sign_out), "logout", destroy_user_session_path, method: :delete %> + <%= image_button_to t(".sign_out"), "logout", destroy_user_session_path, + method: :delete %> <% end %> <%= image_link_to current_user.email, "account-wrench-outline", edit_user_registration_path, current: :hide %> diff --git a/app/views/users/passwords/edit.html.erb b/app/views/users/passwords/edit.html.erb index e3a1076..b69bf4a 100644 --- a/app/views/users/passwords/edit.html.erb +++ b/app/views/users/passwords/edit.html.erb @@ -1,11 +1,11 @@ <%= tabular_form_for resource, url: user_password_path, html: { method: :put } do |f| %> <%= f.hidden_field :reset_password_token, label: false %> - <%= f.password_field :password, label: t('.new_password'), + <%= f.password_field :password, label: t(".new_password"), required: true, size: 30, autofocus: true, autocomplete: "new-password", hint: ("(#{@minimum_password_length} characters minimum)" if @minimum_password_length) %> - <%= f.password_field :password_confirmation, label: t('.password_confirmation'), + <%= f.password_field :password_confirmation, label: t(".password_confirmation"), required: true, size: 30, autocomplete: "new-password" %> - <%= f.submit t('.update_password') %> + <%= f.submit t(".update_password") %> <% end %> diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb index 901fb8f..5e67e27 100644 --- a/app/views/users/registrations/edit.html.erb +++ b/app/views/users/registrations/edit.html.erb @@ -21,9 +21,9 @@ <%= f.select :status, User.statuses, readonly: true %> <%= f.password_field :password, size: 30, autocomplete: "off", - hint: t('.blank_password_hint_html', - subhint: t('.minimum_length_hint_html', count: @minimum_password_length)) %> + hint: t(".blank_password_hint_html", + subhint: t(".minimum_length_hint_html", count: @minimum_password_length)) %> <%= f.password_field :password_confirmation, size: 30, autocomplete: "off" %> - <%= f.submit t('.update') %> + <%= f.submit t(".update") %> <% end %> diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index fcb196b..432f614 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -3,7 +3,7 @@ <%= f.password_field :password, required: true, size: 30, minlength: @minimum_password_length, autocomplete: "new-password", hint: ("(#{@minimum_password_length} characters minimum)" if @minimum_password_length) %> - <%= f.password_field :password_confirmation, label: t('.password_confirmation'), + <%= f.password_field :password_confirmation, label: t(".password_confirmation"), required: true, size: 30, autocomplete: "new-password" %> <%= f.submit t(:register) %> diff --git a/app/views/users/sessions/new.html.erb b/app/views/users/sessions/new.html.erb index 4213a79..2eed7cf 100644 --- a/app/views/users/sessions/new.html.erb +++ b/app/views/users/sessions/new.html.erb @@ -3,7 +3,7 @@ <%= f.password_field :password, required: true, size: 30, autocomplete: "current-password" %> <% if devise_mapping.rememberable? %> - <%= f.check_box :remember_me, label: t('.remember_me') %> + <%= f.check_box :remember_me, label: t(".remember_me") %> <% end %> <%= f.submit t(:sign_in) %> diff --git a/config/environments/test.rb b/config/environments/test.rb index a7706f5..3593d36 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -52,7 +52,7 @@ Rails.application.configure do config.active_support.disallowed_deprecation_warnings = [] # Raises error for missing translations. - # config.i18n.raise_on_missing_translations = true + config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true diff --git a/config/locales/en.yml b/config/locales/en.yml index fa9fd63..5210532 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -35,13 +35,12 @@ en: layouts: application: revert: Revert + sign_out: Sign out users: Users actions: Actions back: Back or: or - profile: Profile register: Register sign_in: Sign in - sign_out: Sign out recover_password: Recover password resend_confirmation: Resend confirmation diff --git a/test/system/users_test.rb b/test/system/users_test.rb index 96c6904..515296e 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -8,21 +8,21 @@ class UsersTest < ApplicationSystemTestCase test "sign in" do sign_in assert_no_current_path new_user_session_path - assert_text t('devise.sessions.signed_in') + assert_text t("devise.sessions.signed_in") end test "sign in fails with invalid password" do sign_in password: random_password assert_current_path new_user_session_path - assert_text t('devise.failure.invalid', authentication_keys: User.human_attribute_name(:email)) + assert_text t("devise.failure.invalid", authentication_keys: User.human_attribute_name(:email)) end test "sign out" do sign_in visit root_url - click_on t(:sign_out) + click_on t("layouts.application.sign_out") assert_current_path new_user_session_path - assert_text t('devise.sessions.signed_out') + assert_text t("devise.sessions.signed_out") end test "recover password" do @@ -35,19 +35,19 @@ class UsersTest < ApplicationSystemTestCase click_on t(:recover_password) end assert_current_path new_user_session_path - assert_text t('devise.passwords.send_instructions') + assert_text t("devise.passwords.send_instructions") with_last_email do |mail| visit Capybara.string(mail.body.to_s).find_link("Change my password")[:href] end new_password = random_password - fill_in t('users.passwords.edit.new_password'), with: new_password - fill_in t('users.passwords.edit.password_confirmation'), with: new_password + fill_in t("users.passwords.edit.new_password"), with: new_password + fill_in t("users.passwords.edit.password_confirmation"), with: new_password assert_emails 1 do - click_on t('users.passwords.edit.update_password') + click_on t("users.passwords.edit.update_password") end assert_no_current_path user_password_path - assert_text t('devise.passwords.updated') + assert_text t("devise.passwords.updated") end test "register" do @@ -57,7 +57,7 @@ class UsersTest < ApplicationSystemTestCase fill_in User.human_attribute_name(:email).capitalize, with: random_email password = random_password fill_in User.human_attribute_name(:password).capitalize, with: password - fill_in t('users.registrations.new.password_confirmation'), with: password + fill_in t("users.registrations.new.password_confirmation"), with: password assert_difference ->{User.count}, 1 do assert_emails 1 do click_on t(:register) @@ -65,13 +65,13 @@ class UsersTest < ApplicationSystemTestCase end assert_no_current_path new_user_registration_path - assert_text t('devise.registrations.signed_up_but_unconfirmed') + assert_text t("devise.registrations.signed_up_but_unconfirmed") with_last_email do |mail| visit Capybara.string(mail.body.to_s).find_link("Confirm my account")[:href] end assert_current_path new_user_session_path - assert_text t('devise.confirmations.confirmed') + assert_text t("devise.confirmations.confirmed") assert User.last.confirmed? end @@ -86,7 +86,7 @@ class UsersTest < ApplicationSystemTestCase click_on t(:resend_confirmation) end assert_current_path new_user_session_path - assert_text t('devise.confirmations.send_instructions') + assert_text t("devise.confirmations.send_instructions") with_last_email do |mail| visit Capybara.string(mail.body.to_s).find_link("Confirm my account")[:href] @@ -95,7 +95,7 @@ class UsersTest < ApplicationSystemTestCase test "show profile" do sign_in user: users.select(&:admin?).select(&:confirmed?).sample - click_on t('layouts.application.users') + click_on t("layouts.application.users") within all('tr').drop(1).sample do |tr| email = first(:link).text click_on email @@ -107,7 +107,7 @@ class UsersTest < ApplicationSystemTestCase user = users.select(&:admin?).select(&:confirmed?).sample sign_in user: user - click_on t('layouts.application.users') + click_on t("layouts.application.users") all(:link_or_button, text: t("users.index.disguise")).sample.click assert_current_path edit_user_registration_path # TODO: test for profile app-menu link after root changed to different path @@ -122,8 +122,8 @@ class UsersTest < ApplicationSystemTestCase user = users.select(&:admin?).select(&:confirmed?).sample sign_in user: user - click_on t('layouts.application.users') - text = t('users.index.disguise') + click_on t("layouts.application.users") + text = t("users.index.disguise") undisguisable = all(:xpath, "//tbody//tr[not(descendant::*[contains(text(),\"#{text}\")])]") within undisguisable.sample do |tr| email = first(:link).text @@ -144,8 +144,8 @@ class UsersTest < ApplicationSystemTestCase end assert_difference ->{ User.count }, -1 do # TODO: accept_confirm when modal dialog is working - #accept_confirm { click_on t('users.registrations.edit.delete') } - click_on t('users.registrations.edit.delete') + #accept_confirm { click_on t("users.registrations.edit.delete") } + click_on t("users.registrations.edit.delete") end assert_current_path new_user_session_path end