Skip to content

Commit

Permalink
Fix password confirm validation error message (#11625)
Browse files Browse the repository at this point in the history
* Password confirm validation

* changes to password confirm message

* pushing whats been changed

* updated changes to add quotes to error message on pw

* normalisation of i18n strings in locales

* Update decidim-core/spec/forms/account_form_spec.rb

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Added test in registeration_form_spec and change in flash.now[:alert] registrations controller

* test failure changes

* Fixing of SPEC failures

* rspec tests fix

* test

* Broken test with Catalan translation  for sign-in fix

* Registration form spec fix

* fixes to rspec registerations controller on flash message

* Update decidim-core/config/locales/ca.yml

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

---------

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
  • Loading branch information
greenwoodt and andreslucena committed Oct 19, 2023
1 parent 5a93b5d commit 01dfd49
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 18 deletions.
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
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

0 comments on commit 01dfd49

Please sign in to comment.