From 91db5f4ec28b89d80653b9e3d546b3c8a32e884d Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 5 Nov 2019 17:56:23 +0100 Subject: [PATCH 1/6] =?UTF-8?q?met=20=C3=A0=20jour=20la=20doc=20d'install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 97683c010..faf159341 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,14 @@ Les informations nécessaire à l'initialisation de la base doivent être pré-c > create user tps_test with password 'tps_test' superuser; > \q + ### Initialisation de l'environnement de développement +Sous Ubuntu, certains packages doivent être installés au préalable : + + sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev libcurl4-gnutls-dev zlib1g-dev + + Afin d'initialiser l'environnement de développement, exécutez la commande suivante : bin/setup From 08b1a0f90d48e0cf804ae1568330a699da1381f5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 5 Nov 2019 14:18:58 +0100 Subject: [PATCH 2/6] [API Carto]: use typhoeus and correctly handle errors --- app/lib/api_carto/api.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/lib/api_carto/api.rb b/app/lib/api_carto/api.rb index f94c11e2d..eadb813f8 100644 --- a/app/lib/api_carto/api.rb +++ b/app/lib/api_carto/api.rb @@ -12,11 +12,14 @@ class ApiCarto::API private def self.call(url, geojson) - params = geojson.to_s - RestClient.post(url, params, content_type: 'application/json') + response = Typhoeus.post(url, body: geojson.to_s, headers: { 'content-type' => 'application/json' }) - rescue RestClient::InternalServerError, RestClient::BadGateway, RestClient::GatewayTimeout, RestClient::ServiceUnavailable => e - Rails.logger.error "[ApiCarto] Error on #{url}: #{e}" - raise RestClient::ResourceNotFound + if response.success? + response.body + else + message = response.code == 0 ? response.return_message : response.code.to_s + Rails.logger.error "[ApiCarto] Error on #{url}: #{message}" + raise RestClient::ResourceNotFound + end end end From efd03f0169d06254091c7d96ad536bec0c8b6f47 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 5 Nov 2019 15:47:55 +0100 Subject: [PATCH 3/6] Use webdrivers gem to keep webdrivers updated --- Gemfile | 1 + Gemfile.lock | 5 +++++ bin/setup | 2 ++ bin/update | 3 +++ spec/spec_helper.rb | 2 +- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 13763e699..1d23d00d8 100644 --- a/Gemfile +++ b/Gemfile @@ -93,6 +93,7 @@ group :test do gem 'shoulda-matchers', require: false gem 'timecop' gem 'vcr' + gem 'webdrivers', '~> 4.0' gem 'webmock' end diff --git a/Gemfile.lock b/Gemfile.lock index 7eaa820eb..969792790 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -678,6 +678,10 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) + webdrivers (4.1.3) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (>= 3.0, < 4.0) webfinger (1.1.0) activesupport httpclient (>= 2.4) @@ -812,6 +816,7 @@ DEPENDENCIES vcr warden web-console + webdrivers (~> 4.0) webmock webpacker xray-rails diff --git a/bin/setup b/bin/setup index 3d592bcd5..34110e498 100755 --- a/bin/setup +++ b/bin/setup @@ -18,6 +18,8 @@ chdir APP_ROOT do system('bundle check') || system!('bundle install') system! 'bin/yarn install' + puts "\n== Updating webdrivers ==" + system! 'RAILS_ENV=test bin/rails webdrivers:chromedriver:update' puts "\n== Copying sample files ==" unless File.exist?('.env') diff --git a/bin/update b/bin/update index c1968201d..04eb642c5 100755 --- a/bin/update +++ b/bin/update @@ -18,6 +18,9 @@ chdir APP_ROOT do system('bundle check') || system!('bundle install') system! 'bin/yarn install' + puts "\n== Updating webdrivers ==" + system! 'RAILS_ENV=test bin/rails webdrivers:chromedriver:update' + puts "\n== Updating database ==" system! 'bin/rails db:migrate' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dd0af845a..655686eb2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -83,7 +83,7 @@ VCR.configure do |c| c.hook_into :webmock c.cassette_library_dir = 'spec/fixtures/cassettes' c.configure_rspec_metadata! - c.ignore_hosts 'test.host' + c.ignore_hosts 'test.host', 'chromedriver.storage.googleapis.com' end DatabaseCleaner.strategy = :transaction From c5f2dacb7185ed5d367bb3478f37fe91253b0372 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Nov 2019 10:33:00 +0000 Subject: [PATCH 4/6] build(deps): bump loofah from 2.2.3 to 2.3.1 Bumps [loofah](https://github.com/flavorjones/loofah) from 2.2.3 to 2.3.1. - [Release notes](https://github.com/flavorjones/loofah/releases) - [Changelog](https://github.com/flavorjones/loofah/blob/master/CHANGELOG.md) - [Commits](https://github.com/flavorjones/loofah/compare/v2.2.3...v2.3.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 969792790..fae5871bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -162,7 +162,7 @@ GEM carrierwave (>= 0.9) crack (0.4.3) safe_yaml (~> 1.0.0) - crass (1.0.4) + crass (1.0.5) css_parser (1.6.0) addressable curb (0.9.10) @@ -356,7 +356,7 @@ GEM railties (>= 4) request_store (~> 1.0) logstash-event (1.2.02) - loofah (2.2.3) + loofah (2.3.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.0.13) @@ -385,7 +385,7 @@ GEM nenv (0.3.0) netrc (0.11.0) nio4r (2.3.1) - nokogiri (1.10.4) + nokogiri (1.10.5) mini_portile2 (~> 2.4.0) notiffany (0.1.1) nenv (~> 0.1) From 0eeac59ecdf61e773b0cf198648147d36fb13d4f Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 6 Nov 2019 11:59:15 +0100 Subject: [PATCH 5/6] assigns: fix search among the unassigned instructeurs This was broken since moving the email out of the Instructeur column. --- app/controllers/admin/assigns_controller.rb | 2 +- .../admin/assigns_controller_spec.rb | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/assigns_controller.rb b/app/controllers/admin/assigns_controller.rb index 5a59330c4..57d05670a 100644 --- a/app/controllers/admin/assigns_controller.rb +++ b/app/controllers/admin/assigns_controller.rb @@ -18,7 +18,7 @@ class Admin::AssignsController < AdminController not_assign_scope = current_administrateur.instructeurs.where.not(id: assign_scope.ids) if params[:filter] - not_assign_scope = not_assign_scope.where("email LIKE ?", "%#{params[:filter]}%") + not_assign_scope = not_assign_scope.where('users.email LIKE ?', "%#{params[:filter]}%") end @instructeurs_not_assign = smart_listing_create :instructeurs_not_assign, diff --git a/spec/controllers/admin/assigns_controller_spec.rb b/spec/controllers/admin/assigns_controller_spec.rb index 95fb4474a..923d553d2 100644 --- a/spec/controllers/admin/assigns_controller_spec.rb +++ b/spec/controllers/admin/assigns_controller_spec.rb @@ -2,19 +2,45 @@ require 'spec_helper' describe Admin::AssignsController, type: :controller do let(:admin) { create(:administrateur) } - let(:procedure) { create :procedure, administrateur: admin } - let(:instructeur) { create :instructeur, administrateurs: [admin] } before do sign_in(admin.user) end describe 'GET #show' do - subject { get :show, params: { procedure_id: procedure.id } } - it { expect(subject.status).to eq(200) } + let(:procedure) { create :procedure, administrateur: admin, instructeurs: [instructeur_assigned_1, instructeur_assigned_2] } + let!(:instructeur_assigned_1) { create :instructeur, email: 'instructeur_1@ministere_a.gouv.fr', administrateurs: [admin] } + let!(:instructeur_assigned_2) { create :instructeur, email: 'instructeur_2@ministere_b.gouv.fr', administrateurs: [admin] } + let!(:instructeur_not_assigned_1) { create :instructeur, email: 'instructeur_3@ministere_a.gouv.fr', administrateurs: [admin] } + let!(:instructeur_not_assigned_2) { create :instructeur, email: 'instructeur_4@ministere_b.gouv.fr', administrateurs: [admin] } + let(:filter) { nil } + + subject! { get :show, params: { procedure_id: procedure.id, filter: filter } } + + it { expect(response.status).to eq(200) } + + it 'sets the assigned and not assigned instructeurs' do + expect(assigns(:instructeurs_assign)).to match_array([instructeur_assigned_1, instructeur_assigned_2]) + expect(assigns(:instructeurs_not_assign)).to match_array([instructeur_not_assigned_1, instructeur_not_assigned_2]) + end + + context 'with a search filter' do + let(:filter) { '@ministere_a.gouv.fr' } + + it 'filters the unassigned instructeurs' do + expect(assigns(:instructeurs_not_assign)).to match_array([instructeur_not_assigned_1]) + end + + it 'does not filter the assigned instructeurs' do + expect(assigns(:instructeurs_assign)).to match_array([instructeur_assigned_1, instructeur_assigned_2]) + end + end end describe 'PUT #update' do + let(:procedure) { create :procedure, administrateur: admin } + let(:instructeur) { create :instructeur, administrateurs: [admin] } + subject { put :update, params: { instructeur_id: instructeur.id, procedure_id: procedure.id, to: 'assign' } } it { expect(subject).to redirect_to admin_procedure_assigns_path(procedure_id: procedure.id) } From 8df91df9fa2b41a913f6825ba9e3a9de4fdc28ca Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 6 Nov 2019 12:05:41 +0100 Subject: [PATCH 6/6] assigns: strip and lowercase the search filter --- app/controllers/admin/assigns_controller.rb | 5 +++-- spec/controllers/admin/assigns_controller_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/assigns_controller.rb b/app/controllers/admin/assigns_controller.rb index 57d05670a..cf2899643 100644 --- a/app/controllers/admin/assigns_controller.rb +++ b/app/controllers/admin/assigns_controller.rb @@ -17,8 +17,9 @@ class Admin::AssignsController < AdminController not_assign_scope = current_administrateur.instructeurs.where.not(id: assign_scope.ids) - if params[:filter] - not_assign_scope = not_assign_scope.where('users.email LIKE ?', "%#{params[:filter]}%") + if params[:filter].present? + filter = params[:filter].downcase.strip + not_assign_scope = not_assign_scope.where('users.email LIKE ?', "%#{filter}%") end @instructeurs_not_assign = smart_listing_create :instructeurs_not_assign, diff --git a/spec/controllers/admin/assigns_controller_spec.rb b/spec/controllers/admin/assigns_controller_spec.rb index 923d553d2..741937dd8 100644 --- a/spec/controllers/admin/assigns_controller_spec.rb +++ b/spec/controllers/admin/assigns_controller_spec.rb @@ -34,6 +34,14 @@ describe Admin::AssignsController, type: :controller do it 'does not filter the assigned instructeurs' do expect(assigns(:instructeurs_assign)).to match_array([instructeur_assigned_1, instructeur_assigned_2]) end + + context 'when the filter has spaces or a mixed case' do + let(:filter) { ' @ministere_A.gouv.fr ' } + + it 'trims spaces and ignores the case' do + expect(assigns(:instructeurs_not_assign)).to match_array([instructeur_not_assigned_1]) + end + end end end