Commit f2dfcdc6 authored by Patrick Bajao's avatar Patrick Bajao

Merge branch 'refactor/recapcha-error-message-locale' into 'master'

Refactor: let reCAPTCHA error messages use translation

See merge request gitlab-org/gitlab!81977
parents 839e4d28 867aa0a0
...@@ -78,8 +78,9 @@ module Spammable ...@@ -78,8 +78,9 @@ module Spammable
end end
def recaptcha_error! def recaptcha_error!
self.errors.add(:base, "Your #{spammable_entity_type} has been recognized as spam. "\ self.errors.add(:base, _("Your %{spammable_entity_type} has been recognized as spam. "\
"Please, change the content or solve the reCAPTCHA to proceed.") "Please, change the content or solve the reCAPTCHA to proceed.") \
% { spammable_entity_type: spammable_entity_type })
end end
def unrecoverable_spam_error! def unrecoverable_spam_error!
......
...@@ -42389,6 +42389,9 @@ msgstr "" ...@@ -42389,6 +42389,9 @@ msgstr ""
msgid "Your %{plan} subscription expires on %{expiry_date}" msgid "Your %{plan} subscription expires on %{expiry_date}"
msgstr "" msgstr ""
msgid "Your %{spammable_entity_type} has been recognized as spam. Please, change the content or solve the reCAPTCHA to proceed."
msgstr ""
msgid "Your %{strong}%{plan_name}%{strong_close} subscription expires on %{strong}%{expires_on}%{strong_close}. After that date, you cannot create issues or merge requests, or use many other features." msgid "Your %{strong}%{plan_name}%{strong_close} subscription expires on %{strong}%{expires_on}%{strong_close}. After that date, you cannot create issues or merge requests, or use many other features."
msgstr "" msgstr ""
......
...@@ -152,7 +152,7 @@ RSpec.describe ConfirmationsController do ...@@ -152,7 +152,7 @@ RSpec.describe ConfirmationsController do
perform_request perform_request
expect(response).to render_template(:new) expect(response).to render_template(:new)
expect(flash[:alert]).to include 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.' expect(flash[:alert]).to include _('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')
end end
it 'successfully sends password reset when reCAPTCHA is solved' do it 'successfully sends password reset when reCAPTCHA is solved' do
......
...@@ -121,7 +121,7 @@ RSpec.describe PasswordsController do ...@@ -121,7 +121,7 @@ RSpec.describe PasswordsController do
perform_request perform_request
expect(response).to render_template(:new) expect(response).to render_template(:new)
expect(flash[:alert]).to include 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.' expect(flash[:alert]).to include _('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')
end end
it 'successfully sends password reset when reCAPTCHA is solved' do it 'successfully sends password reset when reCAPTCHA is solved' do
......
...@@ -235,7 +235,7 @@ RSpec.describe SessionsController do ...@@ -235,7 +235,7 @@ RSpec.describe SessionsController do
unsuccesful_login(user_params) unsuccesful_login(user_params)
expect(response).to render_template(:new) expect(response).to render_template(:new)
expect(flash[:alert]).to include 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.' expect(flash[:alert]).to include _('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')
expect(subject.current_user).to be_nil expect(subject.current_user).to be_nil
end end
...@@ -259,7 +259,7 @@ RSpec.describe SessionsController do ...@@ -259,7 +259,7 @@ RSpec.describe SessionsController do
unsuccesful_login(user_params, sesion_params: { failed_login_attempts: 6 }) unsuccesful_login(user_params, sesion_params: { failed_login_attempts: 6 })
expect(response).to render_template(:new) expect(response).to render_template(:new)
expect(flash[:alert]).to include 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.' expect(flash[:alert]).to include _('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')
expect(subject.current_user).to be_nil expect(subject.current_user).to be_nil
end end
...@@ -279,7 +279,7 @@ RSpec.describe SessionsController do ...@@ -279,7 +279,7 @@ RSpec.describe SessionsController do
unsuccesful_login(user_params) unsuccesful_login(user_params)
expect(response).to render_template(:new) expect(response).to render_template(:new)
expect(flash[:alert]).to include 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.' expect(flash[:alert]).to include _('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')
expect(subject.current_user).to be_nil expect(subject.current_user).to be_nil
end end
......
...@@ -324,7 +324,7 @@ RSpec.describe 'Signup' do ...@@ -324,7 +324,7 @@ RSpec.describe 'Signup' do
fill_in_signup_form fill_in_signup_form
expect { click_button 'Register' }.not_to change { User.count } expect { click_button 'Register' }.not_to change { User.count }
expect(page).to have_content('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.') expect(page).to have_content(_('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'))
end end
end end
......
...@@ -55,7 +55,7 @@ RSpec.describe Spammable do ...@@ -55,7 +55,7 @@ RSpec.describe Spammable do
subject { invalidate_if_spam(needs_recaptcha: true) } subject { invalidate_if_spam(needs_recaptcha: true) }
it 'has an error related to spam on the model' do it 'has an error related to spam on the model' do
expect(subject.errors.messages[:base]).to match_array /solve the reCAPTCHA/ expect(subject.errors.messages[:base]).to match_array /content or solve the/
end end
end end
...@@ -63,7 +63,7 @@ RSpec.describe Spammable do ...@@ -63,7 +63,7 @@ RSpec.describe Spammable do
subject { invalidate_if_spam(is_spam: true, needs_recaptcha: true) } subject { invalidate_if_spam(is_spam: true, needs_recaptcha: true) }
it 'has an error related to spam on the model' do it 'has an error related to spam on the model' do
expect(subject.errors.messages[:base]).to match_array /solve the reCAPTCHA/ expect(subject.errors.messages[:base]).to match_array /content or solve the/
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment