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 8 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
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
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" do
greenwoodt marked this conversation as resolved.
Show resolved Hide resolved
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

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 @@ -153,4 +153,17 @@ module Decidim
it { is_expected.to be_invalid }
end
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
2 changes: 1 addition & 1 deletion decidim-core/spec/system/locales_spec.rb
Expand Up @@ -48,7 +48,7 @@
end

it "displays devise messages with the right locale when authentication fails" do
click_link "Sign In"
click_link "Log In"

within_language_menu do
click_link "Català"
Expand Down