From 47b7dc368b3af8b1e7ec7edadafe738e712097ac Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 8 Aug 2019 17:37:29 +0200 Subject: [PATCH] Remove or fix now nonsense code --- .../administrateurs/activate_controller.rb | 1 - app/controllers/users/sessions_controller.rb | 1 - app/models/administration.rb | 4 +-- .../sessions/sessions_controller_spec.rb | 14 -------- .../users/sessions_controller_spec.rb | 36 ------------------- spec/models/administrateur_spec.rb | 1 - spec/models/instructeur_spec.rb | 11 ------ spec/models/user_spec.rb | 12 ------- 8 files changed, 2 insertions(+), 78 deletions(-) diff --git a/app/controllers/administrateurs/activate_controller.rb b/app/controllers/administrateurs/activate_controller.rb index 9d616b668..9d4a438bd 100644 --- a/app/controllers/administrateurs/activate_controller.rb +++ b/app/controllers/administrateurs/activate_controller.rb @@ -24,7 +24,6 @@ class Administrateurs::ActivateController < ApplicationController if administrateur && administrateur.errors.empty? sign_in(administrateur, scope: :administrateur) try_to_authenticate(User, administrateur.email, password) - try_to_authenticate(Instructeur, administrateur.email, password) flash.notice = "Mot de passe enregistré" redirect_to admin_procedures_path else diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index df6e89b1a..dbce76e0d 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -17,7 +17,6 @@ class Users::SessionsController < Sessions::SessionsController remember_me = params[:user][:remember_me] == '1' if resource_locked?(try_to_authenticate(User, remember_me)) || - resource_locked?(try_to_authenticate(Instructeur, remember_me)) || resource_locked?(try_to_authenticate(Administrateur, remember_me)) flash.alert = 'Votre compte est verrouillé.' new diff --git a/app/models/administration.rb b/app/models/administration.rb index aa77b2d4d..f72a16936 100644 --- a/app/models/administration.rb +++ b/app/models/administration.rb @@ -20,7 +20,7 @@ class Administration < ApplicationRecord AdministrationMailer.new_admin_email(administrateur, self).deliver_later administrateur.invite!(id) - User.create({ + user = User.create({ email: email, password: password, confirmed_at: Time.zone.now @@ -28,7 +28,7 @@ class Administration < ApplicationRecord Instructeur.create({ email: email, - password: password + user: user }) end diff --git a/spec/controllers/sessions/sessions_controller_spec.rb b/spec/controllers/sessions/sessions_controller_spec.rb index a47746b07..ad1834671 100644 --- a/spec/controllers/sessions/sessions_controller_spec.rb +++ b/spec/controllers/sessions/sessions_controller_spec.rb @@ -35,20 +35,6 @@ describe Sessions::SessionsController, type: :controller do end end - describe '#create with instructeur connected' do - before do - @request.env["devise.mapping"] = Devise.mappings[:instructeur] - - allow_any_instance_of(described_class).to receive(:instructeur_signed_in?).and_return(true) - allow_any_instance_of(described_class).to receive(:current_instructeur).and_return(instructeur) - end - - it 'calls sign out for instructeur' do - expect_any_instance_of(described_class).to receive(:sign_out).with(:instructeur) - post :create - end - end - describe '#create with administrateur connected' do before do @request.env["devise.mapping"] = Devise.mappings[:administrateur] diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 40bb9b045..acc9f9cc4 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -103,47 +103,11 @@ describe Users::SessionsController, type: :controller do end end - context "when associated instructeur" do - let(:user) { create(:user, email: 'unique@plop.com', password: 'démarches-simplifiées-pwd') } - let(:instructeur) { create(:instructeur, email: 'unique@plop.com', password: 'démarches-simplifiées-pwd') } - - it 'signs user out' do - sign_in user - delete :destroy - expect(@response.redirect?).to be(true) - expect(subject.current_user).to be(nil) - end - - it 'signs instructeur out' do - sign_in instructeur - delete :destroy - expect(@response.redirect?).to be(true) - expect(subject.current_instructeur).to be(nil) - end - - it 'signs user + instructeur out' do - sign_in user - sign_in instructeur - delete :destroy - expect(@response.redirect?).to be(true) - expect(subject.current_user).to be(nil) - expect(subject.current_instructeur).to be(nil) - end - - it 'signs user out from france connect' do - user.update(loged_in_with_france_connect: User.loged_in_with_france_connects.fetch(:particulier)) - sign_in user - delete :destroy - expect(@response.headers["Location"]).to eq(FRANCE_CONNECT[:particulier][:logout_endpoint]) - end - end - context "when associated administrateur" do let(:administrateur) { create(:administrateur, email: 'unique@plop.com') } it 'signs user + instructeur + administrateur out' do sign_in user - sign_in administrateur.instructeur sign_in administrateur delete :destroy expect(@response.redirect?).to be(true) diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb index ca705cc29..ad2e63226 100644 --- a/spec/models/administrateur_spec.rb +++ b/spec/models/administrateur_spec.rb @@ -28,7 +28,6 @@ describe Administrateur, type: :model do instructeur.reload expect(instructeur.email).to eq('whoami@plop.com') - expect(instructeur.valid_password?('et encore un autre mdp')).to be(true) end end diff --git a/spec/models/instructeur_spec.rb b/spec/models/instructeur_spec.rb index f269565c6..1b330b66b 100644 --- a/spec/models/instructeur_spec.rb +++ b/spec/models/instructeur_spec.rb @@ -142,17 +142,6 @@ describe Instructeur, type: :model do end context 'unified login' do - it 'syncs credentials to associated user' do - instructeur = create(:instructeur) - user = create(:user, email: instructeur.email) - - instructeur.update(email: 'whoami@plop.com', password: 'démarches-simplifiées-pwd') - - user.reload - expect(user.email).to eq('whoami@plop.com') - expect(user.valid_password?('démarches-simplifiées-pwd')).to be(true) - end - it 'syncs credentials to associated administrateur' do admin = create(:administrateur) instructeur = admin.instructeur diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 581feccf3..fb8532f69 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -102,18 +102,6 @@ describe User, type: :model do end context 'unified login' do - it 'syncs credentials to associated instructeur' do - user = create(:user) - instructeur = create(:instructeur, email: user.email) - - user.update(email: 'whoami@plop.com', password: 'démarches-simplifiées2') - user.confirm - - instructeur.reload - expect(instructeur.email).to eq('whoami@plop.com') - expect(instructeur.valid_password?('démarches-simplifiées2')).to be(true) - end - it 'syncs credentials to associated administrateur' do user = create(:user) admin = create(:administrateur, email: user.email)