From 728150b1488e1a35d07ab0f5f1c6cd21dfd134c0 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 8 Oct 2015 11:26:12 +0200 Subject: [PATCH] [#915] Revu de code Ok --- app/controllers/france_connect_controller.rb | 7 ++----- app/controllers/users/sessions_controller.rb | 6 +++--- app/views/users/sessions/new.html.haml | 2 -- ...connect_to_loged_in_with_france_connect.rb | 5 +++++ db/schema.rb | 10 +++++----- .../france_connect_controller_spec.rb | 4 ++-- .../users/sessions_controller_spec.rb | 20 +++++++++---------- .../france_connect/france_connect_spec.rb | 10 +++++----- spec/models/user_spec.rb | 1 + 9 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 db/migrate/20151008090835_rename_login_with_france_connect_to_loged_in_with_france_connect.rb diff --git a/app/controllers/france_connect_controller.rb b/app/controllers/france_connect_controller.rb index 1c240ff13..48ea640e6 100644 --- a/app/controllers/france_connect_controller.rb +++ b/app/controllers/france_connect_controller.rb @@ -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 diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 8df7952f2..a4dc524bb 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -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)) diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index aa1ee2dde..d56e0553e 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -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| diff --git a/db/migrate/20151008090835_rename_login_with_france_connect_to_loged_in_with_france_connect.rb b/db/migrate/20151008090835_rename_login_with_france_connect_to_loged_in_with_france_connect.rb new file mode 100644 index 000000000..67cead7eb --- /dev/null +++ b/db/migrate/20151008090835_rename_login_with_france_connect_to_loged_in_with_france_connect.rb @@ -0,0 +1,5 @@ +class RenameLoginWithFranceConnectToLogedInWithFranceConnect < ActiveRecord::Migration + def change + rename_column :users, :login_with_france_connect, :loged_in_with_france_connect + end +end diff --git a/db/schema.rb b/db/schema.rb index 7d750d94d..0162dfdbe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/controllers/france_connect_controller_spec.rb b/spec/controllers/france_connect_controller_spec.rb index 58287ff01..84f9a0866 100644 --- a/spec/controllers/france_connect_controller_spec.rb +++ b/spec/controllers/france_connect_controller_spec.rb @@ -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 diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 34597725b..f8d2a759f 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -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) diff --git a/spec/features/france_connect/france_connect_spec.rb b/spec/features/france_connect/france_connect_spec.rb index 59d96805f..dc5c2b3aa 100644 --- a/spec/features/france_connect/france_connect_spec.rb +++ b/spec/features/france_connect/france_connect_spec.rb @@ -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 } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d27505573..bc6073a20 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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) }