From 8c487c65a920e73fe7cb27ab0f351d9470a9ad88 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 11 Jan 2018 11:27:56 +0100 Subject: [PATCH 01/45] FC: remove unused code --- app/controllers/users/sessions_controller.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 8c77f7aac..496ac0ea8 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -49,9 +49,6 @@ class Users::SessionsController < Sessions::SessionsController sign_out :user case connected_with_france_connect - when 'entreprise' - redirect_to FRANCE_CONNECT.entreprise_logout_endpoint - return when 'particulier' redirect_to FRANCE_CONNECT.particulier_logout_endpoint return From 4c2da46dd812e65e1111e10e62228106056d8206 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 11:07:25 +0100 Subject: [PATCH 02/45] FC ParticulierClient: simplier initialize --- app/models/france_connect_particulier_client.rb | 7 +++++-- app/services/france_connect_service.rb | 2 +- spec/models/france_connect_particulier_client_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/france_connect_particulier_client.rb b/app/models/france_connect_particulier_client.rb index bc0e99e9c..5c157aa8c 100644 --- a/app/models/france_connect_particulier_client.rb +++ b/app/models/france_connect_particulier_client.rb @@ -1,5 +1,5 @@ class FranceConnectParticulierClient < OpenIDConnect::Client - def initialize params={} + def initialize(code = nil) super( identifier: FRANCE_CONNECT.particulier_identifier, secret: FRANCE_CONNECT.particulier_secret, @@ -11,6 +11,9 @@ class FranceConnectParticulierClient < OpenIDConnect::Client userinfo_endpoint: FRANCE_CONNECT.particulier_userinfo_endpoint, logout_endpoint: FRANCE_CONNECT.particulier_logout_endpoint ) - self.authorization_code = params[:code] if params.has_key? :code + + if code.present? + self.authorization_code = code + end end end diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index 883169e70..a5ebc6cab 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -1,6 +1,6 @@ class FranceConnectService def self.retrieve_user_informations_particulier code - client = FranceConnectParticulierClient.new code: code + client = FranceConnectParticulierClient.new(code) access_token = client.access_token!(client_auth_method: :secret) user_info = access_token.userinfo! diff --git a/spec/models/france_connect_particulier_client_spec.rb b/spec/models/france_connect_particulier_client_spec.rb index 7f3168d13..a93a6eb34 100644 --- a/spec/models/france_connect_particulier_client_spec.rb +++ b/spec/models/france_connect_particulier_client_spec.rb @@ -7,10 +7,10 @@ describe FranceConnectParticulierClient do end context 'when given code in params' do let(:code) { 'plop' } - subject { described_class.new(code: code) } + subject { described_class.new(code) } it 'set authorisation code' do expect_any_instance_of(described_class).to receive(:authorization_code=).with(code) - described_class.new(code: code) + described_class.new(code) end end end From 06d9c4356ee7cd835fd017a9fdea73bcb7ac3a83 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 11:50:04 +0100 Subject: [PATCH 03/45] FC ParticulierClientSpec: simplier spec --- .../france_connect_particulier_client_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/models/france_connect_particulier_client_spec.rb b/spec/models/france_connect_particulier_client_spec.rb index a93a6eb34..b73825d7d 100644 --- a/spec/models/france_connect_particulier_client_spec.rb +++ b/spec/models/france_connect_particulier_client_spec.rb @@ -2,16 +2,14 @@ require 'spec_helper' describe FranceConnectParticulierClient do describe '.initialize' do - it 'create an openid client' do - expect(described_class).to be < OpenIDConnect::Client - end + subject { FranceConnectParticulierClient.new(code) } + context 'when given code in params' do let(:code) { 'plop' } - subject { described_class.new(code) } - it 'set authorisation code' do - expect_any_instance_of(described_class).to receive(:authorization_code=).with(code) - described_class.new(code) - end + + before { allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_code=) } + + it { is_expected.to have_received(:authorization_code=).with(code) } end end end From 0d46f927958ffab27be1b097bba033ddc3d9fbf1 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 15 Jan 2018 12:07:54 +0100 Subject: [PATCH 04/45] FC: move FC constants under particulier namespace --- app/controllers/users/sessions_controller.rb | 2 +- .../france_connect_particulier_client.rb | 16 +++++++------- app/services/france_connect_salt_service.rb | 2 +- config/initializers/france_connect.rb | 21 ++++++++++++------- .../users/sessions_controller_spec.rb | 4 ++-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 496ac0ea8..302c19596 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -50,7 +50,7 @@ class Users::SessionsController < Sessions::SessionsController case connected_with_france_connect when 'particulier' - redirect_to FRANCE_CONNECT.particulier_logout_endpoint + redirect_to FRANCE_CONNECT.particulier.logout_endpoint return end end diff --git a/app/models/france_connect_particulier_client.rb b/app/models/france_connect_particulier_client.rb index 5c157aa8c..934dddb6a 100644 --- a/app/models/france_connect_particulier_client.rb +++ b/app/models/france_connect_particulier_client.rb @@ -1,15 +1,13 @@ class FranceConnectParticulierClient < OpenIDConnect::Client def initialize(code = nil) super( - identifier: FRANCE_CONNECT.particulier_identifier, - secret: FRANCE_CONNECT.particulier_secret, - - redirect_uri: FRANCE_CONNECT.particulier_redirect_uri, - - authorization_endpoint: FRANCE_CONNECT.particulier_authorization_endpoint, - token_endpoint: FRANCE_CONNECT.particulier_token_endpoint, - userinfo_endpoint: FRANCE_CONNECT.particulier_userinfo_endpoint, - logout_endpoint: FRANCE_CONNECT.particulier_logout_endpoint + identifier: FRANCE_CONNECT.particulier.identifier, + secret: FRANCE_CONNECT.particulier.secret, + redirect_uri: FRANCE_CONNECT.particulier.redirect_uri, + authorization_endpoint: FRANCE_CONNECT.particulier.authorization_endpoint, + token_endpoint: FRANCE_CONNECT.particulier.token_endpoint, + userinfo_endpoint: FRANCE_CONNECT.particulier.userinfo_endpoint, + logout_endpoint: FRANCE_CONNECT.particulier.logout_endpoint ) if code.present? diff --git a/app/services/france_connect_salt_service.rb b/app/services/france_connect_salt_service.rb index a28476952..2e35b5515 100644 --- a/app/services/france_connect_salt_service.rb +++ b/app/services/france_connect_salt_service.rb @@ -11,6 +11,6 @@ class FranceConnectSaltService end def salt - Digest::MD5.hexdigest(model.france_connect_particulier_id + model.given_name + model.family_name + FRANCE_CONNECT.particulier_secret + DateTime.now.to_date.to_s) + Digest::MD5.hexdigest(model.france_connect_particulier_id + model.given_name + model.family_name + FRANCE_CONNECT.particulier.secret + DateTime.now.to_date.to_s) end end diff --git a/config/initializers/france_connect.rb b/config/initializers/france_connect.rb index c9e9d11cf..f4bc1d681 100644 --- a/config/initializers/france_connect.rb +++ b/config/initializers/france_connect.rb @@ -1,14 +1,19 @@ FRANCE_CONNECT = if !Rails.env.test? file_path = "#{Rails.root}/config/france_connect.yml" - Hashie::Mash.load(file_path) + config_hash = YAML.safe_load(File.read(file_path)) + .reduce({}) { |acc, (key, value)| acc[key.gsub('particulier_', '')] = value, acc } + + Hashie::Mash.new(particulier: config_hash) else Hashie::Mash.new({ - particulier_identifier: 'plop', - particulier_secret: 'plip', - particulier_redirect_uri: 'https://bidon.com/endpoint', - particulier_authorization_endpoint: 'https://bidon.com/endpoint', - particulier_token_endpoint: 'https://bidon.com/endpoint', - particulier_userinfo_endpoint: 'https://bidon.com/endpoint', - particulier_logout_endpoint: 'https://bidon.com/endpoint', + particulier: { + identifier: 'plop', + secret: 'plip', + redirect_uri: 'https://bidon.com/endpoint', + authorization_endpoint: 'https://bidon.com/endpoint', + token_endpoint: 'https://bidon.com/endpoint', + userinfo_endpoint: 'https://bidon.com/endpoint', + logout_endpoint: 'https://bidon.com/endpoint', + } }) end diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 6cbaac682..8c812369a 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -118,7 +118,7 @@ describe Users::SessionsController, type: :controller do let(:loged_in_with_france_connect) { 'particulier' } it 'redirect to france connect logout page' do - expect(response).to redirect_to(FRANCE_CONNECT.particulier_logout_endpoint) + expect(response).to redirect_to(FRANCE_CONNECT.particulier.logout_endpoint) end end @@ -161,7 +161,7 @@ describe Users::SessionsController, type: :controller do user.update_attributes(loged_in_with_france_connect: 'particulier') sign_in user delete :destroy - expect(@response.headers["Location"]).to eq(FRANCE_CONNECT.particulier_logout_endpoint) + expect(@response.headers["Location"]).to eq(FRANCE_CONNECT.particulier.logout_endpoint) end context "when associated administrateur" do From ec69be0f7bdf23e20089ae1eebf1f81b4c1b28ec Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 11:36:20 +0100 Subject: [PATCH 05/45] FC ParticulierClient: simplier initializer --- app/models/france_connect_particulier_client.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/models/france_connect_particulier_client.rb b/app/models/france_connect_particulier_client.rb index 934dddb6a..c3b9575a2 100644 --- a/app/models/france_connect_particulier_client.rb +++ b/app/models/france_connect_particulier_client.rb @@ -1,14 +1,6 @@ class FranceConnectParticulierClient < OpenIDConnect::Client def initialize(code = nil) - super( - identifier: FRANCE_CONNECT.particulier.identifier, - secret: FRANCE_CONNECT.particulier.secret, - redirect_uri: FRANCE_CONNECT.particulier.redirect_uri, - authorization_endpoint: FRANCE_CONNECT.particulier.authorization_endpoint, - token_endpoint: FRANCE_CONNECT.particulier.token_endpoint, - userinfo_endpoint: FRANCE_CONNECT.particulier.userinfo_endpoint, - logout_endpoint: FRANCE_CONNECT.particulier.logout_endpoint - ) + super(FRANCE_CONNECT.particulier) if code.present? self.authorization_code = code From f8519c5345cbcc158b71122d0d02e3cf260c8bfb Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 14:04:24 +0100 Subject: [PATCH 06/45] FC initializers: remove Hashie --- app/controllers/users/sessions_controller.rb | 2 +- .../france_connect_particulier_client.rb | 2 +- app/services/france_connect_salt_service.rb | 2 +- config/initializers/france_connect.rb | 7 ++++--- .../users/sessions_controller_spec.rb | 4 ++-- .../france_connect_particulier_spec.rb | 19 +++++++++++-------- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 302c19596..ea455dbfc 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -50,7 +50,7 @@ class Users::SessionsController < Sessions::SessionsController case connected_with_france_connect when 'particulier' - redirect_to FRANCE_CONNECT.particulier.logout_endpoint + redirect_to FRANCE_CONNECT[:particulier][:logout_endpoint] return end end diff --git a/app/models/france_connect_particulier_client.rb b/app/models/france_connect_particulier_client.rb index c3b9575a2..072b5ab90 100644 --- a/app/models/france_connect_particulier_client.rb +++ b/app/models/france_connect_particulier_client.rb @@ -1,6 +1,6 @@ class FranceConnectParticulierClient < OpenIDConnect::Client def initialize(code = nil) - super(FRANCE_CONNECT.particulier) + super(FRANCE_CONNECT[:particulier]) if code.present? self.authorization_code = code diff --git a/app/services/france_connect_salt_service.rb b/app/services/france_connect_salt_service.rb index 2e35b5515..97d5d83d0 100644 --- a/app/services/france_connect_salt_service.rb +++ b/app/services/france_connect_salt_service.rb @@ -11,6 +11,6 @@ class FranceConnectSaltService end def salt - Digest::MD5.hexdigest(model.france_connect_particulier_id + model.given_name + model.family_name + FRANCE_CONNECT.particulier.secret + DateTime.now.to_date.to_s) + Digest::MD5.hexdigest(model.france_connect_particulier_id + model.given_name + model.family_name + FRANCE_CONNECT[:particulier][:secret] + DateTime.now.to_date.to_s) end end diff --git a/config/initializers/france_connect.rb b/config/initializers/france_connect.rb index f4bc1d681..171f9b5b3 100644 --- a/config/initializers/france_connect.rb +++ b/config/initializers/france_connect.rb @@ -2,10 +2,11 @@ FRANCE_CONNECT = if !Rails.env.test? file_path = "#{Rails.root}/config/france_connect.yml" config_hash = YAML.safe_load(File.read(file_path)) .reduce({}) { |acc, (key, value)| acc[key.gsub('particulier_', '')] = value, acc } + .symbolize_keys - Hashie::Mash.new(particulier: config_hash) + { particulier: config_hash } else - Hashie::Mash.new({ + { particulier: { identifier: 'plop', secret: 'plip', @@ -15,5 +16,5 @@ else userinfo_endpoint: 'https://bidon.com/endpoint', logout_endpoint: 'https://bidon.com/endpoint', } - }) + } end diff --git a/spec/controllers/users/sessions_controller_spec.rb b/spec/controllers/users/sessions_controller_spec.rb index 8c812369a..2263df65e 100644 --- a/spec/controllers/users/sessions_controller_spec.rb +++ b/spec/controllers/users/sessions_controller_spec.rb @@ -118,7 +118,7 @@ describe Users::SessionsController, type: :controller do let(:loged_in_with_france_connect) { 'particulier' } it 'redirect to france connect logout page' do - expect(response).to redirect_to(FRANCE_CONNECT.particulier.logout_endpoint) + expect(response).to redirect_to(FRANCE_CONNECT[:particulier][:logout_endpoint]) end end @@ -161,7 +161,7 @@ describe Users::SessionsController, type: :controller do user.update_attributes(loged_in_with_france_connect: 'particulier') sign_in user delete :destroy - expect(@response.headers["Location"]).to eq(FRANCE_CONNECT.particulier.logout_endpoint) + expect(@response.headers["Location"]).to eq(FRANCE_CONNECT[:particulier][:logout_endpoint]) end context "when associated administrateur" do diff --git a/spec/features/france_connect/france_connect_particulier_spec.rb b/spec/features/france_connect/france_connect_particulier_spec.rb index 720523714..bbf163217 100644 --- a/spec/features/france_connect/france_connect_particulier_spec.rb +++ b/spec/features/france_connect/france_connect_particulier_spec.rb @@ -10,14 +10,17 @@ feature 'France Connect Particulier Connexion' do let(:email) { 'plop@plop.com' } let(:france_connect_particulier_id) { 'blabla' } - let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, - given_name: given_name, - family_name: family_name, - birthdate: birthdate, - birthplace: birthplace, - gender: gender, - email: email) - } + let(:user_info) do + { + france_connect_particulier_id: france_connect_particulier_id, + given_name: given_name, + family_name: family_name, + birthdate: birthdate, + birthplace: birthplace, + gender: gender, + email_france_connect: email + } + end context 'when user is on login page' do before do From b35a88ffd42f3465eb4da9fbbfb0e16cd702e7ae Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 14:37:53 +0100 Subject: [PATCH 07/45] FC initializers: simplify --- config/initializers/france_connect.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/config/initializers/france_connect.rb b/config/initializers/france_connect.rb index 171f9b5b3..a3702335b 100644 --- a/config/initializers/france_connect.rb +++ b/config/initializers/france_connect.rb @@ -1,11 +1,4 @@ -FRANCE_CONNECT = if !Rails.env.test? - file_path = "#{Rails.root}/config/france_connect.yml" - config_hash = YAML.safe_load(File.read(file_path)) - .reduce({}) { |acc, (key, value)| acc[key.gsub('particulier_', '')] = value, acc } - .symbolize_keys - - { particulier: config_hash } -else +FRANCE_CONNECT = if Rails.env.test? { particulier: { identifier: 'plop', @@ -17,4 +10,13 @@ else logout_endpoint: 'https://bidon.com/endpoint', } } +else + fc_config_file_path = "#{Rails.root}/config/france_connect.yml" + + # FIXME: with a yaml with a { particulier: {} } structure + config_hash = YAML.safe_load(File.read(fc_config_file_path)) + .reduce({}) { |acc, (key, value)| acc[key.gsub('particulier_', '')] = value; acc } + .symbolize_keys + + { particulier: config_hash } end From fc4ce4460cde2b727b3fa448d42a211d2d83887f Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 15:23:07 +0100 Subject: [PATCH 08/45] FC Particulier Controller: do not parse an URI into URI --- app/controllers/france_connect/particulier_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 3d0e0a0f7..1f0ee1a05 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -10,7 +10,7 @@ class FranceConnect::ParticulierController < ApplicationController state: session[:state], nonce: session[:nonce] ) - redirect_to URI.parse(authorization_uri).to_s + redirect_to authorization_uri end def callback From 9dc242d9075c3cab7f51c41a8d9fafecad454883 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 15:29:58 +0100 Subject: [PATCH 09/45] FC Particulier Controller: simplier login --- .../france_connect/particulier_controller.rb | 12 +----------- app/services/france_connect_service.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 1f0ee1a05..271bfe89a 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -1,16 +1,6 @@ class FranceConnect::ParticulierController < ApplicationController def login - client = FranceConnectParticulierClient.new - - session[:state] = SecureRandom.hex(16) - session[:nonce] = SecureRandom.hex(16) - - authorization_uri = client.authorization_uri( - scope: [:profile, :email], - state: session[:state], - nonce: session[:nonce] - ) - redirect_to authorization_uri + redirect_to FranceConnectService.authorization_uri end def callback diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index a5ebc6cab..d844fd82a 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -1,4 +1,13 @@ class FranceConnectService + def self.authorization_uri + client = FranceConnectParticulierClient.new + + client.authorization_uri( + scope: [:profile, :email], + state: SecureRandom.hex(16), + nonce: SecureRandom.hex(16)) + end + def self.retrieve_user_informations_particulier code client = FranceConnectParticulierClient.new(code) From 4294c8eec7520f2e4e5fbc4728a8fcd9f8780aa8 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 15:54:39 +0100 Subject: [PATCH 10/45] Brakeman: make it happy --- config/brakeman.ignore | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 config/brakeman.ignore diff --git a/config/brakeman.ignore b/config/brakeman.ignore new file mode 100644 index 000000000..a8ca1ae00 --- /dev/null +++ b/config/brakeman.ignore @@ -0,0 +1,26 @@ +{ + "ignored_warnings": [ + { + "warning_type": "Redirect", + "warning_code": 18, + "fingerprint": "a0a4cede6d50308b90bd747efd0a2ebd58947fbd5d100349ccd640c60413b1a9", + "check_name": "Redirect", + "message": "Possible unprotected redirect", + "file": "app/controllers/france_connect/particulier_controller.rb", + "line": 3, + "link": "http://brakemanscanner.org/docs/warning_types/redirect/", + "code": "redirect_to(FranceConnectParticulierClient.new.authorization_uri)", + "render_path": null, + "location": { + "type": "method", + "class": "FranceConnect::ParticulierController", + "method": "login" + }, + "user_input": "FranceConnectParticulierClient.new.authorization_uri", + "confidence": "High", + "note": "We trust FC OpenId implem" + } + ], + "updated": "2018-01-11 15:53:22 +0100", + "brakeman_version": "3.7.0" +} From e68fc0811f1a7875cecb07108511c0b0c7d31126 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 16:00:14 +0100 Subject: [PATCH 11/45] FC ParticulierController: callback syntax cleaning --- .../france_connect/particulier_controller.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 271bfe89a..451149820 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -4,14 +4,17 @@ class FranceConnect::ParticulierController < ApplicationController end def callback - return redirect_to new_user_session_path if !params.has_key?(:code) + if params[:code].nil? + return redirect_to new_user_session_path + end user_infos = FranceConnectService.retrieve_user_informations_particulier(params[:code]) if user_infos.present? - france_connect_information = FranceConnectInformation.find_by_france_connect_particulier user_infos + france_connect_information = FranceConnectInformation.find_by_france_connect_particulier(user_infos) - france_connect_information = FranceConnectInformation.create( + if france_connect_information.nil? + france_connect_information = FranceConnectInformation.create( {gender: user_infos[:gender], given_name: user_infos[:given_name], family_name: user_infos[:family_name], @@ -19,14 +22,17 @@ class FranceConnect::ParticulierController < ApplicationController birthdate: user_infos[:birthdate], birthplace: user_infos[:birthplace], france_connect_particulier_id: user_infos[:france_connect_particulier_id]} - ) if france_connect_information.nil? + ) + end user = france_connect_information.user salt = FranceConnectSaltService.new(france_connect_information).salt - return redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) if user.nil? + if user.nil? + return redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) + end - connect_france_connect_particulier user + connect_france_connect_particulier(user) end rescue Rack::OAuth2::Client::Error => e Rails.logger.error e.message From 8e26a50f162775b58939ba3a058029ef66679b78 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 17:07:35 +0100 Subject: [PATCH 12/45] FC service: clean syntax --- app/services/france_connect_service.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index d844fd82a..3ccca2f50 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -8,12 +8,13 @@ class FranceConnectService nonce: SecureRandom.hex(16)) end - def self.retrieve_user_informations_particulier code + def self.retrieve_user_informations_particulier(code) client = FranceConnectParticulierClient.new(code) access_token = client.access_token!(client_auth_method: :secret) + user_info = access_token.userinfo! - hash = Hashie::Mash.new user_info.raw_attributes + hash = Hashie::Mash.new(user_info.raw_attributes) hash.france_connect_particulier_id = hash.sub hash From 7024e14d1cbf575561b9aacd289c7c1eac24c689 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 18:26:55 +0100 Subject: [PATCH 13/45] FC information: remove funny find_by --- .../france_connect/particulier_controller.rb | 3 ++- app/models/france_connect_information.rb | 4 ---- spec/models/france_connect_information_spec.rb | 16 ---------------- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 451149820..71b9f8e0e 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -11,7 +11,8 @@ class FranceConnect::ParticulierController < ApplicationController user_infos = FranceConnectService.retrieve_user_informations_particulier(params[:code]) if user_infos.present? - france_connect_information = FranceConnectInformation.find_by_france_connect_particulier(user_infos) + france_connect_information = FranceConnectInformation + .find_by(france_connect_particulier_id: user_infos[:france_connect_particulier_id]) if france_connect_information.nil? france_connect_information = FranceConnectInformation.create( diff --git a/app/models/france_connect_information.rb b/app/models/france_connect_information.rb index 6bf7f7a85..76e804399 100644 --- a/app/models/france_connect_information.rb +++ b/app/models/france_connect_information.rb @@ -2,8 +2,4 @@ class FranceConnectInformation < ActiveRecord::Base belongs_to :user validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false - - def self.find_by_france_connect_particulier user_info - FranceConnectInformation.find_by(france_connect_particulier_id: user_info[:france_connect_particulier_id]) - end end diff --git a/spec/models/france_connect_information_spec.rb b/spec/models/france_connect_information_spec.rb index 330fc679c..96413d621 100644 --- a/spec/models/france_connect_information_spec.rb +++ b/spec/models/france_connect_information_spec.rb @@ -8,20 +8,4 @@ describe FranceConnectInformation, type: :model do it { is_expected.to allow_value('mon super projet').for(:france_connect_particulier_id) } end end - - describe '.find_by_france_connect_particulier' do - let(:user_info) { {france_connect_particulier_id: '123456'} } - - subject { described_class.find_by_france_connect_particulier user_info } - - context 'when france_connect_particulier_id is prensent in database' do - let!(:france_connect_information) { create(:france_connect_information, france_connect_particulier_id: '123456') } - - it { is_expected.to eq france_connect_information } - end - - context 'when france_connect_particulier_id is prensent in database' do - it { is_expected.to eq nil } - end - end end From 02395e732cb3e7fb8232fcd3d276528560f389c8 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 18:16:38 +0100 Subject: [PATCH 14/45] FC service: return domain info --- .../france_connect/particulier_controller.rb | 17 +++++----------- app/services/france_connect_service.rb | 17 ++++++++++------ .../particulier_controller_spec.rb | 5 +++-- .../france_connect_particulier_spec.rb | 2 +- spec/services/france_connect_service_spec.rb | 20 +++++++++---------- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 71b9f8e0e..d93d2ef0a 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -8,22 +8,15 @@ class FranceConnect::ParticulierController < ApplicationController return redirect_to new_user_session_path end - user_infos = FranceConnectService.retrieve_user_informations_particulier(params[:code]) + fetched_fc_information = FranceConnectService.retrieve_user_informations_particulier(params[:code]) - if user_infos.present? + if fetched_fc_information.present? france_connect_information = FranceConnectInformation - .find_by(france_connect_particulier_id: user_infos[:france_connect_particulier_id]) + .find_by(france_connect_particulier_id: fetched_fc_information[:france_connect_particulier_id]) if france_connect_information.nil? - france_connect_information = FranceConnectInformation.create( - {gender: user_infos[:gender], - given_name: user_infos[:given_name], - family_name: user_infos[:family_name], - email_france_connect: user_infos[:email], - birthdate: user_infos[:birthdate], - birthplace: user_infos[:birthplace], - france_connect_particulier_id: user_infos[:france_connect_particulier_id]} - ) + fetched_fc_information.save + france_connect_information = fetched_fc_information end user = france_connect_information.user diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index 3ccca2f50..bbfe73794 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -11,12 +11,17 @@ class FranceConnectService def self.retrieve_user_informations_particulier(code) client = FranceConnectParticulierClient.new(code) - access_token = client.access_token!(client_auth_method: :secret) + user_info = client.access_token!(client_auth_method: :secret) + .userinfo! + .raw_attributes - user_info = access_token.userinfo! - hash = Hashie::Mash.new(user_info.raw_attributes) - - hash.france_connect_particulier_id = hash.sub - hash + FranceConnectInformation.new( + gender: user_info[:gender], + given_name: user_info[:given_name], + family_name: user_info[:family_name], + email_france_connect: user_info[:email], + birthdate: user_info[:birthdate], + birthplace: user_info[:birthplace], + france_connect_particulier_id: user_info[:sub]) end end diff --git a/spec/controllers/france_connect/particulier_controller_spec.rb b/spec/controllers/france_connect/particulier_controller_spec.rb index 279f7b9ef..9bc9e61fd 100644 --- a/spec/controllers/france_connect/particulier_controller_spec.rb +++ b/spec/controllers/france_connect/particulier_controller_spec.rb @@ -11,7 +11,7 @@ describe FranceConnect::ParticulierController, type: :controller do let(:email) { 'test@test.com' } let(:password) { '' } - let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email: email, password: password) } + let(:user_info) { { france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email_france_connect: email } } describe '.auth' do it 'redirect to france connect serveur' do @@ -31,7 +31,8 @@ describe FranceConnect::ParticulierController, type: :controller do context 'when params code is present' do context 'when code is correct' do before do - allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(user_info) + allow(FranceConnectService).to receive(:retrieve_user_informations_particulier) + .and_return(FranceConnectInformation.new(user_info)) end context 'when france_connect_particulier_id exist in database' do diff --git a/spec/features/france_connect/france_connect_particulier_spec.rb b/spec/features/france_connect/france_connect_particulier_spec.rb index bbf163217..7f1b263af 100644 --- a/spec/features/france_connect/france_connect_particulier_spec.rb +++ b/spec/features/france_connect/france_connect_particulier_spec.rb @@ -47,7 +47,7 @@ feature 'France Connect Particulier Connexion' do before do allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code)) - allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(user_info) + allow(FranceConnectService).to receive(:retrieve_user_informations_particulier).and_return(FranceConnectInformation.new(user_info)) end context 'when is the first connexion' do diff --git a/spec/services/france_connect_service_spec.rb b/spec/services/france_connect_service_spec.rb index 7374ecb32..342b8eb2e 100644 --- a/spec/services/france_connect_service_spec.rb +++ b/spec/services/france_connect_service_spec.rb @@ -7,7 +7,7 @@ describe FranceConnectService do let(:given_name) { 'plop1' } let(:family_name) { 'plop2' } - let(:birthdate) { 'plop3' } + let(:birthdate) { '2012-12-31' } let(:gender) { 'plop4' } let(:birthplace) { 'plop5' } let(:email) { 'plop@emaiL.com' } @@ -29,15 +29,15 @@ describe FranceConnectService do subject end - it 'returns user informations in a object' do - expect(subject.given_name).to eq(given_name) - expect(subject.family_name).to eq(family_name) - expect(subject.birthdate).to eq(birthdate) - expect(subject.gender).to eq(gender) - expect(subject.email).to eq(email) - expect(subject.phone).to eq(phone) - expect(subject.birthplace).to eq(birthplace) - expect(subject.france_connect_particulier_id).to eq(france_connect_particulier_id) + it 'returns user informations' do + expect(subject).to have_attributes({ + given_name: given_name, + family_name: family_name, + birthdate: DateTime.parse(birthdate), + birthplace: birthplace, + gender: gender, + email_france_connect: email, + france_connect_particulier_id: france_connect_particulier_id }) end end end From 34bd3a11e986fa2ecde4b536d7fa1f3f55d17cb3 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 15 Jan 2018 13:19:01 +0100 Subject: [PATCH 15/45] FC ParticulierController: remove superfluous if --- .../france_connect/particulier_controller.rb | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index d93d2ef0a..12c2b828f 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -10,24 +10,22 @@ class FranceConnect::ParticulierController < ApplicationController fetched_fc_information = FranceConnectService.retrieve_user_informations_particulier(params[:code]) - if fetched_fc_information.present? - france_connect_information = FranceConnectInformation - .find_by(france_connect_particulier_id: fetched_fc_information[:france_connect_particulier_id]) + france_connect_information = FranceConnectInformation + .find_by(france_connect_particulier_id: fetched_fc_information[:france_connect_particulier_id]) - if france_connect_information.nil? - fetched_fc_information.save - france_connect_information = fetched_fc_information - end - - user = france_connect_information.user - salt = FranceConnectSaltService.new(france_connect_information).salt - - if user.nil? - return redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) - end - - connect_france_connect_particulier(user) + if france_connect_information.nil? + fetched_fc_information.save + france_connect_information = fetched_fc_information end + + user = france_connect_information.user + salt = FranceConnectSaltService.new(france_connect_information).salt + + if user.nil? + return redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) + end + + connect_france_connect_particulier(user) rescue Rack::OAuth2::Client::Error => e Rails.logger.error e.message redirect_france_connect_error_connection From d086b82d44fde461fcf1d24a1876049ba18058d6 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 15 Jan 2018 13:20:47 +0100 Subject: [PATCH 16/45] FC ParticulierController: remove one return --- app/controllers/france_connect/particulier_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 12c2b828f..283660636 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -22,10 +22,10 @@ class FranceConnect::ParticulierController < ApplicationController salt = FranceConnectSaltService.new(france_connect_information).salt if user.nil? - return redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) + redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) + else + connect_france_connect_particulier(user) end - - connect_france_connect_particulier(user) rescue Rack::OAuth2::Client::Error => e Rails.logger.error e.message redirect_france_connect_error_connection From 5b1d5787269025c9b82eaeaa794179f5d16831c2 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 10:02:32 +0100 Subject: [PATCH 17/45] Delete 3 now unused tables --- ...11153245_drop_preference_devise_profils.rb | 5 ++++ ...111153257_drop_preference_list_dossiers.rb | 5 ++++ ...308_drop_preference_smart_listing_pages.rb | 5 ++++ db/schema.rb | 28 +------------------ 4 files changed, 16 insertions(+), 27 deletions(-) create mode 100644 db/migrate/20180111153245_drop_preference_devise_profils.rb create mode 100644 db/migrate/20180111153257_drop_preference_list_dossiers.rb create mode 100644 db/migrate/20180111153308_drop_preference_smart_listing_pages.rb diff --git a/db/migrate/20180111153245_drop_preference_devise_profils.rb b/db/migrate/20180111153245_drop_preference_devise_profils.rb new file mode 100644 index 000000000..c8c53cc1b --- /dev/null +++ b/db/migrate/20180111153245_drop_preference_devise_profils.rb @@ -0,0 +1,5 @@ +class DropPreferenceDeviseProfils < ActiveRecord::Migration[5.0] + def change + drop_table :preference_devise_profils + end +end diff --git a/db/migrate/20180111153257_drop_preference_list_dossiers.rb b/db/migrate/20180111153257_drop_preference_list_dossiers.rb new file mode 100644 index 000000000..91b65374e --- /dev/null +++ b/db/migrate/20180111153257_drop_preference_list_dossiers.rb @@ -0,0 +1,5 @@ +class DropPreferenceListDossiers < ActiveRecord::Migration[5.0] + def change + drop_table :preference_list_dossiers + end +end diff --git a/db/migrate/20180111153308_drop_preference_smart_listing_pages.rb b/db/migrate/20180111153308_drop_preference_smart_listing_pages.rb new file mode 100644 index 000000000..fac3e1bc8 --- /dev/null +++ b/db/migrate/20180111153308_drop_preference_smart_listing_pages.rb @@ -0,0 +1,5 @@ +class DropPreferenceSmartListingPages < ActiveRecord::Migration[5.0] + def change + drop_table :preference_smart_listing_pages + end +end diff --git a/db/schema.rb b/db/schema.rb index 1b15e08d0..08f4ec561 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180108152958) do +ActiveRecord::Schema.define(version: 20180111153308) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -354,32 +354,6 @@ ActiveRecord::Schema.define(version: 20180108152958) do t.index ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree end - create_table "preference_devise_profils", force: :cascade do |t| - t.string "last_current_devise_profil" - t.integer "administrateurs_id" - t.integer "gestionnaires_id" - t.integer "users_id" - end - - create_table "preference_list_dossiers", force: :cascade do |t| - t.string "libelle" - t.string "table" - t.string "attr" - t.string "attr_decorate" - t.string "bootstrap_lg" - t.string "order" - t.string "filter" - t.integer "gestionnaire_id" - t.integer "procedure_id" - end - - create_table "preference_smart_listing_pages", force: :cascade do |t| - t.string "liste" - t.integer "page" - t.integer "procedure_id" - t.integer "gestionnaire_id" - end - create_table "procedure_paths", force: :cascade do |t| t.string "path" t.integer "procedure_id" From 08ed400ec2f06b69bdb92cc92db0f86d1532078e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 14:42:48 +0100 Subject: [PATCH 18/45] Enable the Layout/FirstArrayElementLineBreak cop --- .rubocop.yml | 2 +- app/jobs/find_dubious_procedures_job.rb | 6 ++- app/lib/siade/entreprise_adapter.rb | 26 +++++----- app/lib/siade/etablissement_adapter.rb | 25 +++++---- app/lib/siade/rna_adapter.rb | 13 ++--- .../concerns/tags_substitution_concern.rb | 52 +++++++++++-------- app/models/gestionnaire.rb | 50 ++++++++++-------- app/models/procedure_overview.rb | 8 +-- app/services/types_de_champ_service.rb | 12 ++++- ...2_build_default_preference_list_dossier.rb | 38 ++++++++------ ...95443_reset_all_preference_list_dossier.rb | 38 ++++++++------ spec/jobs/find_dubious_procedures_job_spec.rb | 6 ++- spec/lib/carto/sgmap/cadastre/adapter_spec.rb | 20 +++---- spec/models/attestation_template_spec.rb | 6 ++- .../concern/tags_substitution_concern_spec.rb | 12 +++-- spec/models/procedure_spec.rb | 21 ++++---- spec/services/geojson_service_spec.rb | 15 ++---- 17 files changed, 201 insertions(+), 149 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 526ff5ee4..89c9c3630 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -83,7 +83,7 @@ Layout/ExtraSpacing: - "Guardfile" Layout/FirstArrayElementLineBreak: - Enabled: false + Enabled: true Layout/FirstHashElementLineBreak: Enabled: false diff --git a/app/jobs/find_dubious_procedures_job.rb b/app/jobs/find_dubious_procedures_job.rb index 5c6122db8..b0a30e8f3 100644 --- a/app/jobs/find_dubious_procedures_job.rb +++ b/app/jobs/find_dubious_procedures_job.rb @@ -1,8 +1,10 @@ class FindDubiousProceduresJob < ApplicationJob queue_as :cron - FORBIDDEN_KEYWORDS = ['IBAN', 'NIR', 'NIRPP', 'race', 'religion', - 'carte bancaire', 'carte bleue', 'sécurité sociale'] + FORBIDDEN_KEYWORDS = [ + 'IBAN', 'NIR', 'NIRPP', 'race', 'religion', + 'carte bancaire', 'carte bleue', 'sécurité sociale' + ] def perform(*args) # \\y is a word boundary diff --git a/app/lib/siade/entreprise_adapter.rb b/app/lib/siade/entreprise_adapter.rb index d926ae189..97723db98 100644 --- a/app/lib/siade/entreprise_adapter.rb +++ b/app/lib/siade/entreprise_adapter.rb @@ -23,18 +23,20 @@ class SIADE::EntrepriseAdapter end def attr_to_fetch - [:siren, - :capital_social, - :numero_tva_intracommunautaire, - :forme_juridique, - :forme_juridique_code, - :nom_commercial, - :raison_sociale, - :siret_siege_social, - :code_effectif_entreprise, - :date_creation, - :nom, - :prenom] + [ + :siren, + :capital_social, + :numero_tva_intracommunautaire, + :forme_juridique, + :forme_juridique_code, + :nom_commercial, + :raison_sociale, + :siret_siege_social, + :code_effectif_entreprise, + :date_creation, + :nom, + :prenom + ] end def mandataires_sociaux diff --git a/app/lib/siade/etablissement_adapter.rb b/app/lib/siade/etablissement_adapter.rb index 3de8f816d..ef03721b3 100644 --- a/app/lib/siade/etablissement_adapter.rb +++ b/app/lib/siade/etablissement_adapter.rb @@ -23,10 +23,11 @@ class SIADE::EtablissementAdapter end def attr_to_fetch - [:siret, - :siege_social, - :naf, - :libelle_naf + [ + :siret, + :siege_social, + :naf, + :libelle_naf ] end @@ -41,12 +42,14 @@ class SIADE::EtablissementAdapter end def address_attribut_to_fetch - [:numero_voie, - :type_voie, - :nom_voie, - :complement_adresse, - :code_postal, - :localite, - :code_insee_localite] + [ + :numero_voie, + :type_voie, + :nom_voie, + :complement_adresse, + :code_postal, + :localite, + :code_insee_localite + ] end end diff --git a/app/lib/siade/rna_adapter.rb b/app/lib/siade/rna_adapter.rb index 80580c336..fd4686eee 100644 --- a/app/lib/siade/rna_adapter.rb +++ b/app/lib/siade/rna_adapter.rb @@ -23,12 +23,13 @@ class SIADE::RNAAdapter end def attr_to_fetch - [:id, - :titre, - :objet, - :date_creation, - :date_declaration, - :date_publication + [ + :id, + :titre, + :objet, + :date_creation, + :date_declaration, + :date_publication ] end end diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index b224e7f46..74e549508 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -28,22 +28,24 @@ module TagsSubstitutionConcern end def dossier_tags - [{ libelle: 'motivation', - description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite', - target: :motivation, - dossier_termine_only: true }, - { libelle: 'date de dépôt', - description: 'Date du passage en construction du dossier par l’usager', - lambda: -> (d) { format_date(d.en_construction_at) } }, - { libelle: 'date de passage en instruction', - description: '', - lambda: -> (d) { format_date(d.en_instruction_at) } }, - { libelle: 'date de décision', - description: 'Date de la décision d’acceptation, refus, ou classement sans suite', - lambda: -> (d) { format_date(d.processed_at) }, - dossier_termine_only: true }, - { libelle: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } }, - { libelle: 'numéro du dossier', description: '', target: :id }] + [ + { libelle: 'motivation', + description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite', + target: :motivation, + dossier_termine_only: true }, + { libelle: 'date de dépôt', + description: 'Date du passage en construction du dossier par l’usager', + lambda: -> (d) { format_date(d.en_construction_at) } }, + { libelle: 'date de passage en instruction', + description: '', + lambda: -> (d) { format_date(d.en_instruction_at) } }, + { libelle: 'date de décision', + description: 'Date de la décision d’acceptation, refus, ou classement sans suite', + lambda: -> (d) { format_date(d.processed_at) }, + dossier_termine_only: true }, + { libelle: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } }, + { libelle: 'numéro du dossier', description: '', target: :id } + ] end def format_date(date) @@ -55,16 +57,20 @@ module TagsSubstitutionConcern end def individual_tags - [{ libelle: 'civilité', description: 'M., Mme', target: :gender }, - { libelle: 'nom', description: "nom de l'usager", target: :nom }, - { libelle: 'prénom', description: "prénom de l'usager", target: :prenom }] + [ + { libelle: 'civilité', description: 'M., Mme', target: :gender }, + { libelle: 'nom', description: "nom de l'usager", target: :nom }, + { libelle: 'prénom', description: "prénom de l'usager", target: :prenom } + ] end def entreprise_tags - [{ libelle: 'SIREN', description: '', target: :siren }, - { libelle: 'numéro de TVA intracommunautaire', description: '', target: :numero_tva_intracommunautaire }, - { libelle: 'SIRET du siège social', description: '', target: :siret_siege_social }, - { libelle: 'raison sociale', description: '', target: :raison_sociale }] + [ + { libelle: 'SIREN', description: '', target: :siren }, + { libelle: 'numéro de TVA intracommunautaire', description: '', target: :numero_tva_intracommunautaire }, + { libelle: 'SIRET du siège social', description: '', target: :siret_siege_social }, + { libelle: 'raison sociale', description: '', target: :raison_sociale } + ] end def etablissement_tags diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 2518679a6..cd952b0de 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -154,22 +154,28 @@ class Gestionnaire < ActiveRecord::Base private def valid_couple_table_attr? table, column - couples = [{ - table: :dossier, - column: :dossier_id - }, { - table: :procedure, - column: :libelle - }, { - table: :etablissement, - column: :siret - }, { - table: :entreprise, - column: :raison_sociale - }, { - table: :dossier, - column: :state - }] + couples = [ + { + table: :dossier, + column: :dossier_id + }, + { + table: :procedure, + column: :libelle + }, + { + table: :etablissement, + column: :siret + }, + { + table: :entreprise, + column: :raison_sociale + }, + { + table: :dossier, + column: :state + } + ] couples.include?({table: table, column: column}) end @@ -205,10 +211,12 @@ class Gestionnaire < ActiveRecord::Base .where('commentaires.updated_at > follows.messagerie_seen_at') .where.not(commentaires: { email: 'contact@tps.apientreprise.fr' }) - [updated_demandes, - updated_pieces_justificatives, - updated_annotations, - updated_avis, - updated_messagerie].map { |query| query.distinct.ids }.flatten.uniq + [ + updated_demandes, + updated_pieces_justificatives, + updated_annotations, + updated_avis, + updated_messagerie + ].map { |query| query.distinct.ids }.flatten.uniq end end diff --git a/app/models/procedure_overview.rb b/app/models/procedure_overview.rb index 98519936c..ddb70a8d1 100644 --- a/app/models/procedure_overview.rb +++ b/app/models/procedure_overview.rb @@ -30,9 +30,11 @@ class ProcedureOverview end def had_some_activities? - [@dossiers_en_instruction_count, - @dossiers_en_construction_count, - @created_dossiers_count].reduce(:+) > 0 + [ + @dossiers_en_instruction_count, + @dossiers_en_construction_count, + @created_dossiers_count + ].reduce(:+) > 0 end def dossiers_en_construction_description diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index 7dcf3adb4..73ab53bd3 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -6,8 +6,16 @@ class TypesDeChampService parameters = params_with_ordered_champs .require(:procedure) - .permit("#{attributes}" => [:libelle, :description, :order_place, :type_champ, :id, :mandatory, :type, - drop_down_list_attributes: [:value, :id]]) + .permit("#{attributes}" => [ + :libelle, + :description, + :order_place, + :type_champ, + :id, + :mandatory, + :type, + drop_down_list_attributes: [:value, :id] + ]) parameters[attributes].each do |param_first, param_second| if param_second[:libelle].empty? diff --git a/db/migrate/20160802113112_build_default_preference_list_dossier.rb b/db/migrate/20160802113112_build_default_preference_list_dossier.rb index 2a11ea8f0..66d344fe8 100644 --- a/db/migrate/20160802113112_build_default_preference_list_dossier.rb +++ b/db/migrate/20160802113112_build_default_preference_list_dossier.rb @@ -20,22 +20,28 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration end def valid_couple_table_attr? table, column - couples = [{ - table: :dossier, - column: :dossier_id - }, { - table: :procedure, - column: :libelle - }, { - table: :etablissement, - column: :siret - }, { - table: :entreprise, - column: :raison_sociale - }, { - table: :dossier, - column: :state - }] + couples = [ + { + table: :dossier, + column: :dossier_id + }, + { + table: :procedure, + column: :libelle + }, + { + table: :etablissement, + column: :siret + }, + { + table: :entreprise, + column: :raison_sociale + }, + { + table: :dossier, + column: :state + } + ] couples.include?({table: table, column: column}) end diff --git a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb index 137cf286b..172ee1fbb 100644 --- a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb +++ b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb @@ -118,22 +118,28 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration private def valid_couple_table_attr? table, column - couples = [{ - table: :dossier, - column: :dossier_id - }, { - table: :procedure, - column: :libelle - }, { - table: :etablissement, - column: :siret - }, { - table: :entreprise, - column: :raison_sociale - }, { - table: :dossier, - column: :state - }] + couples = [ + { + table: :dossier, + column: :dossier_id + }, + { + table: :procedure, + column: :libelle + }, + { + table: :etablissement, + column: :siret + }, + { + table: :entreprise, + column: :raison_sociale + }, + { + table: :dossier, + column: :state + } + ] couples.include?({table: table, column: column}) end diff --git a/spec/jobs/find_dubious_procedures_job_spec.rb b/spec/jobs/find_dubious_procedures_job_spec.rb index 01776aee7..d18ac6992 100644 --- a/spec/jobs/find_dubious_procedures_job_spec.rb +++ b/spec/jobs/find_dubious_procedures_job_spec.rb @@ -16,8 +16,10 @@ RSpec.describe FindDubiousProceduresJob, type: :job do context 'with suspicious champs' do let(:forbidden_tdcs) do - [create(:type_de_champ_public, libelle: 'num de securite sociale, stp'), - create(:type_de_champ_public, libelle: "t'aurais une carte bancaire ?")] + [ + create(:type_de_champ_public, libelle: 'num de securite sociale, stp'), + create(:type_de_champ_public, libelle: "t'aurais une carte bancaire ?") + ] end let(:tdcs) { forbidden_tdcs + [allowed_tdc] } diff --git a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb index 96734e784..3e33ae2f8 100644 --- a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb +++ b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb @@ -23,15 +23,17 @@ describe CARTO::SGMAP::Cadastre::Adapter do subject { adapter.filter_properties adapter.data_source } it { expect(subject.size).to eq 9 } - it { expect(subject.keys).to eq [:surface_intersection, - :surface_parcelle, - :numero, - :feuille, - :section, - :code_dep, - :nom_com, - :code_com, - :code_arr] + it { expect(subject.keys).to eq [ + :surface_intersection, + :surface_parcelle, + :numero, + :feuille, + :section, + :code_dep, + :nom_com, + :code_com, + :code_arr + ] } end diff --git a/spec/models/attestation_template_spec.rb b/spec/models/attestation_template_spec.rb index a02b29b52..455907c8a 100644 --- a/spec/models/attestation_template_spec.rb +++ b/spec/models/attestation_template_spec.rb @@ -148,8 +148,10 @@ describe AttestationTemplate, type: :model do context 'when the procedure has a type de champ named libelleA et libelleB' do let(:types_de_champ) do - [create(:type_de_champ_public, libelle: 'libelleA'), - create(:type_de_champ_public, libelle: 'libelleB')] + [ + create(:type_de_champ_public, libelle: 'libelleA'), + create(:type_de_champ_public, libelle: 'libelleB') + ] end context 'and the are used in the template title and body' do diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 6ab217926..7d6acfa62 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -74,8 +74,10 @@ describe TagsSubstitutionConcern, type: :model do context 'when the procedure has a type de champ named libelleA et libelleB' do let(:types_de_champ) do - [create(:type_de_champ_public, libelle: 'libelleA'), - create(:type_de_champ_public, libelle: 'libelleB')] + [ + create(:type_de_champ_public, libelle: 'libelleA'), + create(:type_de_champ_public, libelle: 'libelleB') + ] end context 'and the template is nil' do @@ -142,8 +144,10 @@ describe TagsSubstitutionConcern, type: :model do context 'when the procedure has 2 types de champ date and datetime' do let(:types_de_champ) do - [create(:type_de_champ_public, libelle: 'date', type_champ: 'date'), - create(:type_de_champ_public, libelle: 'datetime', type_champ: 'datetime')] + [ + create(:type_de_champ_public, libelle: 'date', type_champ: 'date'), + create(:type_de_champ_public, libelle: 'datetime', type_champ: 'datetime') + ] end context 'and the are used in the template' do diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index e5a1e0e95..c749185e8 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -474,15 +474,18 @@ describe Procedure do subject { create(:procedure) } before do - allow(subject).to receive(:fields).and_return([{ - "label" => "label1", - "table" => "table1", - "column" => "column1" - }, { - "label" => "label2", - "table" => "table2", - "column" => "column2" - }]) + allow(subject).to receive(:fields).and_return([ + { + "label" => "label1", + "table" => "table1", + "column" => "column1" + }, + { + "label" => "label2", + "table" => "table2", + "column" => "column2" + } + ]) end it { expect(subject.fields_for_select).to eq([["label1", "table1/column1"], ["label2", "table2/column2"]]) } diff --git a/spec/services/geojson_service_spec.rb b/spec/services/geojson_service_spec.rb index eab37088d..7837e7d72 100644 --- a/spec/services/geojson_service_spec.rb +++ b/spec/services/geojson_service_spec.rb @@ -3,16 +3,11 @@ require 'spec_helper' describe GeojsonService do let(:good_coordinates) { [ - [5.93536376953125, - 48.91888968903368], - [5.93536376953125, - 49.26780455063753], - [7.094421386718749, - 49.26780455063753], - [7.094421386718749, - 48.91888968903368], - [5.93536376953125, - 48.91888968903368] + [5.93536376953125, 48.91888968903368], + [5.93536376953125, 49.26780455063753], + [7.094421386718749, 49.26780455063753], + [7.094421386718749, 48.91888968903368], + [5.93536376953125, 48.91888968903368] ] } From 9f855afdfe828ba2ebda819bb910999439360d9a Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 15:34:26 +0100 Subject: [PATCH 19/45] Enable the Layout/FirstHashElementLineBreak cop --- .rubocop.yml | 2 +- .../concerns/tags_substitution_concern.rb | 24 +++++++---- ...94750_create_france_connect_information.rb | 30 +++++++------ .../attestation_templates_controller_spec.rb | 30 ++++++++----- .../admin/mail_templates_controller_spec.rb | 9 ++-- .../admin/types_de_champ_controller_spec.rb | 41 +++++++++--------- .../types_de_champ_private_controller_spec.rb | 43 +++++++++---------- .../new_gestionnaire/avis_controller_spec.rb | 12 +++--- .../dossiers_controller_spec.rb | 10 +++-- .../description_controller_shared_example.rb | 34 +++++++++------ 10 files changed, 135 insertions(+), 100 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 89c9c3630..7653b091c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -86,7 +86,7 @@ Layout/FirstArrayElementLineBreak: Enabled: true Layout/FirstHashElementLineBreak: - Enabled: false + Enabled: true Layout/FirstMethodArgumentLineBreak: Enabled: false diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index 74e549508..0fc3b059e 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -29,20 +29,28 @@ module TagsSubstitutionConcern def dossier_tags [ - { libelle: 'motivation', + { + libelle: 'motivation', description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite', target: :motivation, - dossier_termine_only: true }, - { libelle: 'date de dépôt', + dossier_termine_only: true + }, + { + libelle: 'date de dépôt', description: 'Date du passage en construction du dossier par l’usager', - lambda: -> (d) { format_date(d.en_construction_at) } }, - { libelle: 'date de passage en instruction', + lambda: -> (d) { format_date(d.en_construction_at) } + }, + { + libelle: 'date de passage en instruction', description: '', - lambda: -> (d) { format_date(d.en_instruction_at) } }, - { libelle: 'date de décision', + lambda: -> (d) { format_date(d.en_instruction_at) } + }, + { + libelle: 'date de décision', description: 'Date de la décision d’acceptation, refus, ou classement sans suite', lambda: -> (d) { format_date(d.processed_at) }, - dossier_termine_only: true }, + dossier_termine_only: true + }, { libelle: 'libellé procédure', description: '', lambda: -> (d) { d.procedure.libelle } }, { libelle: 'numéro du dossier', description: '', target: :id } ] diff --git a/db/migrate/20160120094750_create_france_connect_information.rb b/db/migrate/20160120094750_create_france_connect_information.rb index 9e16a3343..88f7f1128 100644 --- a/db/migrate/20160120094750_create_france_connect_information.rb +++ b/db/migrate/20160120094750_create_france_connect_information.rb @@ -18,13 +18,15 @@ class CreateFranceConnectInformation < ActiveRecord::Migration add_reference :france_connect_informations, :user, references: :users User.all.each do |user| - FranceConnectInformation.create({gender: user.gender, - given_name: user.given_name, - family_name: user.family_name, - birthdate: user.birthdate, - birthplace: user.birthplace, - france_connect_particulier_id: user.france_connect_particulier_id, - user_id: user.id}) if user.france_connect_particulier_id.present? + FranceConnectInformation.create({ + gender: user.gender, + given_name: user.given_name, + family_name: user.family_name, + birthdate: user.birthdate, + birthplace: user.birthplace, + france_connect_particulier_id: user.france_connect_particulier_id, + user_id: user.id + }) if user.france_connect_particulier_id.present? end remove_column :users, :gender @@ -44,12 +46,14 @@ class CreateFranceConnectInformation < ActiveRecord::Migration add_column :users, :france_connect_particulier_id, :string FranceConnectInformation.all.each do |fci| - User.find(fci.user_id).update_attributes({gender: fci.gender, - given_name: fci.given_name, - family_name: fci.family_name, - birthdate: fci.birthdate, - birthplace: fci.birthplace, - france_connect_particulier_id: fci.france_connect_particulier_id}) + User.find(fci.user_id).update_attributes({ + gender: fci.gender, + given_name: fci.given_name, + family_name: fci.family_name, + birthdate: fci.birthdate, + birthplace: fci.birthplace, + france_connect_particulier_id: fci.france_connect_particulier_id + }) end drop_table :france_connect_informations diff --git a/spec/controllers/admin/attestation_templates_controller_spec.rb b/spec/controllers/admin/attestation_templates_controller_spec.rb index 046b58920..6da56b933 100644 --- a/spec/controllers/admin/attestation_templates_controller_spec.rb +++ b/spec/controllers/admin/attestation_templates_controller_spec.rb @@ -19,8 +19,10 @@ describe Admin::AttestationTemplatesController, type: :controller do before do post :preview, - params: { procedure_id: procedure.id, - attestation_template: upload_params } + params: { + procedure_id: procedure.id, + attestation_template: upload_params + } end context 'with an interlaced png' do @@ -73,8 +75,10 @@ describe Admin::AttestationTemplatesController, type: :controller do context 'nominal' do before do post :create, - params: { procedure_id: procedure.id, - attestation_template: attestation_params.merge(logo: logo, signature: signature) } + params: { + procedure_id: procedure.id, + attestation_template: attestation_params.merge(logo: logo, signature: signature) + } procedure.reload end @@ -96,8 +100,10 @@ describe Admin::AttestationTemplatesController, type: :controller do .and_return(double(full_messages: ['nop'])) post :create, - params: { procedure_id: procedure.id, - attestation_template: attestation_params } + params: { + procedure_id: procedure.id, + attestation_template: attestation_params + } procedure.reload end @@ -113,8 +119,10 @@ describe Admin::AttestationTemplatesController, type: :controller do context 'nominal' do before do patch :update, - params: { procedure_id: procedure.id, - attestation_template: attestation_params_with_images } + params: { + procedure_id: procedure.id, + attestation_template: attestation_params_with_images + } procedure.reload end @@ -134,8 +142,10 @@ describe Admin::AttestationTemplatesController, type: :controller do .and_return(double(full_messages: ['nop'])) patch :update, - params: { procedure_id: procedure.id, - attestation_template: attestation_params_with_images } + params: { + procedure_id: procedure.id, + attestation_template: attestation_params_with_images + } procedure.reload end diff --git a/spec/controllers/admin/mail_templates_controller_spec.rb b/spec/controllers/admin/mail_templates_controller_spec.rb index faffe624d..313dd93ad 100644 --- a/spec/controllers/admin/mail_templates_controller_spec.rb +++ b/spec/controllers/admin/mail_templates_controller_spec.rb @@ -24,10 +24,11 @@ describe Admin::MailTemplatesController, type: :controller do before :each do patch :update, - params: { procedure_id: procedure.id, - id: initiated_mail.class.const_get(:SLUG), - mail_template: { subject: mail_subject, body: mail_body } - } + params: { + procedure_id: procedure.id, + id: initiated_mail.class.const_get(:SLUG), + mail_template: { subject: mail_subject, body: mail_body } + } end it { expect(response).to redirect_to admin_procedure_mail_templates_path(procedure) } diff --git a/spec/controllers/admin/types_de_champ_controller_spec.rb b/spec/controllers/admin/types_de_champ_controller_spec.rb index 270d125f9..3b68c6de6 100644 --- a/spec/controllers/admin/types_de_champ_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_controller_spec.rb @@ -41,27 +41,26 @@ describe Admin::TypesDeChampController, type: :controller do let(:mandatory) { 'on' } let(:procedure_params) do - {types_de_champ_attributes: - {'0' => - { - libelle: libelle, - type_champ: type_champ, - description: description, - order_place: order_place, - id: types_de_champ_id, - mandatory: mandatory - }, - '1' => - { - libelle: '', - type_champ: 'text', - description: '', - order_place: '1', - id: '', - mandatory: false, - type: 'TypeDeChampPublic' - } - } + { + types_de_champ_attributes: { + '0' => { + libelle: libelle, + type_champ: type_champ, + description: description, + order_place: order_place, + id: types_de_champ_id, + mandatory: mandatory + }, + '1' => { + libelle: '', + type_champ: 'text', + description: '', + order_place: '1', + id: '', + mandatory: false, + type: 'TypeDeChampPublic' + } + } } end diff --git a/spec/controllers/admin/types_de_champ_private_controller_spec.rb b/spec/controllers/admin/types_de_champ_private_controller_spec.rb index 1dbb9c0b4..701bb2c91 100644 --- a/spec/controllers/admin/types_de_champ_private_controller_spec.rb +++ b/spec/controllers/admin/types_de_champ_private_controller_spec.rb @@ -41,28 +41,27 @@ describe Admin::TypesDeChampPrivateController, type: :controller do let(:mandatory) { 'on' } let(:procedure_params) do - {types_de_champ_private_attributes: - {'0' => - { - libelle: libelle, - type_champ: type_champ, - description: description, - order_place: order_place, - id: types_de_champ_id, - mandatory: mandatory, - type: 'TypeDeChampPrivate' - }, - '1' => - { - libelle: '', - type_champ: 'text', - description: '', - order_place: '1', - id: '', - mandatory: false, - type: 'TypeDeChampPrivate' - } - } + { + types_de_champ_private_attributes: { + '0' => { + libelle: libelle, + type_champ: type_champ, + description: description, + order_place: order_place, + id: types_de_champ_id, + mandatory: mandatory, + type: 'TypeDeChampPrivate' + }, + '1' => { + libelle: '', + type_champ: 'text', + description: '', + order_place: '1', + id: '', + mandatory: false, + type: 'TypeDeChampPrivate' + } + } } end diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb index 5c63450d2..094d384ba 100644 --- a/spec/controllers/new_gestionnaire/avis_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -220,11 +220,13 @@ describe NewGestionnaire::AvisController, type: :controller do .with(avis_id.to_s, invited_email) .and_return(invitations_email) - post :create_gestionnaire, params: { id: avis_id, - email: invited_email, - gestionnaire: { - password: password - } } + post :create_gestionnaire, params: { + id: avis_id, + email: invited_email, + gestionnaire: { + password: password + } + } end context 'when the email does not belong to the invitation' do diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 2bb35d7a4..4249ecfaa 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -230,10 +230,12 @@ describe NewGestionnaire::DossiersController, type: :controller do let(:procedure) { create(:procedure, :published, attestation_template: template, gestionnaires: [gestionnaire]) } subject do - post :terminer, params: { process_action: "accepter", - procedure_id: procedure.id, - dossier_id: dossier.id, - dossier: { motivation: "Yallah" }} + post :terminer, params: { + process_action: "accepter", + procedure_id: procedure.id, + dossier_id: dossier.id, + dossier: { motivation: "Yallah" } + } end before do diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index 785b0e27d..6993e7d47 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -300,9 +300,11 @@ shared_examples 'description_controller_spec' do context 'Sauvegarde des pièces justificatives', vcr: { cassette_name: 'controllers_users_description_controller_sauvegarde_pj' } do let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } before do - post :update, params: { dossier_id: dossier_id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 } + post :update, params: { + dossier_id: dossier_id, + 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, + 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + } dossier.reload end @@ -310,9 +312,11 @@ shared_examples 'description_controller_spec' do it 'ClamavService safe_file? is call' do expect(ClamavService).to receive(:safe_file?).twice - post :update, params: { dossier_id: dossier_id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 } + post :update, params: { + dossier_id: dossier_id, + 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, + 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + } end end @@ -348,9 +352,12 @@ shared_examples 'description_controller_spec' do describe 'POST #pieces_justificatives', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } - subject { patch :pieces_justificatives, params: { dossier_id: dossier.id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 } + subject { + patch :pieces_justificatives, params: { + dossier_id: dossier.id, + 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, + 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + } } context 'when user is a guest' do @@ -424,9 +431,12 @@ end shared_examples 'description_controller_spec_POST_piece_justificatives_for_owner' do let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } - subject { patch :pieces_justificatives, params: { dossier_id: dossier.id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 } + subject { + patch :pieces_justificatives, params: { + dossier_id: dossier.id, + 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, + 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + } } context 'when user is the owner', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do From 5125cf839694b695fa6224e99ab30f91ea966ffa Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 18:48:14 +0100 Subject: [PATCH 20/45] Enable the Layout/FirstParameterIndentation cop --- .rubocop.yml | 2 +- .../admin/gestionnaires_controller.rb | 8 +++++--- app/controllers/admin/procedures_controller.rb | 11 ++++++----- .../new_gestionnaire/recherche_controller.rb | 6 +++--- app/controllers/root_controller.rb | 8 ++++---- app/services/module_api_carto_service.rb | 4 ++-- app/services/sync_credentials_service.rb | 12 ++++++------ ...12_build_default_preference_list_dossier.rb | 16 ++++++++-------- ...095443_reset_all_preference_list_dossier.rb | 18 +++++++++--------- lib/tasks/cloud_storage.rake | 18 +++++++++--------- 10 files changed, 53 insertions(+), 50 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7653b091c..c7d98218a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -95,7 +95,7 @@ Layout/FirstMethodParameterLineBreak: Enabled: false Layout/FirstParameterIndentation: - Enabled: false + Enabled: true Layout/IndentArray: Enabled: false diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb index 1e4ebabe4..6319e2569 100644 --- a/app/controllers/admin/gestionnaires_controller.rb +++ b/app/controllers/admin/gestionnaires_controller.rb @@ -40,9 +40,11 @@ class Admin::GestionnairesController < AdminController attributes = params.require(:gestionnaire).permit(:email) .merge(password: SecureRandom.hex(5)) - @gestionnaire = Gestionnaire.create(attributes.merge( - administrateurs: [current_administrateur] - )) + @gestionnaire = Gestionnaire.create( + attributes.merge( + administrateurs: [current_administrateur] + ) + ) if @gestionnaire.errors.messages.empty? User.create(attributes) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 80904fcfb..d38758eec 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -96,11 +96,12 @@ class Admin::ProceduresController < AdminController procedure = current_administrateur.procedures.find(params[:procedure_id]) new_procedure_path = ProcedurePath.new( - { - path: params[:procedure_path], - procedure: procedure, - administrateur: procedure.administrateur - }) + { + path: params[:procedure_path], + procedure: procedure, + administrateur: procedure.administrateur + }) + if new_procedure_path.validate new_procedure_path.delete else diff --git a/app/controllers/new_gestionnaire/recherche_controller.rb b/app/controllers/new_gestionnaire/recherche_controller.rb index 4d4ce7798..243e0d55b 100644 --- a/app/controllers/new_gestionnaire/recherche_controller.rb +++ b/app/controllers/new_gestionnaire/recherche_controller.rb @@ -13,9 +13,9 @@ module NewGestionnaire # full text search if @dossiers.empty? @dossiers = Search.new( - gestionnaire: current_gestionnaire, - query: @search_terms, - page: params[:page] + gestionnaire: current_gestionnaire, + query: @search_terms, + page: params[:page] ).results end end diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 51ff9066f..7137999c5 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -35,10 +35,10 @@ class RootController < ApplicationController .each do |champ| champ.type_de_champ.drop_down_list = DropDownList.new(type_de_champ: champ.type_de_champ) champ.drop_down_list.value = -"option A -option B --- avant l'option C -- -option C" + "option A + option B + -- avant l'option C -- + option C" champ.value = '["option B", "option C"]' end diff --git a/app/services/module_api_carto_service.rb b/app/services/module_api_carto_service.rb index 2cff27de4..252ad1c2e 100644 --- a/app/services/module_api_carto_service.rb +++ b/app/services/module_api_carto_service.rb @@ -26,14 +26,14 @@ class ModuleApiCartoService def self.generate_qp coordinates coordinates.inject({}) { |acc, coordinate| acc.merge CARTO::SGMAP::QuartiersPrioritaires::Adapter.new( - coordinate.map { |element| [element['lng'], element['lat']] }).to_params + coordinate.map { |element| [element['lng'], element['lat']] }).to_params } end def self.generate_cadastre coordinates (coordinates.inject([]) { |acc, coordinate| acc << CARTO::SGMAP::Cadastre::Adapter.new( - coordinate.map { |element| [element['lng'], element['lat']] }).to_params + coordinate.map { |element| [element['lng'], element['lat']] }).to_params }).flatten end end diff --git a/app/services/sync_credentials_service.rb b/app/services/sync_credentials_service.rb index 43c556c98..983f6a1bd 100644 --- a/app/services/sync_credentials_service.rb +++ b/app/services/sync_credentials_service.rb @@ -11,8 +11,8 @@ class SyncCredentialsService user = User.find_by(email: @email_was) if user return false if !user.update_columns( - email: @email, - encrypted_password: @encrypted_password) + email: @email, + encrypted_password: @encrypted_password) end end @@ -20,8 +20,8 @@ class SyncCredentialsService gestionnaire = Gestionnaire.find_by(email: @email_was) if gestionnaire return false if !gestionnaire.update_columns( - email: @email, - encrypted_password: @encrypted_password) + email: @email, + encrypted_password: @encrypted_password) end end @@ -29,8 +29,8 @@ class SyncCredentialsService administrateur = Administrateur.find_by(email: @email_was) if administrateur return false if !administrateur.update_columns( - email: @email, - encrypted_password: @encrypted_password) + email: @email, + encrypted_password: @encrypted_password) end end diff --git a/db/migrate/20160802113112_build_default_preference_list_dossier.rb b/db/migrate/20160802113112_build_default_preference_list_dossier.rb index 66d344fe8..4f73c4263 100644 --- a/db/migrate/20160802113112_build_default_preference_list_dossier.rb +++ b/db/migrate/20160802113112_build_default_preference_list_dossier.rb @@ -5,14 +5,14 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration table.second.each do |column| if valid_couple_table_attr? table.first, column.first PreferenceListDossier.create( - libelle: column.second[:libelle], - table: column.second[:table], - attr: column.second[:attr], - attr_decorate: column.second[:attr_decorate], - bootstrap_lg: column.second[:bootstrap_lg], - order: nil, - filter: nil, - gestionnaire_id: self.id + libelle: column.second[:libelle], + table: column.second[:table], + attr: column.second[:attr], + attr_decorate: column.second[:attr_decorate], + bootstrap_lg: column.second[:bootstrap_lg], + order: nil, + filter: nil, + gestionnaire_id: self.id ) end end diff --git a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb index 172ee1fbb..629822722 100644 --- a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb +++ b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb @@ -100,15 +100,15 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration table.second.each do |column| if valid_couple_table_attr? table.first, column.first PreferenceListDossier.create( - libelle: column.second[:libelle], - table: column.second[:table], - attr: column.second[:attr], - attr_decorate: column.second[:attr_decorate], - bootstrap_lg: column.second[:bootstrap_lg], - order: nil, - filter: nil, - procedure_id: procedure_id, - gestionnaire: self + libelle: column.second[:libelle], + table: column.second[:table], + attr: column.second[:attr], + attr_decorate: column.second[:attr_decorate], + bootstrap_lg: column.second[:bootstrap_lg], + order: nil, + filter: nil, + procedure_id: procedure_id, + gestionnaire: self ) end end diff --git a/lib/tasks/cloud_storage.rake b/lib/tasks/cloud_storage.rake index 878d3acce..f4cfb11cf 100644 --- a/lib/tasks/cloud_storage.rake +++ b/lib/tasks/cloud_storage.rake @@ -2,15 +2,15 @@ namespace :cloudstorage do task init: :environment do os_config = (YAML.load_file(Fog.credentials_path))['default'] @os = OpenStack::Connection.create( - { - username: os_config['openstack_username'], - api_key: os_config['openstack_api_key'], - auth_method: "password", - auth_url: "https://auth.cloud.ovh.net/v2.0/", - authtenant_name: os_config['openstack_tenant'], - service_type: "object-store", - region: os_config['openstack_region'] - } + { + username: os_config['openstack_username'], + api_key: os_config['openstack_api_key'], + auth_method: "password", + auth_url: "https://auth.cloud.ovh.net/v2.0/", + authtenant_name: os_config['openstack_tenant'], + service_type: "object-store", + region: os_config['openstack_region'] + } ) @cont = @os.container(CarrierWave::Uploader::Base.fog_directory) end From 9e0e553f8013a14d087fe90926a5ac3374dfd92e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 18:54:57 +0100 Subject: [PATCH 21/45] Enable the Layout/IndentArray cop --- .rubocop.yml | 3 +- app/models/gestionnaire.rb | 2 +- app/services/geojson_service.rb | 24 +++++----- config/deploy.rb | 48 +++++++++---------- ...2_build_default_preference_list_dossier.rb | 42 ++++++++-------- ...95443_reset_all_preference_list_dossier.rb | 42 ++++++++-------- .../api/v1/dossiers_controller_spec.rb | 42 ++++++++-------- spec/controllers/stats_controller_spec.rb | 18 +++---- spec/lib/carto/sgmap/cadastre/adapter_spec.rb | 26 +++++----- spec/services/geojson_service_spec.rb | 10 ++-- 10 files changed, 129 insertions(+), 128 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c7d98218a..29cf584a4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -98,7 +98,8 @@ Layout/FirstParameterIndentation: Enabled: true Layout/IndentArray: - Enabled: false + Enabled: true + EnforcedStyle: consistent Layout/IndentAssignment: Enabled: false diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index cd952b0de..b3655b169 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -217,6 +217,6 @@ class Gestionnaire < ActiveRecord::Base updated_annotations, updated_avis, updated_messagerie - ].map { |query| query.distinct.ids }.flatten.uniq + ].map { |query| query.distinct.ids }.flatten.uniq end end diff --git a/app/services/geojson_service.rb b/app/services/geojson_service.rb index 1f6562089..27a80aa4e 100644 --- a/app/services/geojson_service.rb +++ b/app/services/geojson_service.rb @@ -1,10 +1,10 @@ class GeojsonService def self.to_json_polygon_for_qp coordinates polygon = { - geo: { - type: "Polygon", - coordinates: [coordinates] - } + geo: { + type: "Polygon", + coordinates: [coordinates] + } } polygon.to_json @@ -12,15 +12,15 @@ class GeojsonService def self.to_json_polygon_for_cadastre coordinates polygon = { - geom: { - type: "Feature", - geometry: { - type: "Polygon", - coordinates: [ - coordinates - ] - } + geom: { + type: "Feature", + geometry: { + type: "Polygon", + coordinates: [ + coordinates + ] } + } } polygon.to_json diff --git a/config/deploy.rb b/config/deploy.rb index 00ae5579b..f5b8304cd 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -45,30 +45,30 @@ set :rails_env, ENV["to"] # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server. # They will be linked in the 'deploy:link_shared_paths' step. set :shared_paths, [ - 'log', - 'bin', - 'uploads', - 'tmp/pids', - 'tmp/cache', - 'tmp/sockets', - 'public/system', - 'public/uploads', - 'config/database.yml', - "config/skylight.yml", - "config/fog_credentials.yml", - 'config/initializers/secret_token.rb', - 'config/initializers/features.yml', - "config/environments/#{rails_env}.rb", - "config/initializers/token.rb", - "config/initializers/urls.rb", - "config/initializers/super_admin.rb", - "config/unicorn.rb", - "config/initializers/raven.rb", - 'config/france_connect.yml', - 'config/github_secrets.yml', - 'config/initializers/mailjet.rb', - 'config/initializers/storage_url.rb' - ] + 'log', + 'bin', + 'uploads', + 'tmp/pids', + 'tmp/cache', + 'tmp/sockets', + 'public/system', + 'public/uploads', + 'config/database.yml', + "config/skylight.yml", + "config/fog_credentials.yml", + 'config/initializers/secret_token.rb', + 'config/initializers/features.yml', + "config/environments/#{rails_env}.rb", + "config/initializers/token.rb", + "config/initializers/urls.rb", + "config/initializers/super_admin.rb", + "config/unicorn.rb", + "config/initializers/raven.rb", + 'config/france_connect.yml', + 'config/github_secrets.yml', + 'config/initializers/mailjet.rb', + 'config/initializers/storage_url.rb' +] set :rbenv_path, "/usr/local/rbenv/bin/rbenv" diff --git a/db/migrate/20160802113112_build_default_preference_list_dossier.rb b/db/migrate/20160802113112_build_default_preference_list_dossier.rb index 4f73c4263..b8b7a40e9 100644 --- a/db/migrate/20160802113112_build_default_preference_list_dossier.rb +++ b/db/migrate/20160802113112_build_default_preference_list_dossier.rb @@ -21,27 +21,27 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration def valid_couple_table_attr? table, column couples = [ - { - table: :dossier, - column: :dossier_id - }, - { - table: :procedure, - column: :libelle - }, - { - table: :etablissement, - column: :siret - }, - { - table: :entreprise, - column: :raison_sociale - }, - { - table: :dossier, - column: :state - } - ] + { + table: :dossier, + column: :dossier_id + }, + { + table: :procedure, + column: :libelle + }, + { + table: :etablissement, + column: :siret + }, + { + table: :entreprise, + column: :raison_sociale + }, + { + table: :dossier, + column: :state + } + ] couples.include?({table: table, column: column}) end diff --git a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb index 629822722..77b34cda9 100644 --- a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb +++ b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb @@ -119,27 +119,27 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration def valid_couple_table_attr? table, column couples = [ - { - table: :dossier, - column: :dossier_id - }, - { - table: :procedure, - column: :libelle - }, - { - table: :etablissement, - column: :siret - }, - { - table: :entreprise, - column: :raison_sociale - }, - { - table: :dossier, - column: :state - } - ] + { + table: :dossier, + column: :dossier_id + }, + { + table: :procedure, + column: :libelle + }, + { + table: :etablissement, + column: :siret + }, + { + table: :entreprise, + column: :raison_sociale + }, + { + table: :dossier, + column: :state + } + ] couples.include?({table: table, column: column}) end diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 8765cd6ee..fa0fe0008 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -132,7 +132,8 @@ describe API::V1::DossiersController do it { expect(subject.keys).to match_array(field_list) } describe 'entreprise' do - let(:field_list) { [ + let(:field_list) { + [ :siren, :capital_social, :numero_tva_intracommunautaire, @@ -144,7 +145,8 @@ describe API::V1::DossiersController do :code_effectif_entreprise, :date_creation, :nom, - :prenom] + :prenom + ] } subject { super()[:entreprise] } @@ -162,11 +164,7 @@ describe API::V1::DossiersController do end describe 'types_de_piece_justificative' do - let(:field_list) { [ - :id, - :libelle, - :description] - } + let(:field_list) { [:id, :libelle, :description] } subject { super()[:types_de_piece_justificative] } it { expect(subject.length).to eq 2 } @@ -185,9 +183,7 @@ describe API::V1::DossiersController do create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative: dossier.procedure.types_de_piece_justificative.first, user: dossier.user end - let(:field_list) { [ - :url, :created_at, :type_de_piece_justificative_id] - } + let(:field_list) { [:url, :created_at, :type_de_piece_justificative_id] } subject { super()[:pieces_justificatives].first } it { expect(subject.keys.include?(:content_url)).to be_truthy } @@ -204,8 +200,7 @@ describe API::V1::DossiersController do end describe 'champs' do - let(:field_list) { [ - :url] + let(:field_list) { [:url] } subject { super()[:champs] } @@ -218,12 +213,14 @@ describe API::V1::DossiersController do it { expect(subject.keys.include?(:type_de_champ)).to be_truthy } describe 'type de champ' do - let(:field_list) { [ + let(:field_list) { + [ :id, :libelle, :description, :order_place, - :type] + :type + ] } subject { super()[:type_de_champ] } @@ -277,9 +274,7 @@ describe API::V1::DossiersController do end describe 'champs_private' do - let(:field_list) { [ - :url] - } + let(:field_list) { [:url] } subject { super()[:champs_private] } it { expect(subject.length).to eq 1 } @@ -291,12 +286,14 @@ describe API::V1::DossiersController do it { expect(subject.keys.include?(:type_de_champ)).to be_truthy } describe 'type de champ' do - let(:field_list) { [ + let(:field_list) { + [ :id, :libelle, :description, :order_place, - :type] + :type + ] } subject { super()[:type_de_champ] } @@ -343,9 +340,7 @@ describe API::V1::DossiersController do end describe 'user' do - let(:field_list) { [ - :url, :created_at, :type_de_piece_justificative_id] - } + let(:field_list) { [:url, :created_at, :type_de_piece_justificative_id] } subject { super()[:user] } it { expect(subject[:email]).not_to be_nil } @@ -353,7 +348,8 @@ describe API::V1::DossiersController do end describe 'etablissement' do - let(:field_list) { [ + let(:field_list) { + [ :siret, :siege_social, :naf, diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index d8dedd133..35dfb3bcf 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -18,11 +18,12 @@ describe StatsController, type: :controller do subject { @controller.send(:last_four_months_hash, association, :updated_at) } - it { expect(subject).to match_array([ - [I18n.l(62.days.ago.beginning_of_month, format: "%B %Y"), 2], - [I18n.l(31.days.ago.beginning_of_month, format: "%B %Y"), 1] + it do + expect(subject).to match_array([ + [I18n.l(62.days.ago.beginning_of_month, format: "%B %Y"), 2], + [I18n.l(31.days.ago.beginning_of_month, format: "%B %Y"), 1] ]) - } + end end context "while a super admin is logged in" do @@ -41,11 +42,12 @@ describe StatsController, type: :controller do subject { @controller.send(:last_four_months_hash, association, :updated_at) } - it { expect(subject).to eq([ - [I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 1], - [I18n.l(1.days.ago.beginning_of_month, format: "%B %Y"), 2] + it do + expect(subject).to eq([ + [I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 1], + [I18n.l(1.days.ago.beginning_of_month, format: "%B %Y"), 2] ]) - } + end end end diff --git a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb index 3e33ae2f8..d3c7246a6 100644 --- a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb +++ b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb @@ -23,18 +23,20 @@ describe CARTO::SGMAP::Cadastre::Adapter do subject { adapter.filter_properties adapter.data_source } it { expect(subject.size).to eq 9 } - it { expect(subject.keys).to eq [ - :surface_intersection, - :surface_parcelle, - :numero, - :feuille, - :section, - :code_dep, - :nom_com, - :code_com, - :code_arr - ] - } + it do + expect(subject.keys).to eq + [ + :surface_intersection, + :surface_parcelle, + :numero, + :feuille, + :section, + :code_dep, + :nom_com, + :code_com, + :code_arr + ] + end end describe 'Attributes' do diff --git a/spec/services/geojson_service_spec.rb b/spec/services/geojson_service_spec.rb index 7837e7d72..8887d27d0 100644 --- a/spec/services/geojson_service_spec.rb +++ b/spec/services/geojson_service_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe GeojsonService do let(:good_coordinates) { [ - [5.93536376953125, 48.91888968903368], - [5.93536376953125, 49.26780455063753], - [7.094421386718749, 49.26780455063753], - [7.094421386718749, 48.91888968903368], - [5.93536376953125, 48.91888968903368] + [5.93536376953125, 48.91888968903368], + [5.93536376953125, 49.26780455063753], + [7.094421386718749, 49.26780455063753], + [7.094421386718749, 48.91888968903368], + [5.93536376953125, 48.91888968903368] ] } From 3363e2142766557ff5e28a1d5aa140e401ad7a39 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 18:56:00 +0100 Subject: [PATCH 22/45] Enable the Layout/IndentAssignment cop --- .rubocop.yml | 4 ++-- app/services/notification_service.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 29cf584a4..6b3930157 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -99,10 +99,10 @@ Layout/FirstParameterIndentation: Layout/IndentArray: Enabled: true - EnforcedStyle: consistent + EnforcedStyle: consistent Layout/IndentAssignment: - Enabled: false + Enabled: true Layout/IndentHash: Enabled: false diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 991120e95..aacbc527c 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -15,11 +15,11 @@ class NotificationService def notification @notification ||= - begin - Notification.find_by! dossier_id: @dossier_id, already_read: false, type_notif: @type_notif - rescue ActiveRecord::RecordNotFound - Notification.new dossier_id: @dossier_id, type_notif: @type_notif, liste: [] - end + begin + Notification.find_by! dossier_id: @dossier_id, already_read: false, type_notif: @type_notif + rescue ActiveRecord::RecordNotFound + Notification.new dossier_id: @dossier_id, type_notif: @type_notif, liste: [] + end end def text_for_notif attribut='' From 0be657c0d74e06ee672aba2c6a5bdc5efd003ae6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:02:12 +0100 Subject: [PATCH 23/45] Enable the Layout/IndentHash cop --- .rubocop.yml | 3 +- .../api/statistiques_controller.rb | 6 +- app/controllers/api/v1/dossiers_controller.rb | 6 +- app/controllers/users/carte_controller.rb | 4 +- .../users/description_controller.rb | 2 +- app/controllers/users/dossiers_controller.rb | 2 +- .../users/recapitulatif_controller.rb | 2 +- app/lib/carto/sgmap/cadastre/adapter.rb | 18 ++--- config/initializers/browser.rb | 4 +- config/initializers/clamav.rb | 6 +- config/routes.rb | 18 ++--- ...2_build_default_preference_list_dossier.rb | 58 ++++++++-------- ...95443_reset_all_preference_list_dossier.rb | 66 +++++++++---------- .../pieces_justificatives_controller_spec.rb | 12 ++-- .../admin/procedures_controller_spec.rb | 22 +++---- .../passwords_controller_spec.rb | 14 ++-- spec/controllers/stats_controller_spec.rb | 10 +-- .../users/passwords_controller_spec.rb | 24 ++++--- spec/decorators/entreprise_decorator_spec.rb | 11 ++-- spec/lib/file_size_validator_spec.rb | 4 +- spec/services/types_de_champ_service_spec.rb | 26 ++++---- 21 files changed, 163 insertions(+), 155 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6b3930157..32a6c8b45 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -105,7 +105,8 @@ Layout/IndentAssignment: Enabled: true Layout/IndentHash: - Enabled: false + Enabled: true + EnforcedStyle: consistent Layout/IndentHeredoc: Enabled: false diff --git a/app/controllers/api/statistiques_controller.rb b/app/controllers/api/statistiques_controller.rb index 2300337f9..d8c555040 100644 --- a/app/controllers/api/statistiques_controller.rb +++ b/app/controllers/api/statistiques_controller.rb @@ -1,9 +1,9 @@ class API::StatistiquesController < ApplicationController def dossiers_stats render json: { - total: total_dossiers, - mois: dossiers_mois - } + total: total_dossiers, + mois: dossiers_mois + } end private diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index 90a19d136..5303f2f68 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -34,9 +34,9 @@ class API::V1::DossiersController < APIController def pagination(dossiers) { - page: dossiers.current_page, - resultats_par_page: dossiers.limit_value, - nombre_de_page: dossiers.total_pages + page: dossiers.current_page, + resultats_par_page: dossiers.limit_value, + nombre_de_page: dossiers.total_pages } end diff --git a/app/controllers/users/carte_controller.rb b/app/controllers/users/carte_controller.rb index a6ec9f2b3..8c6314033 100644 --- a/app/controllers/users/carte_controller.rb +++ b/app/controllers/users/carte_controller.rb @@ -61,8 +61,8 @@ class Users::CarteController < UsersController def self.route_authorization { - states: [:brouillon, :en_construction], - api_carto: true + states: [:brouillon, :en_construction], + api_carto: true } end end diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 946d24772..e991408d7 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -95,7 +95,7 @@ class Users::DescriptionController < UsersController def self.route_authorization { - states: [:brouillon, :en_construction] + states: [:brouillon, :en_construction] } end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index e382a896e..3a95e5199 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -151,7 +151,7 @@ class Users::DossiersController < UsersController def self.route_authorization { - states: [:brouillon] + states: [:brouillon] } end diff --git a/app/controllers/users/recapitulatif_controller.rb b/app/controllers/users/recapitulatif_controller.rb index bdd1df237..b8b7fb03a 100644 --- a/app/controllers/users/recapitulatif_controller.rb +++ b/app/controllers/users/recapitulatif_controller.rb @@ -18,7 +18,7 @@ class Users::RecapitulatifController < UsersController def self.route_authorization { - states: [:en_construction, :en_instruction, :sans_suite, :accepte, :refuse] + states: [:en_construction, :en_instruction, :sans_suite, :accepte, :refuse] } end diff --git a/app/lib/carto/sgmap/cadastre/adapter.rb b/app/lib/carto/sgmap/cadastre/adapter.rb index 9e2a24d47..6c49a9af3 100644 --- a/app/lib/carto/sgmap/cadastre/adapter.rb +++ b/app/lib/carto/sgmap/cadastre/adapter.rb @@ -18,15 +18,15 @@ class CARTO::SGMAP::Cadastre::Adapter def filter_properties properties { - surface_intersection: properties[:surface_intersection], - surface_parcelle: properties[:surface_parcelle], - numero: properties[:numero], - feuille: properties[:feuille], - section: properties[:section], - code_dep: properties[:code_dep], - nom_com: properties[:nom_com], - code_com: properties[:code_com], - code_arr: properties[:code_arr] + surface_intersection: properties[:surface_intersection], + surface_parcelle: properties[:surface_parcelle], + numero: properties[:numero], + feuille: properties[:feuille], + section: properties[:section], + code_dep: properties[:code_dep], + nom_com: properties[:nom_com], + code_com: properties[:code_com], + code_arr: properties[:code_arr] } end end diff --git a/config/initializers/browser.rb b/config/initializers/browser.rb index 1c850f41e..950d9536c 100644 --- a/config/initializers/browser.rb +++ b/config/initializers/browser.rb @@ -1,3 +1,3 @@ BROWSER = Hashie::Mash.new ({ - value: nil - }) + value: nil +}) diff --git a/config/initializers/clamav.rb b/config/initializers/clamav.rb index 24122c84a..758359382 100644 --- a/config/initializers/clamav.rb +++ b/config/initializers/clamav.rb @@ -1,4 +1,4 @@ CLAMAV = Hashie::Mash.new ({ - mock?: true, - response: true - }) + mock?: true, + response: true +}) diff --git a/config/routes.rb b/config/routes.rb index 081231cb3..eedcd3e86 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,19 +18,19 @@ Rails.application.routes.draw do } devise_for :administrateurs, controllers: { - sessions: 'administrateurs/sessions' - }, skip: [:password, :registrations] + sessions: 'administrateurs/sessions' + }, skip: [:password, :registrations] devise_for :gestionnaires, controllers: { - sessions: 'gestionnaires/sessions', - passwords: 'gestionnaires/passwords' - }, skip: [:registrations] + sessions: 'gestionnaires/sessions', + passwords: 'gestionnaires/passwords' + }, skip: [:registrations] devise_for :users, controllers: { - sessions: 'users/sessions', - registrations: 'users/registrations', - passwords: 'users/passwords' - } + sessions: 'users/sessions', + registrations: 'users/registrations', + passwords: 'users/passwords' + } devise_scope :user do get '/users/sign_in/demo' => redirect("/users/sign_in") diff --git a/db/migrate/20160802113112_build_default_preference_list_dossier.rb b/db/migrate/20160802113112_build_default_preference_list_dossier.rb index b8b7a40e9..d4b211d69 100644 --- a/db/migrate/20160802113112_build_default_preference_list_dossier.rb +++ b/db/migrate/20160802113112_build_default_preference_list_dossier.rb @@ -50,11 +50,11 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration class PreferenceListDossier < ActiveRecord::Base def self.available_columns { - dossier: columns_dossier, - procedure: columns_procedure, - entreprise: columns_entreprise, - etablissement: columns_etablissement, - user: columns_user + dossier: columns_dossier, + procedure: columns_procedure, + entreprise: columns_entreprise, + etablissement: columns_etablissement, + user: columns_user } end @@ -62,10 +62,10 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration table = nil { - dossier_id: create_column('ID', table, 'id', 'id', 1), - created_at: create_column('Créé le', table, 'created_at', 'first_creation', 2), - updated_at: create_column('Mise à jour le', table, 'updated_at', 'last_update', 2), - state: create_column('Statut', table, 'state', 'display_state', 1) + dossier_id: create_column('ID', table, 'id', 'id', 1), + created_at: create_column('Créé le', table, 'created_at', 'first_creation', 2), + updated_at: create_column('Mise à jour le', table, 'updated_at', 'last_update', 2), + state: create_column('Statut', table, 'state', 'display_state', 1) } end @@ -73,9 +73,9 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration table = 'procedure' { - libelle: create_column('Libellé procédure', table, 'libelle', 'libelle', 4), - organisation: create_column('Organisation', table, 'organisation', 'organisation', 3), - direction: create_column('Direction', table, 'direction', 'direction', 3) + libelle: create_column('Libellé procédure', table, 'libelle', 'libelle', 4), + organisation: create_column('Organisation', table, 'organisation', 'organisation', 3), + direction: create_column('Direction', table, 'direction', 'direction', 3) } end @@ -83,12 +83,12 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration table = 'entreprise' { - siren: create_column('SIREN', table, 'siren', 'siren', 2), - forme_juridique: create_column('Forme juridique', table, 'forme_juridique', 'forme_juridique', 3), - nom_commercial: create_column('Nom commercial', table, 'nom_commercial', 'nom_commercial', 3), - raison_sociale: create_column('Raison sociale', table, 'raison_sociale', 'raison_sociale', 3), - siret_siege_social: create_column('SIRET siège social', table, 'siret_siege_social', 'siret_siege_social', 2), - date_creation: create_column('Date de création', table, 'date_creation', 'date_creation', 2), + siren: create_column('SIREN', table, 'siren', 'siren', 2), + forme_juridique: create_column('Forme juridique', table, 'forme_juridique', 'forme_juridique', 3), + nom_commercial: create_column('Nom commercial', table, 'nom_commercial', 'nom_commercial', 3), + raison_sociale: create_column('Raison sociale', table, 'raison_sociale', 'raison_sociale', 3), + siret_siege_social: create_column('SIRET siège social', table, 'siret_siege_social', 'siret_siege_social', 2), + date_creation: create_column('Date de création', table, 'date_creation', 'date_creation', 2), } end @@ -96,9 +96,9 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration table = 'etablissement' { - siret: create_column('SIRET', table, 'siret', 'siret', 2), - libelle: create_column('Nom établissement', table, 'libelle_naf', 'libelle_naf', 3), - code_postal: create_column('Code postal', table, 'code_postal', 'code_postal', 1) + siret: create_column('SIRET', table, 'siret', 'siret', 2), + libelle: create_column('Nom établissement', table, 'libelle_naf', 'libelle_naf', 3), + code_postal: create_column('Code postal', table, 'code_postal', 'code_postal', 1) } end @@ -106,19 +106,19 @@ class BuildDefaultPreferenceListDossier < ActiveRecord::Migration table = 'user' { - email: create_column('Email', table, 'email', 'email', 2) + email: create_column('Email', table, 'email', 'email', 2) } end def self.create_column libelle, table, attr, attr_decorate, bootstrap_lg { - libelle: libelle, - table: table, - attr: attr, - attr_decorate: attr_decorate, - bootstrap_lg: bootstrap_lg, - order: nil, - filter: nil + libelle: libelle, + table: table, + attr: attr, + attr_decorate: attr_decorate, + bootstrap_lg: bootstrap_lg, + order: nil, + filter: nil } end end diff --git a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb index 77b34cda9..9aab6967c 100644 --- a/db/migrate/20161007095443_reset_all_preference_list_dossier.rb +++ b/db/migrate/20161007095443_reset_all_preference_list_dossier.rb @@ -5,12 +5,12 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration def self.available_columns_for procedure_id = nil columns = { - dossier: columns_dossier, - procedure: columns_procedure, - entreprise: columns_entreprise, - etablissement: columns_etablissement, - user: columns_user, - france_connect: columns_france_connect + dossier: columns_dossier, + procedure: columns_procedure, + entreprise: columns_entreprise, + etablissement: columns_etablissement, + user: columns_user, + france_connect: columns_france_connect } columns end @@ -21,10 +21,10 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration table = nil { - dossier_id: create_column('ID', table, 'id', 'id', 1), - created_at: create_column('Créé le', table, 'created_at', 'first_creation', 2), - updated_at: create_column('Mise à jour le', table, 'updated_at', 'last_update', 2), - state: create_column('Statut', table, 'state', 'display_state', 1) + dossier_id: create_column('ID', table, 'id', 'id', 1), + created_at: create_column('Créé le', table, 'created_at', 'first_creation', 2), + updated_at: create_column('Mise à jour le', table, 'updated_at', 'last_update', 2), + state: create_column('Statut', table, 'state', 'display_state', 1) } end @@ -32,9 +32,9 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration table = 'procedure' { - libelle: create_column('Libellé procédure', table, 'libelle', 'libelle', 4), - organisation: create_column('Organisation', table, 'organisation', 'organisation', 3), - direction: create_column('Direction', table, 'direction', 'direction', 3) + libelle: create_column('Libellé procédure', table, 'libelle', 'libelle', 4), + organisation: create_column('Organisation', table, 'organisation', 'organisation', 3), + direction: create_column('Direction', table, 'direction', 'direction', 3) } end @@ -42,12 +42,12 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration table = 'entreprise' { - siren: create_column('SIREN', table, 'siren', 'siren', 2), - forme_juridique: create_column('Forme juridique', table, 'forme_juridique', 'forme_juridique', 3), - nom_commercial: create_column('Nom commercial', table, 'nom_commercial', 'nom_commercial', 3), - raison_sociale: create_column('Raison sociale', table, 'raison_sociale', 'raison_sociale', 3), - siret_siege_social: create_column('SIRET siège social', table, 'siret_siege_social', 'siret_siege_social', 2), - date_creation: create_column('Date de création', table, 'date_creation', 'date_creation', 2), + siren: create_column('SIREN', table, 'siren', 'siren', 2), + forme_juridique: create_column('Forme juridique', table, 'forme_juridique', 'forme_juridique', 3), + nom_commercial: create_column('Nom commercial', table, 'nom_commercial', 'nom_commercial', 3), + raison_sociale: create_column('Raison sociale', table, 'raison_sociale', 'raison_sociale', 3), + siret_siege_social: create_column('SIRET siège social', table, 'siret_siege_social', 'siret_siege_social', 2), + date_creation: create_column('Date de création', table, 'date_creation', 'date_creation', 2), } end @@ -55,16 +55,16 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration table = 'etablissement' { - siret: create_column('SIRET', table, 'siret', 'siret', 2), - libelle: create_column('Nom établissement', table, 'libelle_naf', 'libelle_naf', 3), - code_postal: create_column('Code postal', table, 'code_postal', 'code_postal', 1) + siret: create_column('SIRET', table, 'siret', 'siret', 2), + libelle: create_column('Nom établissement', table, 'libelle_naf', 'libelle_naf', 3), + code_postal: create_column('Code postal', table, 'code_postal', 'code_postal', 1) } end def self.columns_user table = 'user' { - email: create_column('Email', table, 'email', 'email', 2) + email: create_column('Email', table, 'email', 'email', 2) } end @@ -72,21 +72,21 @@ class ResetAllPreferenceListDossier < ActiveRecord::Migration table = 'france_connect_information' { - gender: create_column('Civilité (FC)', table, 'gender', 'gender_fr', 1), - given_name: create_column('Prénom (FC)', table, 'given_name', 'given_name', 2), - family_name: create_column('Nom (FC)', table, 'family_name', 'family_name', 2) + gender: create_column('Civilité (FC)', table, 'gender', 'gender_fr', 1), + given_name: create_column('Prénom (FC)', table, 'given_name', 'given_name', 2), + family_name: create_column('Nom (FC)', table, 'family_name', 'family_name', 2) } end def self.create_column libelle, table, attr, attr_decorate, bootstrap_lg { - libelle: libelle, - table: table, - attr: attr, - attr_decorate: attr_decorate, - bootstrap_lg: bootstrap_lg, - order: nil, - filter: nil + libelle: libelle, + table: table, + attr: attr, + attr_decorate: attr_decorate, + bootstrap_lg: bootstrap_lg, + order: nil, + filter: nil } end end diff --git a/spec/controllers/admin/pieces_justificatives_controller_spec.rb b/spec/controllers/admin/pieces_justificatives_controller_spec.rb index 22244c080..c1e66c366 100644 --- a/spec/controllers/admin/pieces_justificatives_controller_spec.rb +++ b/spec/controllers/admin/pieces_justificatives_controller_spec.rb @@ -36,14 +36,14 @@ describe Admin::PiecesJustificativesController, type: :controller do let(:description) { "relevé d'identité bancaire" } let(:update_params) do { - types_de_piece_justificative_attributes: + types_de_piece_justificative_attributes: + { + '0' => { - '0' => - { - libelle: libelle, - description: description - } + libelle: libelle, + description: description } + } } end diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 073f84b0f..cf1acb3e4 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -18,17 +18,17 @@ describe Admin::ProceduresController, type: :controller do let(:procedure_params) { { - libelle: libelle, - description: description, - organisation: organisation, - direction: direction, - lien_demarche: lien_demarche, - cerfa_flag: cerfa_flag, - module_api_carto_attributes: { - use_api_carto: use_api_carto, - quartiers_prioritaires: quartiers_prioritaires, - cadastre: cadastre - } + libelle: libelle, + description: description, + organisation: organisation, + direction: direction, + lien_demarche: lien_demarche, + cerfa_flag: cerfa_flag, + module_api_carto_attributes: { + use_api_carto: use_api_carto, + quartiers_prioritaires: quartiers_prioritaires, + cadastre: cadastre + } } } diff --git a/spec/controllers/gestionnaires/passwords_controller_spec.rb b/spec/controllers/gestionnaires/passwords_controller_spec.rb index 257109531..a073e1e86 100644 --- a/spec/controllers/gestionnaires/passwords_controller_spec.rb +++ b/spec/controllers/gestionnaires/passwords_controller_spec.rb @@ -21,18 +21,20 @@ describe Gestionnaires::PasswordsController, type: :controller do put :update, params: {gestionnaire: { reset_password_token: @token, password: "supersecret", - password_confirmation: "supersecret", + password_confirmation: "supersecret" }} expect(subject.current_gestionnaire).to eq(gestionnaire) expect(subject.current_user).to eq(user) end it "also signs administrateur in" do - put :update, params: {gestionnaire: { - reset_password_token: @token, - password: "supersecret", - password_confirmation: "supersecret", - }} + put :update, params: { + gestionnaire: { + reset_password_token: @token, + password: "supersecret", + password_confirmation: "supersecret" + } + } expect(subject.current_administrateur).to eq(administrateur) expect(subject.current_user).to eq(user) end diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 35dfb3bcf..74e912e49 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -70,12 +70,13 @@ describe StatsController, type: :controller do subject { @controller.send(:cumulative_hash, association, :updated_at) } - it { expect(subject).to eq({ + it do + expect(subject).to eq({ 2.month.ago.beginning_of_month => 2, 1.month.ago.beginning_of_month => 4, 1.hour.ago.beginning_of_month => 5 }) - } + end end context "while a super admin is not logged in" do @@ -83,11 +84,12 @@ describe StatsController, type: :controller do subject { @controller.send(:cumulative_hash, association, :updated_at) } - it { expect(subject).to eq({ + it do + expect(subject).to eq({ 2.month.ago.beginning_of_month => 2, 1.month.ago.beginning_of_month => 4 }) - } + end end end diff --git a/spec/controllers/users/passwords_controller_spec.rb b/spec/controllers/users/passwords_controller_spec.rb index 37a8f18e6..cd9a76ff0 100644 --- a/spec/controllers/users/passwords_controller_spec.rb +++ b/spec/controllers/users/passwords_controller_spec.rb @@ -18,21 +18,25 @@ describe Users::PasswordsController, type: :controller do end it "also signs gestionnaire in" do - put :update, params: {user: { - reset_password_token: @token, - password: "supersecret", - password_confirmation: "supersecret", - }} + put :update, params: { + user: { + reset_password_token: @token, + password: "supersecret", + password_confirmation: "supersecret", + } + } expect(subject.current_user).to eq(user) expect(subject.current_gestionnaire).to eq(gestionnaire) end it "also signs administrateur in" do - put :update, params: {user: { - reset_password_token: @token, - password: "supersecret", - password_confirmation: "supersecret", - }} + put :update, params: { + user: { + reset_password_token: @token, + password: "supersecret", + password_confirmation: "supersecret", + } + } expect(subject.current_user).to eq(user) expect(subject.current_administrateur).to eq(administrateur) end diff --git a/spec/decorators/entreprise_decorator_spec.rb b/spec/decorators/entreprise_decorator_spec.rb index e5f229486..829dbc762 100644 --- a/spec/decorators/entreprise_decorator_spec.rb +++ b/spec/decorators/entreprise_decorator_spec.rb @@ -7,12 +7,11 @@ describe EntrepriseDecorator do let(:prenom) { 'mon prenom' } let(:entreprise_params) do { - capital_social: 123_000, - code_effectif_entreprise: code_effectif, - raison_sociale: raison_sociale, - nom: nom, - prenom: prenom - + capital_social: 123_000, + code_effectif_entreprise: code_effectif, + raison_sociale: raison_sociale, + nom: nom, + prenom: prenom } end let(:entreprise) { create(:entreprise, entreprise_params) } diff --git a/spec/lib/file_size_validator_spec.rb b/spec/lib/file_size_validator_spec.rb index 081b107ff..78d5461bb 100644 --- a/spec/lib/file_size_validator_spec.rb +++ b/spec/lib/file_size_validator_spec.rb @@ -24,8 +24,8 @@ describe FileSizeValidator, lib: true do describe 'options uses a symbol' do let(:options) do { - maximum: :test, - attributes: { content: attachment } + maximum: :test, + attributes: { content: attachment } } end diff --git a/spec/services/types_de_champ_service_spec.rb b/spec/services/types_de_champ_service_spec.rb index 5ffdc8b88..dbe847cc0 100644 --- a/spec/services/types_de_champ_service_spec.rb +++ b/spec/services/types_de_champ_service_spec.rb @@ -48,10 +48,10 @@ describe TypesDeChampService do it do is_expected.to match({ - '0' => { 'libelle' => 'a', 'order_place' => '0' }, - '1' => { 'libelle' => 'c', 'order_place' => '1' }, - '2' => { 'libelle' => 'b', 'order_place' => '2' } - }) + '0' => { 'libelle' => 'a', 'order_place' => '0' }, + '1' => { 'libelle' => 'c', 'order_place' => '1' }, + '2' => { 'libelle' => 'b', 'order_place' => '2' } + }) end end @@ -66,10 +66,10 @@ describe TypesDeChampService do it do is_expected.to match({ - '0' => { 'libelle' => 'b', 'order_place' => '0' }, - '1' => { 'libelle' => 'a', 'order_place' => '1' }, - '2' => { 'libelle' => 'c', 'order_place' => '2' } - }) + '0' => { 'libelle' => 'b', 'order_place' => '0' }, + '1' => { 'libelle' => 'a', 'order_place' => '1' }, + '2' => { 'libelle' => 'c', 'order_place' => '2' } + }) end end @@ -85,11 +85,11 @@ describe TypesDeChampService do it 'does not change the natural order' do is_expected.to match({ - '0' => { 'libelle' => 'a', 'order_place' => '0' }, - '1' => { 'libelle' => 'b', 'order_place' => '1' }, - '2' => { 'libelle' => 'c', 'order_place' => '2' }, - '3' => { 'libelle' => 'd', 'order_place' => '3' } - }) + '0' => { 'libelle' => 'a', 'order_place' => '0' }, + '1' => { 'libelle' => 'b', 'order_place' => '1' }, + '2' => { 'libelle' => 'c', 'order_place' => '2' }, + '3' => { 'libelle' => 'd', 'order_place' => '3' } + }) end end end From 99a49a8144d127e41390e13f6677ef2f206b7cfd Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:09:08 +0100 Subject: [PATCH 24/45] Enable the Layout/IndentHeredoc cop --- .rubocop.yml | 2 +- config/initializers/apipie.rb | 4 ++-- lib/tasks/dev.rake | 43 ++++++++++++++++------------------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 32a6c8b45..146ebb5d8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -109,7 +109,7 @@ Layout/IndentHash: EnforcedStyle: consistent Layout/IndentHeredoc: - Enabled: false + Enabled: true Layout/IndentationConsistency: Enabled: false diff --git a/config/initializers/apipie.rb b/config/initializers/apipie.rb index 383abc409..362020851 100644 --- a/config/initializers/apipie.rb +++ b/config/initializers/apipie.rb @@ -10,8 +10,8 @@ Apipie.configure do |config| config.namespaced_resources = true config.show_all_examples = true - config.app_info = <<-EOS -Description + config.app_info = <<~EOS + Description EOS end diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 8e8d48257..b363774b1 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -14,40 +14,37 @@ namespace :dev do puts 'creating token.rb file' res = `rake secret`.delete("\n") file = File.new('config/initializers/token.rb', 'w+') - comment = < Date: Mon, 15 Jan 2018 19:12:15 +0100 Subject: [PATCH 25/45] Enable the Layout/IndentationConsistency cop --- .rubocop.yml | 2 +- app/controllers/stats_controller.rb | 2 +- .../concerns/credentials_syncable_concern.rb | 22 +++++++++--------- app/uploaders/piece_justificative_uploader.rb | 2 +- ...5102943_remove_duplicate_email_received.rb | 12 +++++----- spec/lib/carto/sgmap/cadastre/adapter_spec.rb | 23 +++++++++---------- .../concern/tags_substitution_concern_spec.rb | 6 ++--- spec/models/gestionnaire_spec.rb | 15 +++++++----- 8 files changed, 43 insertions(+), 41 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 146ebb5d8..1b3601fa4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -112,7 +112,7 @@ Layout/IndentHeredoc: Enabled: true Layout/IndentationConsistency: - Enabled: false + Enabled: true Layout/IndentationWidth: Enabled: true diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index b62d12505..342dcd762 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -47,7 +47,7 @@ class StatsController < ApplicationController def last_four_months_hash(association, date_attribute) min_date = 3.months.ago.beginning_of_month.to_date - association + association .where(date_attribute => min_date..max_date) .group("DATE_TRUNC('month', #{date_attribute.to_s})") .count diff --git a/app/models/concerns/credentials_syncable_concern.rb b/app/models/concerns/credentials_syncable_concern.rb index 64515b393..bddaf5209 100644 --- a/app/models/concerns/credentials_syncable_concern.rb +++ b/app/models/concerns/credentials_syncable_concern.rb @@ -1,18 +1,18 @@ module CredentialsSyncableConcern extend ActiveSupport::Concern - included do - after_update :sync_credentials - end + included do + after_update :sync_credentials + end - def sync_credentials - if email_changed? || encrypted_password_changed? - return force_sync_credentials - end - true + def sync_credentials + if email_changed? || encrypted_password_changed? + return force_sync_credentials end + true + end - def force_sync_credentials - SyncCredentialsService.new(self.class, email_was, email, encrypted_password).change_credentials! - end + def force_sync_credentials + SyncCredentialsService.new(self.class, email_was, email, encrypted_password).change_credentials! + end end diff --git a/app/uploaders/piece_justificative_uploader.rb b/app/uploaders/piece_justificative_uploader.rb index dddab178c..22e44268f 100644 --- a/app/uploaders/piece_justificative_uploader.rb +++ b/app/uploaders/piece_justificative_uploader.rb @@ -26,7 +26,7 @@ class PieceJustificativeUploader < BaseUploader if original_filename.present? || model.content_secure_token if Features.remote_storage filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension.downcase}" - else original_filename + else filename = "#{model.class.to_s.underscore}.#{file.extension.downcase}" end end diff --git a/db/migrate/20170215102943_remove_duplicate_email_received.rb b/db/migrate/20170215102943_remove_duplicate_email_received.rb index 907762e04..e69945626 100644 --- a/db/migrate/20170215102943_remove_duplicate_email_received.rb +++ b/db/migrate/20170215102943_remove_duplicate_email_received.rb @@ -1,11 +1,11 @@ class RemoveDuplicateEmailReceived < ActiveRecord::Migration[5.0] def change all_mails = MailReceived.all - groupped = all_mails.group_by { |m| m.procedure_id } - filtered = groupped.reject { |k, v| v.length < 2 } - filtered.each do |k, duplicate_mails| - duplicate_mails.pop - duplicate_mails.each(&:destroy) - end + groupped = all_mails.group_by { |m| m.procedure_id } + filtered = groupped.reject { |k, v| v.length < 2 } + filtered.each do |k, duplicate_mails| + duplicate_mails.pop + duplicate_mails.each(&:destroy) + end end end diff --git a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb index d3c7246a6..0e311f5d8 100644 --- a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb +++ b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb @@ -24,18 +24,17 @@ describe CARTO::SGMAP::Cadastre::Adapter do it { expect(subject.size).to eq 9 } it do - expect(subject.keys).to eq - [ - :surface_intersection, - :surface_parcelle, - :numero, - :feuille, - :section, - :code_dep, - :nom_com, - :code_com, - :code_arr - ] + expect(subject.keys).to eq [ + :surface_intersection, + :surface_parcelle, + :numero, + :feuille, + :section, + :code_dep, + :nom_com, + :code_com, + :code_arr + ] end end diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 7d6acfa62..911fa29de 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -182,19 +182,19 @@ describe TagsSubstitutionConcern, type: :model do context "with date de dépôt" do let(:template) { '--date de dépôt--' } - it { is_expected.to eq('03/02/2001') } + it { is_expected.to eq('03/02/2001') } end context "with date de passage en instruction" do let(:template) { '--date de passage en instruction--' } - it { is_expected.to eq('06/05/2004') } + it { is_expected.to eq('06/05/2004') } end context "with date de décision" do let(:template) { '--date de décision--' } - it { is_expected.to eq('09/08/2007') } + it { is_expected.to eq('09/08/2007') } end end diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 206341037..f5425bf79 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -94,9 +94,10 @@ describe Gestionnaire, type: :model do context 'when gestionnaire follow any dossier' do it { is_expected.to eq 0 } it { expect(gestionnaire.follows.count).to eq 0 } - it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject) + it do + expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject) subject - } + end end context 'when gestionnaire follow any dossier into the procedure past in params' do @@ -106,9 +107,10 @@ describe Gestionnaire, type: :model do it { is_expected.to eq 0 } it { expect(gestionnaire.follows.count).to eq 1 } - it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject) + it do + expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject) subject - } + end end context 'when gestionnaire follow a dossier with a notification into the procedure past in params' do @@ -121,9 +123,10 @@ describe Gestionnaire, type: :model do it { is_expected.to eq 1 } it { expect(gestionnaire.follows.count).to eq 1 } - it { expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:inject) + it do + expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:inject) subject - } + end end end From 19ee24d559e426189205a93636cae51da797517a Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:12:45 +0100 Subject: [PATCH 26/45] Enable the Layout/InitialIndentation cop --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1b3601fa4..069eda4ae 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -118,7 +118,7 @@ Layout/IndentationWidth: Enabled: true Layout/InitialIndentation: - Enabled: false + Enabled: true Layout/LeadingCommentSpace: Enabled: false From 345b8929565716c92050ef616f751ed4316302f5 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:14:09 +0100 Subject: [PATCH 27/45] Enable the Layout/LeadingCommentSpace cop --- .rubocop.yml | 2 +- app/controllers/admin/gestionnaires_controller.rb | 2 +- app/controllers/users/sessions_controller.rb | 2 +- app/facades/dossier_facades.rb | 2 +- app/facades/invite_dossier_facades.rb | 2 +- app/models/etablissement.rb | 2 +- app/models/gestionnaire.rb | 2 +- app/models/search.rb | 10 +++++----- config/routes.rb | 2 +- ...0609145737_delete_default_description_to_dossier.rb | 8 ++++---- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 069eda4ae..10af7eb1a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -121,7 +121,7 @@ Layout/InitialIndentation: Enabled: true Layout/LeadingCommentSpace: - Enabled: false + Enabled: true Layout/MultilineArrayBraceLayout: Enabled: false diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb index 6319e2569..e8f1848f3 100644 --- a/app/controllers/admin/gestionnaires_controller.rb +++ b/app/controllers/admin/gestionnaires_controller.rb @@ -61,7 +61,7 @@ class Admin::GestionnairesController < AdminController else @gestionnaire.administrateurs.push current_administrateur flash.notice = 'Accompagnateur ajouté' - #TODO Mailer no assign_to + # TODO Mailer no assign_to end end end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index ea455dbfc..df00724b4 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -12,7 +12,7 @@ class Users::SessionsController < Sessions::SessionsController error_procedure end - #POST /resource/sign_in + # POST /resource/sign_in def create remember_me = params[:user][:remember_me] == '1' try_to_authenticate(User, remember_me) diff --git a/app/facades/dossier_facades.rb b/app/facades/dossier_facades.rb index 160d5e3b5..f41ebd9e8 100644 --- a/app/facades/dossier_facades.rb +++ b/app/facades/dossier_facades.rb @@ -1,5 +1,5 @@ class DossierFacades - #TODO rechercher en fonction de la personne/email + # TODO rechercher en fonction de la personne/email def initialize(dossier_id, email, champ_id = nil) @dossier = Dossier.find(dossier_id) @champ_id = champ_id diff --git a/app/facades/invite_dossier_facades.rb b/app/facades/invite_dossier_facades.rb index 6aaad2450..895e6a684 100644 --- a/app/facades/invite_dossier_facades.rb +++ b/app/facades/invite_dossier_facades.rb @@ -1,5 +1,5 @@ class InviteDossierFacades < DossierFacades - #TODO rechercher en fonction de la personne/email + # TODO rechercher en fonction de la personne/email def initialize id, email @dossier = Invite.where(email: email, id: id).first!.dossier end diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 5e480ae85..23fc3b0c0 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -11,7 +11,7 @@ class Etablissement < ActiveRecord::Base end def inline_adresse - #squeeze needed because of space in excess in the data + # squeeze needed because of space in excess in the data "#{numero_voie} #{type_voie} #{nom_voie}, #{complement_adresse}, #{code_postal} #{localite}".squeeze(' ') end end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index b3655b169..a7ab7f1ea 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -107,7 +107,7 @@ class Gestionnaire < ActiveRecord::Base .find_by(gestionnaire: self, dossier: dossier) if follow.present? - #retirer le seen_at.present? une fois la contrainte de presence en base (et les migrations ad hoc) + # retirer le seen_at.present? une fois la contrainte de presence en base (et les migrations ad hoc) champs_publiques = follow.demande_seen_at.present? && follow.dossier.champs.updated_since?(follow.demande_seen_at).any? diff --git a/app/models/search.rb b/app/models/search.rb index 89f01ea03..7e455f4a8 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -65,11 +65,11 @@ class Search < ActiveRecord::Base Results.new(q) end - #def self.refresh - # # TODO: could be executed concurrently - # # See https://github.com/thoughtbot/scenic#what-about-materialized-views - # Scenic.database.refresh_materialized_view(table_name, concurrently: false) - #end + # def self.refresh + # # TODO: could be executed concurrently + # # See https://github.com/thoughtbot/scenic#what-about-materialized-views + # Scenic.database.refresh_materialized_view(table_name, concurrently: false) + # end private diff --git a/config/routes.rb b/config/routes.rb index eedcd3e86..6f58fe1b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -171,7 +171,7 @@ Rails.application.routes.draw do end namespace :accompagnateurs do - get 'show' #delete after fixed tests admin/accompagnateurs/show_spec without this line + get 'show' # delete after fixed tests admin/accompagnateurs/show_spec without this line end resources :gestionnaires, only: [:index, :create, :destroy] diff --git a/db/migrate/20160609145737_delete_default_description_to_dossier.rb b/db/migrate/20160609145737_delete_default_description_to_dossier.rb index 8ba2fc7d9..feca43f92 100644 --- a/db/migrate/20160609145737_delete_default_description_to_dossier.rb +++ b/db/migrate/20160609145737_delete_default_description_to_dossier.rb @@ -13,21 +13,21 @@ class DeleteDefaultDescriptionToDossier < ActiveRecord::Migration def up Procedure.all.each do |procedure| - #change all type_de_champ place_order by +1 to insert new type_de_champ description on first place + # change all type_de_champ place_order by +1 to insert new type_de_champ description on first place TypeDeChamp.where(procedure_id: procedure.id).each do |type_de_champ| type_de_champ.order_place += 1 type_de_champ.save end - #insert type_de_champ description on first place + # insert type_de_champ description on first place TypeDeChamp.create(libelle: 'Description', description: 'Description de votre demande', type_champ: 'textarea', order_place: 0, procedure_id: procedure.id, mandatory: true) end Dossier.all.each do |dossier| - #get the new type de champ + # get the new type de champ new_type_de_champ = TypeDeChamp.where(libelle: 'Description', type_champ: 'textarea', order_place: 0, procedure_id: dossier.procedure_id, mandatory: true) - #create a new champ with the actual description value + # create a new champ with the actual description value Champ.create(value: dossier.description, type_de_champ_id: new_type_de_champ.first.id, dossier_id: dossier.id) end From 14c17476456787ddda2ed68cc4c1700a2f5aa688 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:17:01 +0100 Subject: [PATCH 28/45] Enable the Layout/MultilineArrayBraceLayout cop --- .rubocop.yml | 3 ++- app/models/concerns/tags_substitution_concern.rb | 3 ++- spec/features/new_gestionnaire/gestionnaire_spec.rb | 3 ++- spec/models/procedure_presentation_spec.rb | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 10af7eb1a..7f6109c35 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -124,7 +124,8 @@ Layout/LeadingCommentSpace: Enabled: true Layout/MultilineArrayBraceLayout: - Enabled: false + Enabled: true + EnforcedStyle: new_line Layout/MultilineAssignmentLayout: Enabled: false diff --git a/app/models/concerns/tags_substitution_concern.rb b/app/models/concerns/tags_substitution_concern.rb index 0fc3b059e..6dcfc25ce 100644 --- a/app/models/concerns/tags_substitution_concern.rb +++ b/app/models/concerns/tags_substitution_concern.rb @@ -97,7 +97,8 @@ module TagsSubstitutionConcern [dossier_tags, dossier], [individual_tags, dossier.individual], [entreprise_tags, dossier.entreprise], - [etablissement_tags, dossier.entreprise&.etablissement]] + [etablissement_tags, dossier.entreprise&.etablissement] + ] tags_and_datas .map { |(tags, data)| [filter_tags(tags, dossier.termine?), data] } diff --git a/spec/features/new_gestionnaire/gestionnaire_spec.rb b/spec/features/new_gestionnaire/gestionnaire_spec.rb index d858ca41e..ed4cacc89 100644 --- a/spec/features/new_gestionnaire/gestionnaire_spec.rb +++ b/spec/features/new_gestionnaire/gestionnaire_spec.rb @@ -162,7 +162,8 @@ feature 'The gestionnaire part' do "suivi #{suivi}", "traité #{traite}", "tous les dossiers #{tous_les_dossiers}", - "archivé #{archive}"] + "archivé #{archive}" + ] texts.each { |text| expect(page).to have_text(text) } end diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index f75aa84cc..21c8a6a9e 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -5,7 +5,8 @@ describe ProcedurePresentation do ProcedurePresentation.create( displayed_fields: [ { "label" => "test1", "table" => "user" }.to_json, - { "label" => "test2", "table" => "champs" }.to_json], + { "label" => "test2", "table" => "champs" }.to_json + ], sort: { "table" => "user","column" => "email","order" => "asc" }.to_json, filters: { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "table1", "column" => "column1" }] }.to_json ).id From 9d755264600e63754e70cc938637db8e5655e6fc Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:22:02 +0100 Subject: [PATCH 29/45] Enable the Layout/MultilineAssignmentLayout cop --- .rubocop.yml | 2 +- .../admin/procedures_controller.rb | 23 ++++++----- app/controllers/ban/search_controller.rb | 8 ++-- .../api/v1/dossiers_controller_spec.rb | 3 +- .../france_connect_particulier_spec.rb | 19 ++++----- spec/models/dossier_spec.rb | 22 ++++++----- spec/models/drop_down_list_spec.rb | 39 +++++++++++-------- 7 files changed, 66 insertions(+), 50 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7f6109c35..fe31ef760 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -131,7 +131,7 @@ Layout/MultilineAssignmentLayout: Enabled: false Layout/MultilineBlockLayout: - Enabled: false + Enabled: true Layout/MultilineHashBraceLayout: Enabled: false diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index d38758eec..f54444e12 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -208,15 +208,20 @@ class Admin::ProceduresController < AdminController end def path_list - render json: ProcedurePath - .joins(', procedures') - .where("procedures.id = procedure_paths.procedure_id") - .where("procedures.archived_at" => nil) - .where("path LIKE ?", "%#{params[:request]}%") - .pluck(:path, :administrateur_id) - .inject([]) { - |acc, value| acc.push({label: value.first, mine: value.second == current_administrateur.id}) - }.to_json + json_path_list = ProcedurePath + .joins(', procedures') + .where("procedures.id = procedure_paths.procedure_id") + .where("procedures.archived_at" => nil) + .where("path LIKE ?", "%#{params[:request]}%") + .pluck(:path, :administrateur_id) + .map do |value| + { + label: value.first, + mine: value.second == current_administrateur.id + } + end.to_json + + render json: json_path_list end private diff --git a/app/controllers/ban/search_controller.rb b/app/controllers/ban/search_controller.rb index 294ad0cc4..ec079347c 100644 --- a/app/controllers/ban/search_controller.rb +++ b/app/controllers/ban/search_controller.rb @@ -2,9 +2,11 @@ class Ban::SearchController < ApplicationController def get request = params[:request] - render json: Carto::Bano::AddressRetriever.new(request).list.inject([]) { - |acc, value| acc.push({label: value}) - }.to_json + json = Carto::Bano::AddressRetriever.new(request).list.map do |value| + { label: value } + end.to_json + + render json: json end def get_address_point diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index fa0fe0008..266babaad 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -200,8 +200,7 @@ describe API::V1::DossiersController do end describe 'champs' do - let(:field_list) { [:url] - } + let(:field_list) { [:url] } subject { super()[:champs] } it { expect(subject.length).to eq 1 } diff --git a/spec/features/france_connect/france_connect_particulier_spec.rb b/spec/features/france_connect/france_connect_particulier_spec.rb index 7f1b263af..41b57d27f 100644 --- a/spec/features/france_connect/france_connect_particulier_spec.rb +++ b/spec/features/france_connect/france_connect_particulier_spec.rb @@ -35,15 +35,16 @@ feature 'France Connect Particulier Connexion' do let(:code) { 'plop' } context 'when authentification is ok' do - let(:france_connect_information) { create(:france_connect_information, - france_connect_particulier_id: france_connect_particulier_id, - given_name: given_name, - family_name: family_name, - birthdate: birthdate, - birthplace: birthplace, - gender: gender, - email_france_connect: email) - } + let(:france_connect_information) do + create(:france_connect_information, + france_connect_particulier_id: france_connect_particulier_id, + given_name: given_name, + family_name: family_name, + birthdate: birthdate, + birthplace: birthplace, + gender: gender, + email_france_connect: email) + end before do allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code)) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index c0b468df5..f293c9205 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -211,11 +211,12 @@ describe Dossier do it { expect(subject).to include(:individual_nom) } it { expect(subject).to include(:individual_prenom) } it { expect(subject).to include(:individual_birthdate) } - it { expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + - dossier.procedure.types_de_champ.count + - dossier.procedure.types_de_champ_private.count + - dossier.export_entreprise_data.count) - } + it do + expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + + dossier.procedure.types_de_champ.count + + dossier.procedure.types_de_champ_private.count + + dossier.export_entreprise_data.count) + end end describe '#to_sorted_values' do @@ -238,11 +239,12 @@ describe Dossier do it { expect(subject[14]).to be_nil } it { expect(subject[15]).to be_nil } it { expect(subject[16]).to be_nil } - it { expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + - dossier.procedure.types_de_champ.count + - dossier.procedure.types_de_champ_private.count + - dossier.export_entreprise_data.count) - } + it do + expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count + + dossier.procedure.types_de_champ.count + + dossier.procedure.types_de_champ_private.count + + dossier.export_entreprise_data.count) + end context 'dossier for individual' do let(:dossier_with_individual) { create(:dossier, :for_individual, user: user, procedure: procedure) } diff --git a/spec/models/drop_down_list_spec.rb b/spec/models/drop_down_list_spec.rb index c75c9c74e..b898201db 100644 --- a/spec/models/drop_down_list_spec.rb +++ b/spec/models/drop_down_list_spec.rb @@ -4,32 +4,39 @@ describe DropDownList do let(:dropdownlist) { create :drop_down_list, value: value } describe '#options' do - let(:value) { "Cohésion sociale -Dév.Eco / Emploi -Cadre de vie / Urb. -Pilotage / Ingénierie -" -} + let(:value) do + <<~EOS + Cohésion sociale + Dév.Eco / Emploi + Cadre de vie / Urb. + Pilotage / Ingénierie + EOS + end it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } context 'when one value is empty' do - let(:value) { "Cohésion sociale -Cadre de vie / Urb. -Pilotage / Ingénierie -" -} + let(:value) do + <<~EOS + Cohésion sociale + Cadre de vie / Urb. + Pilotage / Ingénierie + EOS + end it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] } end end describe 'disabled_options' do - let(:value) { "tip ---top-- ---troupt-- -ouaich" -} + let(:value) do + <<~EOS + tip + --top-- + --troupt-- + ouaich + EOS + end it { expect(dropdownlist.disabled_options).to match(['--top--', '--troupt--']) } end From 5077e654f2e9393e6b040b376bfb395865151c55 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:24:05 +0100 Subject: [PATCH 30/45] Enable the Layout/MultilineHashBraceLayout cop --- .rubocop.yml | 3 ++- .../gestionnaires/passwords_controller_spec.rb | 12 +++++++----- spec/services/france_connect_service_spec.rb | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index fe31ef760..7638e3b15 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -134,7 +134,8 @@ Layout/MultilineBlockLayout: Enabled: true Layout/MultilineHashBraceLayout: - Enabled: false + Enabled: true + EnforcedStyle: new_line Layout/MultilineMethodCallBraceLayout: Enabled: false diff --git a/spec/controllers/gestionnaires/passwords_controller_spec.rb b/spec/controllers/gestionnaires/passwords_controller_spec.rb index a073e1e86..d23fe6623 100644 --- a/spec/controllers/gestionnaires/passwords_controller_spec.rb +++ b/spec/controllers/gestionnaires/passwords_controller_spec.rb @@ -18,11 +18,13 @@ describe Gestionnaires::PasswordsController, type: :controller do end it "also signs user in" do - put :update, params: {gestionnaire: { - reset_password_token: @token, - password: "supersecret", - password_confirmation: "supersecret" - }} + put :update, params: { + gestionnaire: { + reset_password_token: @token, + password: "supersecret", + password_confirmation: "supersecret" + } + } expect(subject.current_gestionnaire).to eq(gestionnaire) expect(subject.current_user).to eq(user) end diff --git a/spec/services/france_connect_service_spec.rb b/spec/services/france_connect_service_spec.rb index 342b8eb2e..c3c1f70b4 100644 --- a/spec/services/france_connect_service_spec.rb +++ b/spec/services/france_connect_service_spec.rb @@ -37,7 +37,8 @@ describe FranceConnectService do birthplace: birthplace, gender: gender, email_france_connect: email, - france_connect_particulier_id: france_connect_particulier_id }) + france_connect_particulier_id: france_connect_particulier_id + }) end end end From b77837bfd19e470040473a5d52481d671aa6ab8a Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:29:44 +0100 Subject: [PATCH 31/45] Enable the Layout/MultilineMethodCallBraceLayout cop --- .rubocop.yml | 3 ++- app/controllers/admin/procedures_controller.rb | 3 ++- app/controllers/users_controller.rb | 7 ++++--- app/services/france_connect_service.rb | 6 ++++-- app/services/module_api_carto_service.rb | 6 ++++-- app/services/sync_credentials_service.rb | 18 ++++++------------ lib/tasks/2017_10_06_set_follow_date.rake | 3 ++- .../_pieces_justificatives.html.haml_spec.rb | 14 ++++++++------ 8 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7638e3b15..08f12618b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -138,7 +138,8 @@ Layout/MultilineHashBraceLayout: EnforcedStyle: new_line Layout/MultilineMethodCallBraceLayout: - Enabled: false + Enabled: true + EnforcedStyle: symmetrical Layout/MultilineMethodCallIndentation: Enabled: false diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index f54444e12..034df45e0 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -100,7 +100,8 @@ class Admin::ProceduresController < AdminController path: params[:procedure_path], procedure: procedure, administrateur: procedure.administrateur - }) + } + ) if new_procedure_path.validate new_procedure_path.delete diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f531a487f..15c7ba21f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,9 +16,10 @@ class UsersController < ApplicationController end def authorized_routes? controller - redirect_to_root_path 'Le statut de votre dossier n\'autorise pas cette URL' if !UserRoutesAuthorizationService.authorized_route?( - controller, - current_user_dossier) + if !UserRoutesAuthorizationService.authorized_route?(controller, current_user_dossier) + redirect_to_root_path 'Le statut de votre dossier n\'autorise pas cette URL' + end + rescue ActiveRecord::RecordNotFound redirect_to_root_path 'Vous n’avez pas accès à ce dossier.' end diff --git a/app/services/france_connect_service.rb b/app/services/france_connect_service.rb index bbfe73794..a0ba7fb04 100644 --- a/app/services/france_connect_service.rb +++ b/app/services/france_connect_service.rb @@ -5,7 +5,8 @@ class FranceConnectService client.authorization_uri( scope: [:profile, :email], state: SecureRandom.hex(16), - nonce: SecureRandom.hex(16)) + nonce: SecureRandom.hex(16) + ) end def self.retrieve_user_informations_particulier(code) @@ -22,6 +23,7 @@ class FranceConnectService email_france_connect: user_info[:email], birthdate: user_info[:birthdate], birthplace: user_info[:birthplace], - france_connect_particulier_id: user_info[:sub]) + france_connect_particulier_id: user_info[:sub] + ) end end diff --git a/app/services/module_api_carto_service.rb b/app/services/module_api_carto_service.rb index 252ad1c2e..e1120c316 100644 --- a/app/services/module_api_carto_service.rb +++ b/app/services/module_api_carto_service.rb @@ -26,14 +26,16 @@ class ModuleApiCartoService def self.generate_qp coordinates coordinates.inject({}) { |acc, coordinate| acc.merge CARTO::SGMAP::QuartiersPrioritaires::Adapter.new( - coordinate.map { |element| [element['lng'], element['lat']] }).to_params + coordinate.map { |element| [element['lng'], element['lat']] } + ).to_params } end def self.generate_cadastre coordinates (coordinates.inject([]) { |acc, coordinate| acc << CARTO::SGMAP::Cadastre::Adapter.new( - coordinate.map { |element| [element['lng'], element['lat']] }).to_params + coordinate.map { |element| [element['lng'], element['lat']] } + ).to_params }).flatten end end diff --git a/app/services/sync_credentials_service.rb b/app/services/sync_credentials_service.rb index 983f6a1bd..7ae2dcad2 100644 --- a/app/services/sync_credentials_service.rb +++ b/app/services/sync_credentials_service.rb @@ -9,28 +9,22 @@ class SyncCredentialsService def change_credentials! if @klass != User user = User.find_by(email: @email_was) - if user - return false if !user.update_columns( - email: @email, - encrypted_password: @encrypted_password) + if user && !user.update_columns(email: @email, encrypted_password: @encrypted_password) + return false end end if @klass != Gestionnaire gestionnaire = Gestionnaire.find_by(email: @email_was) - if gestionnaire - return false if !gestionnaire.update_columns( - email: @email, - encrypted_password: @encrypted_password) + if gestionnaire && !gestionnaire.update_columns(email: @email, encrypted_password: @encrypted_password) + return false end end if @klass != Administrateur administrateur = Administrateur.find_by(email: @email_was) - if administrateur - return false if !administrateur.update_columns( - email: @email, - encrypted_password: @encrypted_password) + if administrateur && !administrateur.update_columns(email: @email, encrypted_password: @encrypted_password) + return false end end diff --git a/lib/tasks/2017_10_06_set_follow_date.rake b/lib/tasks/2017_10_06_set_follow_date.rake index c40f3f2f4..4a7cae3db 100644 --- a/lib/tasks/2017_10_06_set_follow_date.rake +++ b/lib/tasks/2017_10_06_set_follow_date.rake @@ -23,7 +23,8 @@ namespace :'2017_10_06_set_follow_date' do demande_seen_at: gestionnaire.current_sign_in_at, annotations_privees_seen_at: gestionnaire.current_sign_in_at, avis_seen_at: gestionnaire.current_sign_in_at, - messagerie_seen_at: gestionnaire.current_sign_in_at) + messagerie_seen_at: gestionnaire.current_sign_in_at + ) end end diff --git a/spec/views/users/description/_pieces_justificatives.html.haml_spec.rb b/spec/views/users/description/_pieces_justificatives.html.haml_spec.rb index 410d63c74..df2b7e6bf 100644 --- a/spec/views/users/description/_pieces_justificatives.html.haml_spec.rb +++ b/spec/views/users/description/_pieces_justificatives.html.haml_spec.rb @@ -2,24 +2,26 @@ require 'spec_helper' describe 'users/description/_pieces_justificatives.html.haml', type: :view do let!(:procedure) { create(:procedure) } - let!(:tpj1) { - create(:type_de_piece_justificative, + let!(:tpj1) do + create( + :type_de_piece_justificative, procedure: procedure, libelle: "Première pièce jointe", description: "Première description", order_place: 1, mandatory: true ) - } - let!(:tpj2) { - create(:type_de_piece_justificative, + end + let!(:tpj2) do + create( + :type_de_piece_justificative, procedure: procedure, libelle: "Seconde pièce jointe", description: "Seconde description", order_place: 2, lien_demarche: "https://www.google.fr" ) - } + end let!(:dossier) { create(:dossier, :procedure => procedure) } before do From 73dd58b6cdf104a8ed31ddcf058ac98736b3b90d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:34:08 +0100 Subject: [PATCH 32/45] Enable the Layout/MultilineMethodCallIndentation cop --- .rubocop.yml | 3 ++- .../new_gestionnaire/procedures_controller.rb | 8 +++---- app/models/gestionnaire.rb | 13 +++++----- app/services/pieces_justificatives_service.rb | 24 +++++++++---------- app/services/types_de_champ_service.rb | 22 ++++++++--------- spec/controllers/root_controller_spec.rb | 2 +- .../users/carte_controller_shared_example.rb | 18 +++++++------- .../users/dossiers_controller_spec.rb | 10 ++++---- spec/features/admin/connection_spec.rb | 2 +- spec/features/users/complete_demande_spec.rb | 8 +++---- spec/features/users/dossier_creation_spec.rb | 8 +++---- spec/features/users/start_demande_spec.rb | 8 +++---- spec/lib/carto/bano/address_retriever_spec.rb | 2 +- spec/lib/carto/sgmap/api_spec.rb | 12 +++++----- spec/lib/carto/sgmap/cadastre/adapter_spec.rb | 6 ++--- .../quartiers_prioritaires/adapter_spec.rb | 6 ++--- spec/lib/siade/api_spec.rb | 8 +++---- spec/lib/siade/entreprise_adapter_spec.rb | 2 +- spec/lib/siade/etablissement_adapter_spec.rb | 4 ++-- spec/lib/siade/exercices_adapter_spec.rb | 2 +- spec/lib/siade/rna_adapter_spec.rb | 2 +- 21 files changed, 85 insertions(+), 85 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 08f12618b..e637b7440 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -142,7 +142,8 @@ Layout/MultilineMethodCallBraceLayout: EnforcedStyle: symmetrical Layout/MultilineMethodCallIndentation: - Enabled: false + Enabled: true + EnforcedStyle: indented Layout/MultilineMethodDefinitionBraceLayout: Enabled: false diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index 33165bfd4..dd60ffbae 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -240,12 +240,12 @@ module NewGestionnaire when 'user', 'etablissement', 'entreprise' if filter['column'] == 'date_creation' dossiers - .includes(filter['table']) - .where("#{filter['table'].pluralize}.#{filter['column']} = ?", filter['value'].to_date) + .includes(filter['table']) + .where("#{filter['table'].pluralize}.#{filter['column']} = ?", filter['value'].to_date) else dossiers - .includes(filter['table']) - .where("#{filter['table'].pluralize}.#{filter['column']} LIKE ?", "%#{filter['value']}%") + .includes(filter['table']) + .where("#{filter['table'].pluralize}.#{filter['column']} LIKE ?", "%#{filter['value']}%") end end.pluck(:id) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index a7ab7f1ea..f28ffc1ee 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -54,8 +54,7 @@ class Gestionnaire < ActiveRecord::Base procedure_ids = followed_dossiers.pluck(:procedure_id) if procedure_ids.include?(procedure.id) - return followed_dossiers.where(procedure_id: procedure.id) - .inject(0) do |acc, dossier| + return followed_dossiers.where(procedure_id: procedure.id).inject(0) do |acc, dossier| acc += dossier.notifications.where(already_read: false).count end end @@ -83,9 +82,9 @@ class Gestionnaire < ActiveRecord::Base start_date = DateTime.now.beginning_of_week active_procedure_overviews = procedures - .publiees - .map { |procedure| procedure.procedure_overview(start_date) } - .select(&:had_some_activities?) + .publiees + .map { |procedure| procedure.procedure_overview(start_date) } + .select(&:had_some_activities?) if active_procedure_overviews.count == 0 nil @@ -124,8 +123,8 @@ class Gestionnaire < ActiveRecord::Base messagerie = follow.messagerie_seen_at.present? && dossier.commentaires - .where.not(email: 'contact@tps.apientreprise.fr') - .updated_since?(follow.messagerie_seen_at).any? + .where.not(email: 'contact@tps.apientreprise.fr') + .updated_since?(follow.messagerie_seen_at).any? annotations_hash(demande, annotations_privees, avis_notif, messagerie) else diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index 106526e06..373ce7366 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -1,27 +1,27 @@ class PiecesJustificativesService def self.upload!(dossier, user, params) tpj_contents = dossier.types_de_piece_justificative - .map { |tpj| [tpj, params["piece_justificative_#{tpj.id}"]] } - .select { |_, content| content.present? } + .map { |tpj| [tpj, params["piece_justificative_#{tpj.id}"]] } + .select { |_, content| content.present? } without_virus, with_virus = tpj_contents - .partition { |_, content| ClamavService.safe_file?(content.path) } + .partition { |_, content| ClamavService.safe_file?(content.path) } errors = with_virus - .map { |_, content| content.original_filename + ' : virus détecté' } + .map { |_, content| content.original_filename + ' : virus détecté' } errors += without_virus - .map { |tpj, content| save_pj(content, dossier, tpj, user) } - .compact() + .map { |tpj, content| save_pj(content, dossier, tpj, user) } + .compact() end def self.upload_one! dossier, user, params content = params[:piece_justificative][:content] if ClamavService.safe_file? content.path pj = PieceJustificative.new(content: content, - dossier: dossier, - type_de_piece_justificative: nil, - user: user) + dossier: dossier, + type_de_piece_justificative: nil, + user: user) pj.save else @@ -34,9 +34,9 @@ class PiecesJustificativesService def self.save_pj(content, dossier, tpj, user) pj = PieceJustificative.new(content: content, - dossier: dossier, - type_de_piece_justificative: tpj, - user: user) + dossier: dossier, + type_de_piece_justificative: tpj, + user: user) pj.save ? nil : "le fichier #{content.original_filename} (#{pj.libelle.truncate(200)}) n'a pas pu être sauvegardé" end diff --git a/app/services/types_de_champ_service.rb b/app/services/types_de_champ_service.rb index 73ab53bd3..a2e523007 100644 --- a/app/services/types_de_champ_service.rb +++ b/app/services/types_de_champ_service.rb @@ -5,17 +5,17 @@ class TypesDeChampService params_with_ordered_champs = order_champs(params, attributes) parameters = params_with_ordered_champs - .require(:procedure) - .permit("#{attributes}" => [ - :libelle, - :description, - :order_place, - :type_champ, - :id, - :mandatory, - :type, - drop_down_list_attributes: [:value, :id] - ]) + .require(:procedure) + .permit("#{attributes}" => [ + :libelle, + :description, + :order_place, + :type_champ, + :id, + :mandatory, + :type, + drop_down_list_attributes: [:value, :id] + ]) parameters[attributes].each do |param_first, param_second| if param_second[:libelle].empty? diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb index fb72d2994..29538876b 100644 --- a/spec/controllers/root_controller_spec.rb +++ b/spec/controllers/root_controller_spec.rb @@ -45,7 +45,7 @@ describe RootController, type: :controller do before do stub_request(:get, "https://api.github.com/repos/betagouv/tps/releases/latest") - .to_return(:status => 200, :body => '{"tag_name": "plip", "body": "blabla", "published_at": "2016-02-09T16:46:47Z"}', :headers => {}) + .to_return(:status => 200, :body => '{"tag_name": "plip", "body": "blabla", "published_at": "2016-02-09T16:46:47Z"}', :headers => {}) subject end diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb index 7703f7a6d..01c885884 100644 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ b/spec/controllers/users/carte_controller_shared_example.rb @@ -82,8 +82,8 @@ shared_examples 'carte_controller_spec' do before do allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter) - .to receive(:to_params) - .and_return({"QPCODE1234" => {:code => "QPCODE1234", :nom => "QP de test", :commune => "Paris", :geometry => {:type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]}}}) + .to receive(:to_params) + .and_return({"QPCODE1234" => {:code => "QPCODE1234", :nom => "QP de test", :commune => "Paris", :geometry => {:type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]}}}) post :save, params: {dossier_id: dossier.id, json_latlngs: json_latlngs} end @@ -129,8 +129,8 @@ shared_examples 'carte_controller_spec' do before do allow_any_instance_of(CARTO::SGMAP::Cadastre::Adapter) - .to receive(:to_params) - .and_return([{:surface_intersection => "0.0006", :surface_parcelle => 11252.692583090324, :numero => "0013", :feuille => 1, :section => "CD", :code_dep => "30", :nom_com => "Le Grau-du-Roi", :code_com => "133", :code_arr => "000", :geometry => {:type => "MultiPolygon", :coordinates => [[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]]}}]) + .to receive(:to_params) + .and_return([{:surface_intersection => "0.0006", :surface_parcelle => 11252.692583090324, :numero => "0013", :feuille => 1, :section => "CD", :code_dep => "30", :nom_com => "Le Grau-du-Roi", :code_com => "133", :code_arr => "000", :geometry => {:type => "MultiPolygon", :coordinates => [[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]]}}]) post :save, params: {dossier_id: dossier.id, json_latlngs: json_latlngs} end @@ -184,7 +184,7 @@ shared_examples 'carte_controller_spec' do dossier.update etablissement: nil stub_request(:get, /http:\/\/api-adresse[.]data[.]gouv[.]fr\/search[?]limit=1&q=/) - .to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {}) + .to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {}) get :get_position, params: {dossier_id: dossier.id} end @@ -202,7 +202,7 @@ shared_examples 'carte_controller_spec' do before do stub_request(:get, /http:\/\/api-adresse[.]data[.]gouv[.]fr\/search[?]limit=1&q=/) - .to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {}) + .to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {}) get :get_position, params: {dossier_id: dossier.id} end @@ -217,7 +217,7 @@ shared_examples 'carte_controller_spec' do context 'retour d\'un fichier JSON avec 3 attributs' do before do stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{adresse}") - .to_return(status: 200, body: '{"query": "50 avenue des champs u00e9lysu00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs u00c9lysu00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs u00c9lysu00e9es", "citycode": "75108", "context": "75, u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', headers: {}) + .to_return(status: 200, body: '{"query": "50 avenue des champs u00e9lysu00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs u00c9lysu00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs u00c9lysu00e9es", "citycode": "75108", "context": "75, u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', headers: {}) get :get_position, params: {dossier_id: dossier.id} end @@ -244,8 +244,8 @@ shared_examples 'carte_controller_spec' do describe 'POST #get_qp' do before do allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter) - .to receive(:to_params) - .and_return({"QPCODE1234" => {:code => "QPCODE1234", :geometry => {:type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]}}}) + .to receive(:to_params) + .and_return({"QPCODE1234" => {:code => "QPCODE1234", :geometry => {:type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]}}}) post :get_qp, params: {dossier_id: dossier.id, coordinates: coordinates} end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index deb8fb97e..3b5865c60 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -179,19 +179,19 @@ describe Users::DossiersController, type: :controller do before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}") - .to_return(status: 404, body: 'fake body') + .to_return(status: 404, body: 'fake body') stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}") - .to_return(status: status_entreprise_call, body: File.read('spec/support/files/etablissement.json')) + .to_return(status: status_entreprise_call, body: File.read('spec/support/files/etablissement.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") - .to_return(status: status_entreprise_call, body: File.read('spec/support/files/entreprise.json')) + .to_return(status: status_entreprise_call, body: File.read('spec/support/files/entreprise.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}") - .to_return(status: exercices_status, body: exercices_body) + .to_return(status: exercices_status, body: exercices_body) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/associations/#{siret}?token=#{SIADETOKEN}") - .to_return(status: rna_status, body: rna_body) + .to_return(status: rna_status, body: rna_body) dossier end diff --git a/spec/features/admin/connection_spec.rb b/spec/features/admin/connection_spec.rb index 7b839e6da..aeb6a4dcc 100644 --- a/spec/features/admin/connection_spec.rb +++ b/spec/features/admin/connection_spec.rb @@ -30,7 +30,7 @@ feature 'Administrator connection' do context 'when clicking on sign-out' do before do stub_request(:get, "https://api.github.com/repos/betagouv/tps/releases/latest") - .to_return(:status => 200, :body => '{"tag_name": "plip", "body": "blabla", "published_at": "2016-02-09T16:46:47Z"}', :headers => {}) + .to_return(:status => 200, :body => '{"tag_name": "plip", "body": "blabla", "published_at": "2016-02-09T16:46:47Z"}', :headers => {}) page.find_by_id('sign-out').find('a').click end diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb index f524fd3f9..c2f455100 100644 --- a/spec/features/users/complete_demande_spec.rb +++ b/spec/features/users/complete_demande_spec.rb @@ -31,14 +31,14 @@ feature 'user path for dossier creation' do context 'sets siret' do before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}") - .to_return(body: File.read('spec/support/files/etablissement.json', status: 200)) + .to_return(body: File.read('spec/support/files/etablissement.json', status: 200)) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) + .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/exercices.json')) + .to_return(status: 200, body: File.read('spec/support/files/exercices.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/associations/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 404, body: '') + .to_return(status: 404, body: '') page.find_by_id('dossier-siret').set siret page.click_on 'Valider' diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index 67b1d7185..4c10c007e 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -47,13 +47,13 @@ feature 'As a User I wanna create a dossier' do expect(page).to have_current_path(users_dossier_path(procedure_with_siret.dossiers.last.id.to_s), only_path: true) fill_in 'dossier-siret', with: siret stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) + .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) + .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/exercices.json')) + .to_return(status: 200, body: File.read('spec/support/files/exercices.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/associations/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 404, body: '') + .to_return(status: 404, body: '') page.find_by_id('dossier-siret').set siret page.find_by_id('submit-siret').trigger('click') expect(page).to have_css('#recap-info-entreprise') diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb index caa29fc31..c78e29cb0 100644 --- a/spec/features/users/start_demande_spec.rb +++ b/spec/features/users/start_demande_spec.rb @@ -27,13 +27,13 @@ feature 'user arrive on siret page' do context 'when enter a siret', js: true do before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) + .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) + .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/exercices/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/exercices.json')) + .to_return(status: 200, body: File.read('spec/support/files/exercices.json')) stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/associations/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 404, body: '') + .to_return(status: 404, body: '') page.find_by_id('dossier-siret').set siret page.click_on 'Valider' diff --git a/spec/lib/carto/bano/address_retriever_spec.rb b/spec/lib/carto/bano/address_retriever_spec.rb index 0f7797a0e..8ace473f0 100644 --- a/spec/lib/carto/bano/address_retriever_spec.rb +++ b/spec/lib/carto/bano/address_retriever_spec.rb @@ -10,7 +10,7 @@ describe Carto::Bano::AddressRetriever do before do stub_request(:get, "http://api-adresse.data.gouv.fr/search?&q=#{request}&limit=5") - .to_return(status: status, body: response, headers: {}) + .to_return(status: status, body: response, headers: {}) end context 'when address return a list of address' do diff --git a/spec/lib/carto/sgmap/api_spec.rb b/spec/lib/carto/sgmap/api_spec.rb index 00fe308b8..1a541d1cc 100644 --- a/spec/lib/carto/sgmap/api_spec.rb +++ b/spec/lib/carto/sgmap/api_spec.rb @@ -6,9 +6,9 @@ describe CARTO::SGMAP::API do before do stub_request(:post, "https://apicarto.sgmap.fr/quartiers-prioritaires/search") - .with(:body => /.*/, - :headers => {'Content-Type' => 'application/json'}) - .to_return(status: status, body: body) + .with(:body => /.*/, + :headers => {'Content-Type' => 'application/json'}) + .to_return(status: status, body: body) end context 'when geojson is empty' do let(:geojson) { '' } @@ -54,9 +54,9 @@ describe CARTO::SGMAP::API do before do stub_request(:post, "https://apicarto.sgmap.fr/cadastre/geometrie") - .with(:body => /.*/, - :headers => {'Content-Type' => 'application/json'}) - .to_return(status: status, body: body) + .with(:body => /.*/, + :headers => {'Content-Type' => 'application/json'}) + .to_return(status: status, body: body) end context 'when geojson is empty' do let(:geojson) { '' } diff --git a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb index 0e311f5d8..46b11e1b1 100644 --- a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb +++ b/spec/lib/carto/sgmap/cadastre/adapter_spec.rb @@ -5,9 +5,9 @@ describe CARTO::SGMAP::Cadastre::Adapter do before do stub_request(:post, "https://apicarto.sgmap.fr/cadastre/geometrie") - .with(:body => /.*/, - :headers => {'Content-Type' => 'application/json'}) - .to_return(status: status, body: body) + .with(:body => /.*/, + :headers => {'Content-Type' => 'application/json'}) + .to_return(status: status, body: body) end context 'coordinates are filled' do diff --git a/spec/lib/carto/sgmap/quartiers_prioritaires/adapter_spec.rb b/spec/lib/carto/sgmap/quartiers_prioritaires/adapter_spec.rb index 79ed40afc..1458acb06 100644 --- a/spec/lib/carto/sgmap/quartiers_prioritaires/adapter_spec.rb +++ b/spec/lib/carto/sgmap/quartiers_prioritaires/adapter_spec.rb @@ -5,9 +5,9 @@ describe CARTO::SGMAP::QuartiersPrioritaires::Adapter do before do stub_request(:post, "https://apicarto.sgmap.fr/quartiers-prioritaires/search") - .with(:body => /.*/, - :headers => {'Content-Type' => 'application/json'}) - .to_return(status: status, body: body) + .with(:body => /.*/, + :headers => {'Content-Type' => 'application/json'}) + .to_return(status: status, body: body) end context 'coordinates are filled' do diff --git a/spec/lib/siade/api_spec.rb b/spec/lib/siade/api_spec.rb index 591e10423..ab9732265 100644 --- a/spec/lib/siade/api_spec.rb +++ b/spec/lib/siade/api_spec.rb @@ -5,7 +5,7 @@ describe SIADE::API do subject { described_class.entreprise(siren) } before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/entreprises/#{siren}?token=#{SIADETOKEN}") - .to_return(status: status, body: body) + .to_return(status: status, body: body) end context 'when siren does not exist' do let(:siren) { '111111111' } @@ -31,7 +31,7 @@ describe SIADE::API do subject { described_class.etablissement(siret) } before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}") - .to_return(status: status, body: body) + .to_return(status: status, body: body) end context 'when siret does not exist' do @@ -58,7 +58,7 @@ describe SIADE::API do describe '.exercices' do before do stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/exercices\/.*token=/) - .to_return(status: status, body: body) + .to_return(status: status, body: body) end context 'when siret does not exist' do @@ -89,7 +89,7 @@ describe SIADE::API do describe '.rna' do before do stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/associations\/.*token=/) - .to_return(status: status, body: body) + .to_return(status: status, body: body) end subject { described_class.rna(siren) } diff --git a/spec/lib/siade/entreprise_adapter_spec.rb b/spec/lib/siade/entreprise_adapter_spec.rb index 02a2e7f42..9cd14a50f 100644 --- a/spec/lib/siade/entreprise_adapter_spec.rb +++ b/spec/lib/siade/entreprise_adapter_spec.rb @@ -5,7 +5,7 @@ describe SIADE::EntrepriseAdapter do before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/entreprises/418166096?token=#{SIADETOKEN}") - .to_return(body: File.read('spec/support/files/entreprise.json', status: 200)) + .to_return(body: File.read('spec/support/files/entreprise.json', status: 200)) end it '#to_params class est une Hash ?' do diff --git a/spec/lib/siade/etablissement_adapter_spec.rb b/spec/lib/siade/etablissement_adapter_spec.rb index 1693a2756..394f2ee70 100644 --- a/spec/lib/siade/etablissement_adapter_spec.rb +++ b/spec/lib/siade/etablissement_adapter_spec.rb @@ -7,7 +7,7 @@ describe SIADE::EtablissementAdapter do before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}") - .to_return(body: File.read('spec/support/files/etablissement.json', status: 200)) + .to_return(body: File.read('spec/support/files/etablissement.json', status: 200)) end it '#to_params class est une Hash ?' do @@ -74,7 +74,7 @@ describe SIADE::EtablissementAdapter do before do stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{bad_siret}?token=#{SIADETOKEN}") - .to_return(body: 'Fake body', status: 404) + .to_return(body: 'Fake body', status: 404) end it { expect(subject).to be_nil } diff --git a/spec/lib/siade/exercices_adapter_spec.rb b/spec/lib/siade/exercices_adapter_spec.rb index bdf499021..eaab69563 100644 --- a/spec/lib/siade/exercices_adapter_spec.rb +++ b/spec/lib/siade/exercices_adapter_spec.rb @@ -6,7 +6,7 @@ describe SIADE::ExercicesAdapter do before do stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/exercices\/.*token=/) - .to_return(body: File.read('spec/support/files/exercices.json', status: 200)) + .to_return(body: File.read('spec/support/files/exercices.json', status: 200)) end it '#to_params class est une Hash ?' do diff --git a/spec/lib/siade/rna_adapter_spec.rb b/spec/lib/siade/rna_adapter_spec.rb index ded722203..116b14761 100644 --- a/spec/lib/siade/rna_adapter_spec.rb +++ b/spec/lib/siade/rna_adapter_spec.rb @@ -9,7 +9,7 @@ describe SIADE::RNAAdapter do before do stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/associations\/.*token=/) - .to_return(body: body, status: status) + .to_return(body: body, status: status) end context 'when siret is not valid' do From 084ee98ab21d45bc2c8159791a28738ee323a65e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:35:20 +0100 Subject: [PATCH 33/45] Enable the Layout/MultilineMethodDefinitionBraceLayout cop --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index e637b7440..0115f85b1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -146,7 +146,7 @@ Layout/MultilineMethodCallIndentation: EnforcedStyle: indented Layout/MultilineMethodDefinitionBraceLayout: - Enabled: false + Enabled: true Layout/MultilineOperationIndentation: Enabled: false From 727c40ad3554910f21c49760993b2bcc65bd9078 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 19:38:28 +0100 Subject: [PATCH 34/45] Enable the Layout/RescueEnsureAlignment cop --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0115f85b1..4919aebc8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -152,7 +152,7 @@ Layout/MultilineOperationIndentation: Enabled: false Layout/RescueEnsureAlignment: - Enabled: false + Enabled: true Layout/SpaceAfterColon: Enabled: false From 8688d62a24dc302cfb26e04cfa19e08d3dd7aeef Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 8 Jan 2018 16:04:31 +0100 Subject: [PATCH 35/45] Add active attribute to administrateur model --- db/migrate/20180104150513_add_active_to_administrateurs.rb | 5 +++++ db/schema.rb | 7 ++++--- .../2018_01_11_add_active_state_to_administrators.rake | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180104150513_add_active_to_administrateurs.rb create mode 100644 lib/tasks/2018_01_11_add_active_state_to_administrators.rake diff --git a/db/migrate/20180104150513_add_active_to_administrateurs.rb b/db/migrate/20180104150513_add_active_to_administrateurs.rb new file mode 100644 index 000000000..5de20b1f3 --- /dev/null +++ b/db/migrate/20180104150513_add_active_to_administrateurs.rb @@ -0,0 +1,5 @@ +class AddActiveToAdministrateurs < ActiveRecord::Migration[5.0] + def change + add_column :administrateurs, :active, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 08f4ec561..ab3be6bdd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,12 +17,12 @@ ActiveRecord::Schema.define(version: 20180111153308) do enable_extension "unaccent" create_table "administrateurs", 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.string "current_sign_in_ip" @@ -30,6 +30,7 @@ ActiveRecord::Schema.define(version: 20180111153308) do t.datetime "created_at" t.datetime "updated_at" t.string "api_token" + t.boolean "active", default: false t.index ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree t.index ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true, using: :btree end diff --git a/lib/tasks/2018_01_11_add_active_state_to_administrators.rake b/lib/tasks/2018_01_11_add_active_state_to_administrators.rake new file mode 100644 index 000000000..7de822e6c --- /dev/null +++ b/lib/tasks/2018_01_11_add_active_state_to_administrators.rake @@ -0,0 +1,7 @@ +namespace :'2018_01_11_add_active_state_to_administrators' do + task set: :environment do + Administrateur.find_each do |administrateur| + administrateur.update_column(:active, true) + end + end +end From 5a984a3637a62f54d8661f16fdd2dcf97bb6e364 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 11 Jan 2018 14:17:37 +0100 Subject: [PATCH 36/45] Add admin invitation mailer --- app/mailers/administration_mailer.rb | 7 +++++++ .../administration_mailer/invite_admin.html.haml | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 app/views/administration_mailer/invite_admin.html.haml diff --git a/app/mailers/administration_mailer.rb b/app/mailers/administration_mailer.rb index 0bafaec32..bcc0839eb 100644 --- a/app/mailers/administration_mailer.rb +++ b/app/mailers/administration_mailer.rb @@ -9,6 +9,13 @@ class AdministrationMailer < ApplicationMailer subject: "Création d'un compte Admin TPS") end + def invite_admin(admin, reset_password_token) + @reset_password_token = reset_password_token + mail(to: admin.email, + subject: "TPS - Activez votre compte administrateur", + reply_to: "equipe@tps.apientreprise.fr") + end + def dubious_procedures(procedures_and_type_de_champs) @procedures_and_type_de_champs = procedures_and_type_de_champs mail(to: 'equipe@tps.apientreprise.fr', diff --git a/app/views/administration_mailer/invite_admin.html.haml b/app/views/administration_mailer/invite_admin.html.haml new file mode 100644 index 000000000..6693ae419 --- /dev/null +++ b/app/views/administration_mailer/invite_admin.html.haml @@ -0,0 +1,16 @@ +- content_for(:title, 'Activation du compte administrateur') + +Bonjour, +%br +%br +L'équipe TPS vous invite à activer votre compte administrateur sur TPS. +%br +%br +Pour le faire, merci de cliquer sur le lien suivant : += link_to admin_activate_url(token: @reset_password_token), admin_activate_url(token: @reset_password_token) +%br +%br +Bonne journée, +%br +%br +L'équipe Téléprocédures Simplifiées From 0cf40f4f180355fe22dca4c3858556a48d9172bf Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 11 Jan 2018 14:17:50 +0100 Subject: [PATCH 37/45] Add invitation related methods to administrateur model --- app/models/administrateur.rb | 50 ++++++++++++++++++++++++++++++ app/models/administration.rb | 15 +++++++++ spec/models/administrateur_spec.rb | 16 ++++++++++ spec/models/administration_spec.rb | 17 ++++++++++ 4 files changed, 98 insertions(+) create mode 100644 spec/models/administration_spec.rb diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index d23ce1cf4..18ad7e7ae 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -9,6 +9,16 @@ class Administrateur < ActiveRecord::Base include CredentialsSyncableConcern + scope :inactive, -> { where(active: false) } + + def self.find_inactive_by_token(reset_password_token) + self.inactive.with_reset_password_token(reset_password_token) + end + + def self.find_inactive_by_id(id) + self.inactive.find(id) + end + def ensure_api_token if api_token.nil? self.api_token = generate_api_token @@ -19,6 +29,46 @@ class Administrateur < ActiveRecord::Base update_attributes(api_token: generate_api_token) end + def registration_state + if active? + 'Actif' + elsif reset_password_period_valid? + 'En attente' + else + 'Expiré' + end + end + + def invite! + if active? + raise "Impossible d'inviter un utilisateur déjà actif !" + end + + reset_password_token = set_reset_password_token + + AdministrationMailer.invite_admin(self, reset_password_token).deliver_now! + + reset_password_token + end + + def invitation_expired? + !active && !reset_password_period_valid? + end + + def self.reset_password(reset_password_token, password) + administrateur = self.reset_password_by_token({ + password: password, + password_confirmation: password, + reset_password_token: reset_password_token + }) + + if administrateur && administrateur.errors.empty? + administrateur.update_column(:active, true) + end + + administrateur + end + private def generate_api_token diff --git a/app/models/administration.rb b/app/models/administration.rb index f19ea8226..a2e3b56fa 100644 --- a/app/models/administration.rb +++ b/app/models/administration.rb @@ -6,4 +6,19 @@ class Administration < ActiveRecord::Base def self.from_omniauth(params) find_by(email: params["info"]["email"]) end + + def invite_admin(email) + administrateur = Administrateur.new({ + email: email, + active: false + }) + administrateur.password = administrateur.password_confirmation = SecureRandom.hex + + if administrateur.save + AdministrationMailer.new_admin_email(administrateur, self).deliver_now! + administrateur.invite! + end + + administrateur + end end diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb index 65cc16f5f..6fb94c9fc 100644 --- a/spec/models/administrateur_spec.rb +++ b/spec/models/administrateur_spec.rb @@ -50,4 +50,20 @@ describe Administrateur, type: :model do expect(gestionnaire.valid_password?('super secret')).to be(true) end end + + describe '#find_inactive_by_token' do + let(:administrateur) { create(:administration).invite_admin('paul@tps.fr') } + let(:reset_password_token) { administrateur.invite! } + + it { expect(Administrateur.find_inactive_by_token(reset_password_token)).not_to be_nil } + end + + describe '#reset_password' do + let(:administrateur) { create(:administration).invite_admin('paul@tps.fr') } + let(:reset_password_token) { administrateur.invite! } + + it { expect(Administrateur.reset_password(reset_password_token, '12345678').errors).to be_empty } + it { expect(Administrateur.reset_password('123', '12345678').errors).not_to be_empty } + it { expect(Administrateur.reset_password(reset_password_token, '').errors).not_to be_empty } + end end diff --git a/spec/models/administration_spec.rb b/spec/models/administration_spec.rb new file mode 100644 index 000000000..9f8e0463e --- /dev/null +++ b/spec/models/administration_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Administration, type: :model do + describe '#invite_admin' do + let(:administration) { create :administration } + let(:valid_email) { 'paul@tps.fr' } + subject { administration.invite_admin(valid_email) } + + it { + expect(subject.errors).to be_empty + expect(subject).to be_persisted + expect(administration.invite_admin(valid_email).errors).not_to be_empty + } + it { expect(administration.invite_admin(nil).errors).not_to be_empty } + it { expect(administration.invite_admin('toto').errors).not_to be_empty } + end +end From bbf55ab85e562f378bcf4ff9b55519fb2420b335 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 11 Jan 2018 14:18:17 +0100 Subject: [PATCH 38/45] Create administrateurs with invitation link and no password --- .../administrateurs/activate_controller.rb | 34 +++++++++++++++++++ app/controllers/administrations_controller.rb | 15 +++++--- .../administrateurs/activate/new.html.haml | 8 +++++ app/views/administrations/_list.html.haml | 6 ++++ app/views/administrations/index.html.haml | 1 - config/routes.rb | 5 +-- .../administrations_controller_spec.rb | 4 ++- 7 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 app/controllers/administrateurs/activate_controller.rb create mode 100644 app/views/administrateurs/activate/new.html.haml diff --git a/app/controllers/administrateurs/activate_controller.rb b/app/controllers/administrateurs/activate_controller.rb new file mode 100644 index 000000000..396d31df6 --- /dev/null +++ b/app/controllers/administrateurs/activate_controller.rb @@ -0,0 +1,34 @@ +class Administrateurs::ActivateController < ApplicationController + layout "new_application" + + def new + @administrateur = Administrateur.find_inactive_by_token(params[:token]) + + if !@administrateur + flash.alert = "Le lien de validation d'administrateur a expiré, contactez-nous à contact@tps.apientreprise.fr pour obtenir un nouveau lien." + redirect_to root_path + end + end + + def create + administrateur = Administrateur.reset_password( + update_administrateur_params[:reset_password_token], + update_administrateur_params[:password] + ) + + if administrateur && administrateur.errors.empty? + sign_in(administrateur, scope: :administrateur) + flash.notice = "Mot de passe enregistré" + redirect_to admin_procedures_path + else + flash.alert = administrateur.errors.full_messages + redirect_to admin_activate_path(token: update_administrateur_params[:reset_password_token]) + end + end + + private + + def update_administrateur_params + params.require(:administrateur).permit(:reset_password_token, :password) + end +end diff --git a/app/controllers/administrations_controller.rb b/app/controllers/administrations_controller.rb index f182fc0a7..f600ecfd5 100644 --- a/app/controllers/administrations_controller.rb +++ b/app/controllers/administrations_controller.rb @@ -14,21 +14,26 @@ class AdministrationsController < ApplicationController end def create - admin = Administrateur.new create_administrateur_params + administrateur = current_administration.invite_admin(create_administrateur_params[:email]) - if admin.save + if administrateur.errors.empty? flash.notice = "Administrateur créé" - AdministrationMailer.new_admin_email(admin, current_administration).deliver_now! else - flash.alert = admin.errors.full_messages + flash.alert = administrateur.errors.full_messages end redirect_to administrations_path end + def update + Administrateur.find_inactive_by_id(params[:id]).invite! + + redirect_to administrations_path + end + private def create_administrateur_params - params.require(:administrateur).permit(:email, :password) + params.require(:administrateur).permit(:email) end end diff --git a/app/views/administrateurs/activate/new.html.haml b/app/views/administrateurs/activate/new.html.haml new file mode 100644 index 000000000..256159867 --- /dev/null +++ b/app/views/administrateurs/activate/new.html.haml @@ -0,0 +1,8 @@ +.container + = form_for @administrateur, url: { controller: 'administrateurs/activate', action: :create }, html: { class: "form" } do |f| + %br + %h1 + = @administrateur.email + = f.password_field :password, placeholder: 'Mot de passe' + = f.hidden_field :reset_password_token, value: params[:token] + = f.submit 'Définir le mot de passe', class: 'button large primary expand' diff --git a/app/views/administrations/_list.html.haml b/app/views/administrations/_list.html.haml index c5559f651..e17abfa15 100644 --- a/app/views/administrations/_list.html.haml +++ b/app/views/administrations/_list.html.haml @@ -4,6 +4,7 @@ %thead %th.col-xs-4= smart_listing.sortable 'Email', :email %th.col-xs-4= smart_listing.sortable 'Date de dernière connexion', :last_sign_in_at + %th.col-xs-2 État %th.col-xs-2 Procédure active %th.col-xs-2 Dossier en cours @@ -17,6 +18,11 @@ ( = admin.last_sign_in_at.localtime.strftime('%d/%m/%Y') ) + %td + - if admin.invitation_expired? + = link_to admin.registration_state, administration_path(admin), remote: true, method: :patch + - else + = admin.registration_state %td = admin.procedures.publiees.count %td diff --git a/app/views/administrations/index.html.haml b/app/views/administrations/index.html.haml index 869242426..730a7b487 100644 --- a/app/views/administrations/index.html.haml +++ b/app/views/administrations/index.html.haml @@ -3,7 +3,6 @@ = form_for @admin, url: { controller: 'administrations', action: :create } do |f| .form-group.form-inline.text-center = f.text_field :email, placeholder: :email, class: 'form-control' - = f.text_field :password, placeholder: :password, class: 'form-control' = f.submit 'Créer un administrateur', class: 'btn btn-success', id: 'submit_new_administrateur' diff --git a/config/routes.rb b/config/routes.rb index 6f58fe1b3..e28361914 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,8 +55,7 @@ Rails.application.routes.draw do get 'administrations/sign_in' => 'administrations/sessions#new' delete 'administrations/sign_out' => 'administrations/sessions#destroy' authenticate :administration do - resources :administrations, only: [:index, :create] - namespace :administrations do + resources :administrations, only: [:index, :create, :update] do match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post] end end @@ -111,6 +110,8 @@ Rails.application.routes.draw do end namespace :admin do + get 'activate' => '/administrateurs/activate#new' + patch 'activate' => '/administrateurs/activate#create' get 'sign_in' => '/administrateurs/sessions#new' get 'procedures/archived' => 'procedures#archived' get 'procedures/draft' => 'procedures#draft' diff --git a/spec/controllers/administrations_controller_spec.rb b/spec/controllers/administrations_controller_spec.rb index 48b2ba8dc..1ce833d1b 100644 --- a/spec/controllers/administrations_controller_spec.rb +++ b/spec/controllers/administrations_controller_spec.rb @@ -27,7 +27,7 @@ describe AdministrationsController, type: :controller do sign_in administration end - subject { post :create, administrateur: {email: email, password: password} } + subject { post :create, administrateur: {email: email } } context 'when email and password are correct' do it 'add new administrateur in database' do @@ -37,6 +37,8 @@ describe AdministrationsController, type: :controller do it 'alert new mail are send' do expect(AdministrationMailer).to receive(:new_admin_email).and_return(AdministrationMailer) expect(AdministrationMailer).to receive(:deliver_now!) + expect(AdministrationMailer).to receive(:invite_admin).and_return(AdministrationMailer) + expect(AdministrationMailer).to receive(:deliver_now!) subject end end From a050bc20dee8410451e9924d8d7e4337e5f4b868 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 Jan 2018 09:23:20 +0100 Subject: [PATCH 39/45] Add a dossiers_from_avis relation to Gestionnaire --- app/models/gestionnaire.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index f28ffc1ee..65034cc43 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -10,6 +10,7 @@ class Gestionnaire < ActiveRecord::Base has_many :followed_dossiers, through: :follows, source: :dossier has_many :follows has_many :avis + has_many :dossiers_from_avis, through: :avis, source: :dossier include CredentialsSyncableConcern From d33d488db7d2dca884ab36c0ea04b43092f65e73 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 Jan 2018 09:25:23 +0100 Subject: [PATCH 40/45] Avoid EOL if statements --- app/controllers/new_gestionnaire/recherche_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/new_gestionnaire/recherche_controller.rb b/app/controllers/new_gestionnaire/recherche_controller.rb index 243e0d55b..4073b32c8 100644 --- a/app/controllers/new_gestionnaire/recherche_controller.rb +++ b/app/controllers/new_gestionnaire/recherche_controller.rb @@ -8,7 +8,9 @@ module NewGestionnaire @dossiers = current_gestionnaire.dossiers.where(id: @search_terms.to_i) end - @dossiers = Dossier.none if @dossiers.nil? + if @dossiers.nil? + @dossiers = Dossier.none + end # full text search if @dossiers.empty? From 16254899e1d8667157f429dbdc03be72fa775a07 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 Jan 2018 09:27:32 +0100 Subject: [PATCH 41/45] [Fix #1199] Make id search work for experts --- app/controllers/new_gestionnaire/recherche_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/new_gestionnaire/recherche_controller.rb b/app/controllers/new_gestionnaire/recherche_controller.rb index 4073b32c8..0f7dcf159 100644 --- a/app/controllers/new_gestionnaire/recherche_controller.rb +++ b/app/controllers/new_gestionnaire/recherche_controller.rb @@ -5,7 +5,9 @@ module NewGestionnaire # exact id match? if @search_terms.to_i != 0 - @dossiers = current_gestionnaire.dossiers.where(id: @search_terms.to_i) + @dossiers = current_gestionnaire.dossiers.where(id: @search_terms.to_i) + + current_gestionnaire.dossiers_from_avis.where(id: @search_terms.to_i) + @dossiers.uniq! end if @dossiers.nil? From c3754a173f1bae0f36801d36ec6fff9a1452eb53 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 21:33:29 +0100 Subject: [PATCH 42/45] Use map instead of inject --- app/lib/carto/bano/address_retriever.rb | 4 ++-- app/lib/carto/sgmap/cadastre/adapter.rb | 4 ++-- app/models/champ.rb | 6 +++--- app/services/module_api_carto_service.rb | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/lib/carto/bano/address_retriever.rb b/app/lib/carto/bano/address_retriever.rb index 83fb03de3..895320adc 100644 --- a/app/lib/carto/bano/address_retriever.rb +++ b/app/lib/carto/bano/address_retriever.rb @@ -25,8 +25,8 @@ module Carto return [] end - result['features'].inject([]) do |acc, feature| - acc.push feature['properties']['label'] + result['features'].map do |feature| + feature['properties']['label'] end rescue TypeError, JSON::ParserError [] diff --git a/app/lib/carto/sgmap/cadastre/adapter.rb b/app/lib/carto/sgmap/cadastre/adapter.rb index 6c49a9af3..ae9d0bce5 100644 --- a/app/lib/carto/sgmap/cadastre/adapter.rb +++ b/app/lib/carto/sgmap/cadastre/adapter.rb @@ -8,11 +8,11 @@ class CARTO::SGMAP::Cadastre::Adapter end def to_params - data_source[:features].inject([]) do |acc, feature| + data_source[:features].map do |feature| tmp = filter_properties feature[:properties] tmp[:geometry] = feature[:geometry] - acc << tmp + tmp end end diff --git a/app/models/champ.rb b/app/models/champ.rb index d5932bef6..82e14e40e 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -48,15 +48,15 @@ class Champ < ActiveRecord::Base end def self.regions - JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.inject([]) { |acc, liste| acc.push(liste['nom']) } + JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.map { |liste| liste['nom'] } end def self.departements - JSON.parse(Carto::GeoAPI::Driver.departements).inject([]) { |acc, liste| acc.push(liste['code'] + ' - ' + liste['nom']) }.push('99 - Étranger') + JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| liste['code'] + ' - ' + liste['nom'] }.push('99 - Étranger') end def self.pays - JSON.parse(Carto::GeoAPI::Driver.pays).inject([]) { |acc, liste| acc.push(liste['nom']) } + JSON.parse(Carto::GeoAPI::Driver.pays).map { |liste| liste['nom'] } end def to_s diff --git a/app/services/module_api_carto_service.rb b/app/services/module_api_carto_service.rb index e1120c316..492a2543d 100644 --- a/app/services/module_api_carto_service.rb +++ b/app/services/module_api_carto_service.rb @@ -32,10 +32,10 @@ class ModuleApiCartoService end def self.generate_cadastre coordinates - (coordinates.inject([]) { |acc, coordinate| - acc << CARTO::SGMAP::Cadastre::Adapter.new( + coordinates.flat_map do |coordinate| + CARTO::SGMAP::Cadastre::Adapter.new( coordinate.map { |element| [element['lng'], element['lat']] } ).to_params - }).flatten + end end end From 83be054884840464b7e2af8073c260d5ae5baaf0 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 21:34:32 +0100 Subject: [PATCH 43/45] .map.flatten -> .flat_map --- app/models/gestionnaire.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 65034cc43..4a71848a9 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -217,6 +217,6 @@ class Gestionnaire < ActiveRecord::Base updated_annotations, updated_avis, updated_messagerie - ].map { |query| query.distinct.ids }.flatten.uniq + ].flat_map { |query| query.distinct.ids }.uniq end end From 80ed589a17e52fc8c602822e8cfdbd8d015a00da Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Jan 2018 21:41:16 +0100 Subject: [PATCH 44/45] Use string interpolation --- app/decorators/entreprise_decorator.rb | 2 +- app/jobs/find_dubious_procedures_job.rb | 2 +- app/models/champ.rb | 2 +- app/services/pieces_justificatives_service.rb | 4 ++-- app/services/render_partial_service.rb | 4 ++-- config/initializers/features.rb | 4 ++-- config/initializers/storage_url.rb | 2 +- .../users/description_controller_shared_example.rb | 2 +- spec/decorators/entreprise_decorator_spec.rb | 2 +- spec/services/render_partial_service_spec.rb | 4 ++-- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/decorators/entreprise_decorator.rb b/app/decorators/entreprise_decorator.rb index 155a76b0c..21d32e4d9 100644 --- a/app/decorators/entreprise_decorator.rb +++ b/app/decorators/entreprise_decorator.rb @@ -2,7 +2,7 @@ class EntrepriseDecorator < Draper::Decorator delegate_all def raison_sociale_or_name - raison_sociale.blank? ? nom + ' ' + prenom : raison_sociale + raison_sociale.blank? ? "#{nom} #{prenom}" : raison_sociale end def effectif diff --git a/app/jobs/find_dubious_procedures_job.rb b/app/jobs/find_dubious_procedures_job.rb index b0a30e8f3..babe5a51c 100644 --- a/app/jobs/find_dubious_procedures_job.rb +++ b/app/jobs/find_dubious_procedures_job.rb @@ -9,7 +9,7 @@ class FindDubiousProceduresJob < ApplicationJob def perform(*args) # \\y is a word boundary forbidden_regexp = FORBIDDEN_KEYWORDS - .map { |keyword| '\\y' + keyword + '\\y' } + .map { |keyword| "\\y#{keyword}\\y" } .join('|') # ~* -> case insensitive regexp match diff --git a/app/models/champ.rb b/app/models/champ.rb index 82e14e40e..0f29a2f00 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -52,7 +52,7 @@ class Champ < ActiveRecord::Base end def self.departements - JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| liste['code'] + ' - ' + liste['nom'] }.push('99 - Étranger') + JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger') end def self.pays diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index 373ce7366..a99e1334f 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -8,7 +8,7 @@ class PiecesJustificativesService .partition { |_, content| ClamavService.safe_file?(content.path) } errors = with_virus - .map { |_, content| content.original_filename + ' : virus détecté' } + .map { |_, content| "#{content.original_filename} : virus détecté" } errors += without_virus .map { |tpj, content| save_pj(content, dossier, tpj, user) } @@ -26,7 +26,7 @@ class PiecesJustificativesService pj.save else pj = PieceJustificative.new - pj.errors.add(:content, content.original_filename + ': Virus détecté !!') + pj.errors.add(:content, "#{content.original_filename} : Virus détecté !!") end pj diff --git a/app/services/render_partial_service.rb b/app/services/render_partial_service.rb index c45a9197f..5d37024ea 100644 --- a/app/services/render_partial_service.rb +++ b/app/services/render_partial_service.rb @@ -17,7 +17,7 @@ class RenderPartialService def self.left_panel_exist? left_panel_url file = left_panel_url.split('/').last - File.exist?(Rails.root.join('app','views', 'layouts', 'left_panels', '_' + file + '.html.haml')) + File.exist?(Rails.root.join('app','views', 'layouts', 'left_panels', "_#{file}.html.haml")) end private @@ -31,6 +31,6 @@ class RenderPartialService end def retrieve_name - controller.to_s.parameterize.underscore + '_' + method.to_s + "#{controller.to_s.parameterize.underscore}_#{method.to_s}" end end diff --git a/config/initializers/features.rb b/config/initializers/features.rb index 286132103..761494df0 100644 --- a/config/initializers/features.rb +++ b/config/initializers/features.rb @@ -8,8 +8,8 @@ require 'yaml' # ansible config class Features class << self - if File.exist?(File.dirname(__FILE__) + '/features.yml') - features_map = YAML.load_file(File.dirname(__FILE__) + '/features.yml') + if File.exist?("#{File.dirname(__FILE__)}/features.yml") + features_map = YAML.load_file("#{File.dirname(__FILE__)}/features.yml") if features_map features_map.each do |feature, is_active| define_method("#{feature}") do diff --git a/config/initializers/storage_url.rb b/config/initializers/storage_url.rb index 65165ab2e..d89d1bc83 100644 --- a/config/initializers/storage_url.rb +++ b/config/initializers/storage_url.rb @@ -1 +1 @@ -STORAGE_URL = "https://storage.apientreprise.fr/" + CarrierWave::Uploader::Base.fog_directory + '/' +STORAGE_URL = "https://storage.apientreprise.fr/#{CarrierWave::Uploader::Base.fog_directory}/" diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index 6993e7d47..68da86a82 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -279,7 +279,7 @@ shared_examples 'description_controller_spec' do it { expect(response).to redirect_to users_dossier_recapitulatif_path } context 'when champs is type_de_champ datetime' do - it { expect(dossier.champs.find(dossier_datetime_champ_id).value).to eq(dossier_date_value + ' ' + dossier_hour_value + ':' + dossier_minute_value) } + it { expect(dossier.champs.find(dossier_datetime_champ_id).value).to eq("#{dossier_date_value} #{dossier_hour_value}:#{dossier_minute_value}") } end context 'when champs value is empty' do diff --git a/spec/decorators/entreprise_decorator_spec.rb b/spec/decorators/entreprise_decorator_spec.rb index 829dbc762..90076d179 100644 --- a/spec/decorators/entreprise_decorator_spec.rb +++ b/spec/decorators/entreprise_decorator_spec.rb @@ -27,7 +27,7 @@ describe EntrepriseDecorator do context 'when raison_sociale is nil' do let(:raison_sociale) { nil } it 'display nom and prenom' do - expect(subject).to eq(nom + ' ' + prenom) + expect(subject).to eq("#{nom} #{prenom}") end end end diff --git a/spec/services/render_partial_service_spec.rb b/spec/services/render_partial_service_spec.rb index a1cc0e4e1..9f0e30533 100644 --- a/spec/services/render_partial_service_spec.rb +++ b/spec/services/render_partial_service_spec.rb @@ -8,12 +8,12 @@ describe RenderPartialService do describe 'navbar' do subject { service.navbar } - it { is_expected.to eq 'layouts/navbars/navbar_' + controller.to_s.parameterize + '_' + method.to_s } + it { is_expected.to eq "layouts/navbars/navbar_#{controller.to_s.parameterize}_#{method.to_s}" } end describe 'left_panel' do subject { service.left_panel } - it { is_expected.to eq 'layouts/left_panels/left_panel_' + controller.to_s.parameterize + '_' + method.to_s } + it { is_expected.to eq "layouts/left_panels/left_panel_#{controller.to_s.parameterize}_#{method.to_s}" } end end From 7c93b2a0c2aad417b5547ac36e5ce7b189f0613d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 Jan 2018 13:23:29 +0100 Subject: [PATCH 45/45] .map -> .pluck when possible --- app/models/champ.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index 0f29a2f00..ca6a59c8c 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -48,7 +48,7 @@ class Champ < ActiveRecord::Base end def self.regions - JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.map { |liste| liste['nom'] } + JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.pluck("nom") end def self.departements @@ -56,7 +56,7 @@ class Champ < ActiveRecord::Base end def self.pays - JSON.parse(Carto::GeoAPI::Driver.pays).map { |liste| liste['nom'] } + JSON.parse(Carto::GeoAPI::Driver.pays).pluck("nom") end def to_s