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