Skip to content

Commit

Permalink
fix validating email in strict mode (#976)
Browse files Browse the repository at this point in the history
To enable strict mode in email validation, mode: :strict should be used, not strict_mode: true.
  • Loading branch information
manuelmeurer authored May 17, 2024
1 parent 3ab1852 commit 82e6f73
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/clearance/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module Validations

included do
validates :email,
email: { strict_mode: true },
email: { mode: :strict },
presence: true,
uniqueness: { allow_blank: true, case_sensitive: true },
unless: :email_optional?
Expand Down
4 changes: 1 addition & 3 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
it { is_expected.to have_db_index(:remember_token) }
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_presence_of(:password) }
it { is_expected.to allow_value("foo;@example.com").for(:email) }
it { is_expected.to allow_value("foo@.example.com").for(:email) }
it { is_expected.to allow_value("foo@example..com").for(:email) }
it { is_expected.to allow_value("foo@example.co.uk").for(:email) }
it { is_expected.to allow_value("foo@example.com").for(:email) }
it { is_expected.to allow_value("foo+bar@example.com").for(:email) }
it { is_expected.not_to allow_value("example.com").for(:email) }
it { is_expected.not_to allow_value("foo").for(:email) }
it { is_expected.not_to allow_value("foo@").for(:email) }
it { is_expected.not_to allow_value("foo@bar").for(:email) }

describe "#email" do
it "stores email in down case and removes whitespace" do
Expand Down

0 comments on commit 82e6f73

Please sign in to comment.