Skip to content

Commit

Permalink
Merge pull request lynndylanhurley#1055 from pjungwir/missing-email-e…
Browse files Browse the repository at this point in the history
…rror-message

Separate error messages for missing vs invalid email
  • Loading branch information
lynndylanhurley authored Jan 1, 2018
2 parents d206c40 + 211098c commit dfda0c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit dfda0c6

Please sign in to comment.