From 211098c90b706481a4742b6391cb33335e7a17c2 Mon Sep 17 00:00:00 2001 From: "Paul A. Jungwirth" Date: Sat, 30 Dec 2017 11:51:33 -0800 Subject: [PATCH] Separate error messages for missing vs invalid email --- .../concerns/user_omniauth_callbacks.rb | 3 ++- test/models/user_test.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb b/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb index 6c35c818e..f47053f3a 100644 --- a/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +++ b/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb @@ -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 diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 52e113833..bb5a78780 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -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