User.by_any_email does not respect confirmed flag for unverified secondary email addresses
> Email.find_by(email: "me@yahoo.com").attributes
=> {"id"=>1,
"user_id"=>1,
"email"=>"me@yahoo.com",
"created_at"=>Thu, 15 Nov 2018 15:12:20 UTC +00:00,
"updated_at"=>Thu, 15 Nov 2018 15:12:20 UTC +00:00,
"confirmation_token"=>"N2w5ZzoGwHTbjCsPgVwp",
"confirmed_at"=>nil,
"confirmation_sent_at"=>Thu, 15 Nov 2018 15:12:20 UTC +00:00}
> User.find_by_any_email('me@yahoo.com', confirmed: true)
=> #<User id:1 @root>
The variable emails
is an ActiveRecord::Relation
on User
, not on Email
. So when it uses the .confirmed
scope, it's using the scope on User
and not on Email
, while we would need on both.
/cc @reprazent
Edited by Imre Farkas