From fa06d17169464488ecb70baa54d623aa51b6e12e Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 27 May 2024 10:01:14 +0200 Subject: [PATCH] Feat(user): set email_verified_at when setting confirmed_at --- app/models/user.rb | 4 ++-- db/seeds.rb | 3 ++- spec/models/france_connect_information_spec.rb | 1 + spec/models/user_spec.rb | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index f3e4f6b47..d047ab1d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -99,7 +99,7 @@ class User < ApplicationRecord def self.create_or_promote_to_instructeur(email, password, administrateurs: []) user = User - .create_with(password: password, confirmed_at: Time.zone.now) + .create_with(password: password, confirmed_at: Time.zone.now, email_verified_at: Time.zone.now) .find_or_create_by(email: email) if user.valid? @@ -138,7 +138,7 @@ class User < ApplicationRecord def self.create_or_promote_to_expert(email, password) user = User - .create_with(password: password, confirmed_at: Time.zone.now) + .create_with(password: password, confirmed_at: Time.zone.now, email_verified_at: Time.zone.now) .find_or_create_by(email: email) if user.valid? diff --git a/db/seeds.rb b/db/seeds.rb index 52f97d02f..1a021ad23 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -13,7 +13,8 @@ SuperAdmin.create!(email: default_user, password: default_password) user = User.create!( email: default_user, password: default_password, - confirmed_at: Time.zone.now + confirmed_at: Time.zone.now, + email_verified_at: Time.zone.now ) user.create_instructeur! user.create_administrateur! diff --git a/spec/models/france_connect_information_spec.rb b/spec/models/france_connect_information_spec.rb index 621c729b3..1dcb149cc 100644 --- a/spec/models/france_connect_information_spec.rb +++ b/spec/models/france_connect_information_spec.rb @@ -19,6 +19,7 @@ describe FranceConnectInformation, type: :model do it do subject expect(fci.user.email).to eq('a@email.com') + expect(fci.user.email_verified_at).to be_present end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 958346a47..409507d37 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -117,6 +117,7 @@ describe User, type: :model do user = subject expect(user.valid_password?(password)).to be true expect(user.confirmed_at).to be_present + expect(user.email_verified_at).to be_present expect(user.instructeur).to be_present end @@ -190,6 +191,7 @@ describe User, type: :model do user = subject expect(user.valid_password?(password)).to be true expect(user.confirmed_at).to be_present + expect(user.email_verified_at).to be_present expect(user.expert).to be_present end end @@ -220,6 +222,18 @@ describe User, type: :model do end end + describe '.create_or_promote_to_gestionnaire' do + let(:email) { 'inst1@gmail.com' } + let(:password) { 'un super password !' } + + subject { User.create_or_promote_to_gestionnaire(email, password) } + + it 'verifies its email' do + user = subject + expect(user.email_verified_at).to be_present + end + end + describe 'invite_administrateur!' do let(:super_admin) { create(:super_admin) } let(:administrateur) { create(:administrateur) }