• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mgmodell / devise_token_auth_multi_email / #2539

08 Apr 2026 02:16AM UTC coverage: 28.73% (-62.1%) from 90.879%
#2539

push

mgmodell
fixed test to work on my mac

439 of 1528 relevant lines covered (28.73%)

21.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb
1
# frozen_string_literal: true
2

3
module DeviseTokenAuth::Concerns::UserOmniauthCallbacks
1✔
4
  extend ActiveSupport::Concern
1✔
5

6
  included do
1✔
7
    validates :email, presence: true, if: lambda { uid_and_provider_defined? && email_provider? }
12✔
8
    validates :email, :devise_token_auth_email => true, allow_nil: true, allow_blank: true, if: lambda { uid_and_provider_defined? && email_provider? }
12✔
9
    validates_presence_of :uid, if: lambda { uid_and_provider_defined? && !email_provider? }
12✔
10

11
    # Only skip the uniqueness validation for models that use devise-multi_email
12
    # (detected by the presence of the multi_email_association class method, which
13
    # Devise::MultiEmail::ParentModelExtensions adds via :multi_email_authenticatable).
14
    # Standard models always validate; multi_email models manage uniqueness via the
15
    # emails association table instead.
16
    unless Gem.loaded_specs['devise-multi_email'] && respond_to?(:multi_email_association)
9✔
17
      # only validate unique emails among email registration users
18
      validates :email, uniqueness: { case_sensitive: false, scope: :provider }, on: :create, if: lambda { uid_and_provider_defined? && email_provider? }
11✔
19
    end
20

21
    # keep uid in sync with email
22
    before_save :sync_uid
9✔
23
    before_create :sync_uid
9✔
24
  end
25

26
  protected
1✔
27

28
  def uid_and_provider_defined?
1✔
29
    defined?(provider) && defined?(uid)
18✔
30
  end
31

32
  def email_provider?
1✔
33
    provider == 'email'
18✔
34
  end
35

36
  def sync_uid
1✔
37
    unless self.new_record?
6✔
38
      return if devise_modules.include?(:confirmable) && !@bypass_confirmation_postpone && postpone_email_change?
×
39
    end
40
    self.uid = email if uid_and_provider_defined? && email_provider?
6✔
41
  end
42
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc