Add unified_login feature flip

This commit is contained in:
Julien Portalier 2016-10-18 15:49:04 +02:00
parent e942274773
commit fa762dbb39
8 changed files with 40 additions and 20 deletions

View file

@ -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}")

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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 }

View file

@ -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

View file

@ -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

View file

@ -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|