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..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) @@ -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/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 diff --git a/app/controllers/admin/assigns_controller.rb b/app/controllers/admin/assigns_controller.rb index 5a59330c4..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("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/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 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/controllers/admin/assigns_controller_spec.rb b/spec/controllers/admin/assigns_controller_spec.rb index 95fb4474a..741937dd8 100644 --- a/spec/controllers/admin/assigns_controller_spec.rb +++ b/spec/controllers/admin/assigns_controller_spec.rb @@ -2,19 +2,53 @@ 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 + + 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 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) } 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