From fa762dbb3993ded3ad3d876f8f1266cec2dfb00f Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Tue, 18 Oct 2016 15:49:04 +0200 Subject: [PATCH] Add unified_login feature flip --- app/models/gestionnaire.rb | 2 +- app/models/user.rb | 3 +-- .../gestionnaires/passwords_controller_spec.rb | 3 ++- .../users/passwords_controller_spec.rb | 3 ++- .../users/sessions_controller_spec.rb | 3 ++- spec/models/gestionnaire_spec.rb | 18 +++++++++++------- spec/models/user_spec.rb | 18 +++++++++++------- spec/spec_helper.rb | 10 ++++++++++ 8 files changed, 40 insertions(+), 20 deletions(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index c053d3f16..70c4d7ba7 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -14,7 +14,7 @@ class Gestionnaire < ActiveRecord::Base after_create :build_default_preferences_list_dossier after_create :build_default_preferences_smart_listing_page - after_save :sync_credentials + after_update :sync_credentials, if: -> { Features.unified_login } def dossiers_follow dossiers.joins(:follows).where("follows.gestionnaire_id = #{id}") diff --git a/app/models/user.rb b/app/models/user.rb index 31bc7779e..23794964c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,8 +15,7 @@ class User < ActiveRecord::Base delegate :given_name, :family_name, :email_france_connect, :gender, :birthdate, :birthplace, :france_connect_particulier_id, to: :france_connect_information accepts_nested_attributes_for :france_connect_information - - after_update :sync_credentials + after_update :sync_credentials, if: -> { Features.unified_login } def self.find_for_france_connect email, siret user = User.find_by_email(email) diff --git a/spec/controllers/gestionnaires/passwords_controller_spec.rb b/spec/controllers/gestionnaires/passwords_controller_spec.rb index 004beabb7..c094f606e 100644 --- a/spec/controllers/gestionnaires/passwords_controller_spec.rb +++ b/spec/controllers/gestionnaires/passwords_controller_spec.rb @@ -6,11 +6,12 @@ describe Gestionnaires::PasswordsController, type: :controller do end describe "update" do - context "when associated gestionnaire" do + context "unified login" do let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') } let(:user) { create(:user, email: 'unique@plop.com', password: 'password') } before do + allow(Features).to receive(:unified_login).and_return(true) @token = gestionnaire.send(:set_reset_password_token) user # make sure it's created end diff --git a/spec/controllers/users/passwords_controller_spec.rb b/spec/controllers/users/passwords_controller_spec.rb index 72e38aa73..83d877b4e 100644 --- a/spec/controllers/users/passwords_controller_spec.rb +++ b/spec/controllers/users/passwords_controller_spec.rb @@ -6,11 +6,12 @@ describe Users::PasswordsController, type: :controller do end describe "update" do - context "when associated gestionnaire" do + context "unified login" do let(:user) { create(:user, email: 'unique@plop.com', password: 'password') } let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') } before do + allow(Features).to receive(:unified_login).and_return(true) @token = user.send(:set_reset_password_token) gestionnaire # make sure it's created end diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 418f4fbbd..1f51dc107 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -34,9 +34,10 @@ describe Users::SessionsController, type: :controller do it { is_expected.to be_falsey } end - context "when associated gestionnaire" do + context "unified login" do let(:user) { create(:user, email: 'unique@plop.com', password: 'password') } let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'password') } + before { allow(Features).to receive(:unified_login).and_return(true) } it 'signs user in' do post :create, user: { email: user.email, password: user.password } diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 21cacaf59..61f71acec 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -185,14 +185,18 @@ describe Gestionnaire, type: :model do end end - it 'syncs credentials to associated user' do - gestionnaire = create(:gestionnaire) - user = create(:user, email: gestionnaire.email) + context 'unified login' do + before { allow(Features).to receive(:unified_login).and_return(true) } - gestionnaire.update_attributes(email: 'whoami@plop.com', password: 'super secret') + it 'syncs credentials to associated user' do + gestionnaire = create(:gestionnaire) + user = create(:user, email: gestionnaire.email) - user.reload - expect(user.email).to eq('whoami@plop.com') - expect(user.valid_password?('super secret')).to be(true) + gestionnaire.update_attributes(email: 'whoami@plop.com', password: 'super secret') + + user.reload + expect(user.email).to eq('whoami@plop.com') + expect(user.valid_password?('super secret')).to be(true) + end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 41243be83..3cbb0283c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -73,14 +73,18 @@ describe User, type: :model do end end - it 'syncs credentials to associated gestionnaire' do - user = create(:user) - gestionnaire = create(:gestionnaire, email: user.email) + context 'unified login' do + before { allow(Features).to receive(:unified_login).and_return(true) } - user.update_attributes(email: 'whoami@plop.com', password: 'super secret') + it 'syncs credentials to associated gestionnaire' do + user = create(:user) + gestionnaire = create(:gestionnaire, email: user.email) - gestionnaire.reload - expect(gestionnaire.email).to eq('whoami@plop.com') - expect(gestionnaire.valid_password?('super secret')).to be(true) + user.update_attributes(email: 'whoami@plop.com', password: 'super secret') + + gestionnaire.reload + expect(gestionnaire.email).to eq('whoami@plop.com') + expect(gestionnaire.valid_password?('super secret')).to be(true) + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bbbac8b2e..c8bf64f29 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -75,6 +75,16 @@ module SmartListing end end +class Features + #def self.remote_storage + # true + #end + + def self.unified_login + false + end +end + WebMock.disable_net_connect!(allow_localhost: true) RSpec.configure do |config|