invite: move invites link to the after_confirmation callback

Refactored from 6a69d958da

The `after_confirmation_path_for` isn't really made to be a callbback.
For instance, it is not executed during tests.

Moving the invitations linking to a proper documented callback allows
the linking to work in a testing environment, when invoking `user.confirm`.
This commit is contained in:
Pierre de La Morinerie 2018-09-19 09:56:05 +00:00
parent cceb88539d
commit 082ef92a99
5 changed files with 31 additions and 63 deletions

View file

@ -24,6 +24,11 @@ class User < ApplicationRecord
before_validation -> { sanitize_email(:email) }
# Callback provided by Devise
def after_confirmation
link_invites!
end
def self.find_for_france_connect(email, siret)
user = User.find_by(email: email)
if user.nil?
@ -49,4 +54,10 @@ class User < ApplicationRecord
def owns_or_invite?(dossier)
owns?(dossier) || invite?(dossier.id)
end
private
def link_invites!
Invite.where(email: email).update_all(user_id: id)
end
end