[#915] Revu de code Ok

This commit is contained in:
Xavier J 2015-10-08 11:26:12 +02:00
parent a828c6259b
commit 728150b148
9 changed files with 33 additions and 32 deletions

View file

@ -23,13 +23,10 @@ class FranceConnectController < ApplicationController
sign_in @user sign_in @user
if current_user == @user @user.loged_in_with_france_connect = true
@user.login_with_france_connect = true @user.save
@user.save
end
redirect_to stored_location_for(current_user) || signed_in_root_path(current_user) redirect_to stored_location_for(current_user) || signed_in_root_path(current_user)
end end
rescue Rack::OAuth2::Client::Error => e rescue Rack::OAuth2::Client::Error => e
Rails.logger.error e.message Rails.logger.error e.message

View file

@ -10,13 +10,13 @@ class Users::SessionsController < Devise::SessionsController
def create def create
super super
current_user.update_attributes(login_with_france_connect: false) current_user.update_attributes(loged_in_with_france_connect: false)
end end
# DELETE /resource/sign_out # DELETE /resource/sign_out
def destroy def destroy
connected_with_france_connect = current_user.login_with_france_connect connected_with_france_connect = current_user.loged_in_with_france_connect
current_user.update_attributes(login_with_france_connect: false) current_user.update_attributes(loged_in_with_france_connect: false)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))

View file

@ -6,8 +6,6 @@
%div{style:'margin-left:35px'} %div{style:'margin-left:35px'}
S'identifier avec S'identifier avec
France Connect France Connect
%hr %hr
= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|

View file

@ -0,0 +1,5 @@
class RenameLoginWithFranceConnectToLogedInWithFranceConnect < ActiveRecord::Migration
def change
rename_column :users, :login_with_france_connect, :loged_in_with_france_connect
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151007085022) do ActiveRecord::Schema.define(version: 20151008090835) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -133,12 +133,12 @@ ActiveRecord::Schema.define(version: 20151007085022) do
end end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "reset_password_sent_at" t.datetime "reset_password_sent_at"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip" t.inet "current_sign_in_ip"
@ -146,7 +146,7 @@ ActiveRecord::Schema.define(version: 20151007085022) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "siret" t.string "siret"
t.boolean "login_with_france_connect", default: false t.boolean "loged_in_with_france_connect", default: false
end end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree

View file

@ -30,8 +30,8 @@ describe FranceConnectController, type: :controller do
get :callback, code: code get :callback, code: code
end end
it 'login_with_france_connect user attribut is true' do it 'current user have attribut loged_in_with_france_connect at true' do
expect(current_user.login_with_france_connect).to be_truthy expect(current_user.loged_in_with_france_connect).to be_truthy
end end
let(:stored_location) { '/plip/plop' } let(:stored_location) { '/plip/plop' }
it 'redirect to stored location' do it 'redirect to stored location' do

View file

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Users::SessionsController, type: :controller do describe Users::SessionsController, type: :controller do
let(:login_with_france_connect) { true } let(:loged_in_with_france_connect) { true }
let(:user) { create(:user, login_with_france_connect: login_with_france_connect) } let(:user) { create(:user, loged_in_with_france_connect: loged_in_with_france_connect) }
before do before do
@request.env["devise.mapping"] = Devise.mappings[:user] @request.env["devise.mapping"] = Devise.mappings[:user]
@ -10,13 +10,13 @@ describe Users::SessionsController, type: :controller do
describe '.create' do describe '.create' do
before do before do
post :create, user: {email: user.email, password: user.password} post :create, user: { email: user.email, password: user.password }
user.reload
end end
it 'login_with_france_connect current_user attribut is false' do subject { user.loged_in_with_france_connect }
user.reload
expect(user.login_with_france_connect).to be_falsey it { is_expected.to be_falsey }
end
end end
describe '.destroy' do describe '.destroy' do
@ -29,9 +29,9 @@ describe Users::SessionsController, type: :controller do
expect(subject.current_user).to be_nil expect(subject.current_user).to be_nil
end end
it 'login_with_france_connect current_user attribut is false' do it 'loged_in_with_france_connect current_user attribut is false' do
user.reload user.reload
expect(user.login_with_france_connect).to be_falsey expect(user.loged_in_with_france_connect).to be_falsey
end end
context 'when user is connect with france connect' do context 'when user is connect with france connect' do
@ -41,7 +41,7 @@ describe Users::SessionsController, type: :controller do
end end
context 'when user is not connect with france connect' do context 'when user is not connect with france connect' do
let(:login_with_france_connect) { false } let(:loged_in_with_france_connect) { false }
it 'redirect to root page' do it 'redirect to root page' do
expect(response).to redirect_to(root_path) expect(response).to redirect_to(root_path)

View file

@ -9,7 +9,7 @@ feature 'France Connect Connexion' do
end end
scenario 'link to France Connect is present' do scenario 'link to France Connect is present' do
expect(page).to have_css('a#france_connect') expect(page).to have_css('a#btn_fc')
end end
context 'and click on france connect link' do context 'and click on france connect link' do
@ -19,7 +19,7 @@ feature 'France Connect Connexion' do
before do before do
allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com')) allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(Hashie::Mash.new(email: 'patator@cake.com'))
page.find_by_id('france_connect').click page.find_by_id('btn_fc').click
end end
scenario 'he is redirected to france connect' do scenario 'he is redirected to france connect' do
@ -31,11 +31,11 @@ feature 'France Connect Connexion' do
before do before do
allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') } allow(FranceConnectService).to receive(:retrieve_user_informations) { raise Rack::OAuth2::Client::Error.new(500, error: 'Unknown') }
page.find_by_id('france_connect').click page.find_by_id('btn_fc').click
end end
scenario 'he is redirected to login page' do scenario 'he is redirected to login page' do
expect(page).to have_css('a#france_connect') expect(page).to have_css('a#btn_fc')
end end
scenario 'error message is displayed' do scenario 'error message is displayed' do
@ -58,7 +58,7 @@ feature 'France Connect Connexion' do
before do before do
allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code)) allow_any_instance_of(FranceConnectClient).to receive(:authorization_uri).and_return(france_connect_callback_path(code: code))
allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_infos) allow(FranceConnectService).to receive(:retrieve_user_informations).and_return(user_infos)
page.find_by_id('france_connect').click page.find_by_id('btn_fc').click
end end
context 'when starting page is dossiers list' do context 'when starting page is dossiers list' do
let(:initial_path) { users_dossiers_path } let(:initial_path) { users_dossiers_path }

View file

@ -15,6 +15,7 @@ describe User, type: :model do
it { is_expected.to have_db_column(:created_at) } it { is_expected.to have_db_column(:created_at) }
it { is_expected.to have_db_column(:updated_at) } it { is_expected.to have_db_column(:updated_at) }
it { is_expected.to have_db_column(:siret) } it { is_expected.to have_db_column(:siret) }
it { is_expected.to have_db_column(:loged_in_with_france_connect) }
end end
describe 'associations' do describe 'associations' do
it { is_expected.to have_many(:dossiers) } it { is_expected.to have_many(:dossiers) }