Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix password confirm validation error message #11625

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,7 +39,7 @@ def create
end

on(:invalid) do
flash.now[:alert] = @form.errors.full_messages.join(", ") if @form.errors.full_messages.any?
flash.now[:alert] = t("error", scope: "decidim.devise.registrations.create")
render :new
end
end
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/forms/decidim/account_form.rb
Expand Up @@ -24,7 +24,7 @@ class AccountForm < Form
validates :nickname, presence: true, format: { with: Decidim::User::REGEXP_NICKNAME }

validates :nickname, length: { maximum: Decidim::User.nickname_max_length, allow_blank: true }
validates :password, confirmation: true
validates :password, confirmation: { message: I18n.t("errors.messages.password_confirmation_message") }
validates :password, password: { name: :name, email: :email, username: :nickname }, if: -> { password.present? }
validates :password_confirmation, presence: true, if: :password_present
validates :avatar, passthru: { to: Decidim::User }
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/forms/decidim/registration_form.rb
Expand Up @@ -17,7 +17,7 @@ class RegistrationForm < Form
validates :name, presence: true, format: { with: Decidim::User::REGEXP_NAME }
validates :nickname, presence: true, format: { with: Decidim::User::REGEXP_NICKNAME }, length: { maximum: Decidim::User.nickname_max_length }
validates :email, presence: true, "valid_email_2/email": { disposable: true }
validates :password, confirmation: true
validates :password, confirmation: { message: I18n.t("errors.messages.password_confirmation_message") }
validates :password, password: { name: :name, email: :email, username: :nickname }
validates :password_confirmation, presence: true
validates :tos_agreement, allow_nil: false, acceptance: true
Expand Down
4 changes: 2 additions & 2 deletions decidim-core/config/locales/ca.yml
Expand Up @@ -1658,7 +1658,7 @@ ca:
sessions:
already_signed_out: Sessió finalitzada correctament.
new:
sign_in: Iniciar sessió
sign_in: Entra
greenwoodt marked this conversation as resolved.
Show resolved Hide resolved
signed_in: Sessió iniciada correctament.
signed_out: S'ha iniciat la sessió correctament.
shared:
Expand All @@ -1667,7 +1667,7 @@ ca:
didn_t_receive_confirmation_instructions: No has rebut instruccions de confirmació?
didn_t_receive_unlock_instructions: No has rebut instruccions de desbloqueig?
forgot_your_password: Has oblidat la teva contrasenya?
sign_in: Iniciar sessió
sign_in: Entra
greenwoodt marked this conversation as resolved.
Show resolved Hide resolved
sign_in_with_provider: Inicia sessió amb %{provider}
sign_up: Registra't
minimum_password_length:
Expand Down
3 changes: 3 additions & 0 deletions decidim-core/config/locales/en.yml
Expand Up @@ -534,6 +534,8 @@ en:
subtitle: Please fill in the following form in order to complete the sign up
username_help: Public name that appears on your posts. With the aim of guaranteeing the anonymity, can be any name.
registrations:
create:
error: There was a problem creating your account.
new:
already_have_an_account?: Already have an account?
newsletter: Receive an occasional newsletter with relevant information
Expand Down Expand Up @@ -1708,6 +1710,7 @@ en:
not_saved:
one: 'There''s been an error processing your request:'
other: 'There were multiple errors when processing your request:'
password_confirmation_message: '"Confirm your password" does not match Password'
too_many_marks: is using too many consecutive punctuation marks (e.g. ! and ?)
too_much_caps: is using too many capital letters (over 25% of the text)
too_short: is too short (under %{count} characters)
Expand Down
17 changes: 3 additions & 14 deletions decidim-core/spec/controllers/registrations_controller_spec.rb
Expand Up @@ -59,7 +59,7 @@ def send_form_and_expect_rendering_the_new_template_again

it "adds the flash message" do
post :create, params: params
expect(controller.flash.now[:alert]).to have_content("Your email can't be blank")
expect(controller.flash.now[:alert]).to have_content("There was a problem creating your account.")
end

context "when all params are invalid" do
Expand All @@ -80,18 +80,7 @@ def send_form_and_expect_rendering_the_new_template_again

it "adds the flash message" do
post :create, params: params
expect(controller.flash.now[:alert]).to have_content(
[
"Your name can't be blank",
"Nickname can't be blank",
"Nickname is invalid",
"Your email can't be blank",
"Confirm your password doesn't match Password",
"Password is too short",
"Password does not have enough unique characters",
"Terms and conditions of use agreement must be accepted"
].join(", ")
)
expect(controller.flash.now[:alert]).to have_content("There was a problem creating your account.")
end
end
end
Expand All @@ -105,7 +94,7 @@ def send_form_and_expect_rendering_the_new_template_again

it "informs the user she must accept the pending invitation" do
send_form_and_expect_rendering_the_new_template_again
expect(controller.flash.now[:alert]).to have_content("You have a pending invitation, accept it to finish creating your account")
expect(controller.flash.now[:alert]).to have_content("There was a problem creating your account.")
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions decidim-core/spec/forms/account_form_spec.rb
Expand Up @@ -155,6 +155,19 @@ module Decidim
end
end

describe "password_confirmation_message" do
context "when the password confirmaiton does not match" do
let(:password_confirmation) { "aaaabbbbcccc" }

it { is_expected.not_to be_valid }

it "adds the correct error" do
subject.valid?
expect(subject.errors[:password_confirmation]).to include('"Confirm your password" does not match Password')
end
end
end

describe "personal_url" do
context "when it doesn't start with http" do
let(:personal_url) { "example.org" }
Expand Down
13 changes: 13 additions & 0 deletions decidim-core/spec/forms/registration_form_spec.rb
Expand Up @@ -152,5 +152,18 @@ module Decidim

it { is_expected.to be_invalid }
end

describe "password_confirmation" do
context "when the password confirmaiton does not match" do
let(:password_confirmation) { "aaaabbbbcccc" }

it { is_expected.to be_invalid }

it "adds the correct error" do
subject.valid?
expect(subject.errors[:password_confirmation]).to include('"Confirm your password" does not match Password')
end
end
end
end
end
2 changes: 1 addition & 1 deletion decidim-core/spec/system/locales_spec.rb
Expand Up @@ -57,7 +57,7 @@
fill_in "session_user_email", with: "toto@example.org"
fill_in "session_user_password", with: "toto"

click_button "Iniciar sessió"
click_button "Entra"

expect(page).to have_content("Email o la contrasenya no són vàlids.")
end
Expand Down