[#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
if current_user == @user
@user.login_with_france_connect = true
@user.save
end
@user.loged_in_with_france_connect = true
@user.save
redirect_to stored_location_for(current_user) || signed_in_root_path(current_user)
end
rescue Rack::OAuth2::Client::Error => e
Rails.logger.error e.message

View file

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

View file

@ -6,8 +6,6 @@
%div{style:'margin-left:35px'}
S'identifier avec
France Connect
%hr
= 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.
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
enable_extension "plpgsql"
@ -133,12 +133,12 @@ ActiveRecord::Schema.define(version: 20151007085022) do
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_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 "last_sign_in_at"
t.inet "current_sign_in_ip"
@ -146,7 +146,7 @@ ActiveRecord::Schema.define(version: 20151007085022) do
t.datetime "created_at"
t.datetime "updated_at"
t.string "siret"
t.boolean "login_with_france_connect", default: false
t.boolean "loged_in_with_france_connect", default: false
end
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
end
it 'login_with_france_connect user attribut is true' do
expect(current_user.login_with_france_connect).to be_truthy
it 'current user have attribut loged_in_with_france_connect at true' do
expect(current_user.loged_in_with_france_connect).to be_truthy
end
let(:stored_location) { '/plip/plop' }
it 'redirect to stored location' do

View file

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

View file

@ -9,7 +9,7 @@ feature 'France Connect Connexion' do
end
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
context 'and click on france connect link' do
@ -19,7 +19,7 @@ feature 'France Connect Connexion' do
before do
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'))
page.find_by_id('france_connect').click
page.find_by_id('btn_fc').click
end
scenario 'he is redirected to france connect' do
@ -31,11 +31,11 @@ feature 'France Connect Connexion' do
before do
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') }
page.find_by_id('france_connect').click
page.find_by_id('btn_fc').click
end
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
scenario 'error message is displayed' do
@ -58,7 +58,7 @@ feature 'France Connect Connexion' do
before do
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)
page.find_by_id('france_connect').click
page.find_by_id('btn_fc').click
end
context 'when starting page is dossiers list' do
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(:updated_at) }
it { is_expected.to have_db_column(:siret) }
it { is_expected.to have_db_column(:loged_in_with_france_connect) }
end
describe 'associations' do
it { is_expected.to have_many(:dossiers) }