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

Separate error messages for missing vs invalid email #1055

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module DeviseTokenAuth::Concerns::UserOmniauthCallbacks
extend ActiveSupport::Concern

included do
validates :email, presence: true, email: true, if: :email_provider?
validates :email, presence: true,if: :email_provider?
validates :email, email: true, allow_nil: true, allow_blank: true, if: :email_provider?
validates_presence_of :uid, unless: :email_provider?

# only validate unique emails among email registration users
Expand Down
12 changes: 11 additions & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ class UserTest < ActiveSupport::TestCase
@resource.password_confirmation = @password

refute @resource.save
assert @resource.errors.messages[:email]
assert @resource.errors.messages[:email] == [I18n.t("errors.messages.blank")]
end

test 'model should not save if email is not an email' do
@resource.provider = 'email'
@resource.email = '@example.com'
@resource.password = @password
@resource.password_confirmation = @password

refute @resource.save
assert @resource.errors.messages[:email] == [I18n.t("errors.messages.not_email")]
end
end

Expand Down