commit
ec6026ef2c
9 changed files with 70 additions and 15 deletions
1
Gemfile
1
Gemfile
|
@ -93,6 +93,7 @@ group :test do
|
||||||
gem 'shoulda-matchers', require: false
|
gem 'shoulda-matchers', require: false
|
||||||
gem 'timecop'
|
gem 'timecop'
|
||||||
gem 'vcr'
|
gem 'vcr'
|
||||||
|
gem 'webdrivers', '~> 4.0'
|
||||||
gem 'webmock'
|
gem 'webmock'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
11
Gemfile.lock
11
Gemfile.lock
|
@ -162,7 +162,7 @@ GEM
|
||||||
carrierwave (>= 0.9)
|
carrierwave (>= 0.9)
|
||||||
crack (0.4.3)
|
crack (0.4.3)
|
||||||
safe_yaml (~> 1.0.0)
|
safe_yaml (~> 1.0.0)
|
||||||
crass (1.0.4)
|
crass (1.0.5)
|
||||||
css_parser (1.6.0)
|
css_parser (1.6.0)
|
||||||
addressable
|
addressable
|
||||||
curb (0.9.10)
|
curb (0.9.10)
|
||||||
|
@ -356,7 +356,7 @@ GEM
|
||||||
railties (>= 4)
|
railties (>= 4)
|
||||||
request_store (~> 1.0)
|
request_store (~> 1.0)
|
||||||
logstash-event (1.2.02)
|
logstash-event (1.2.02)
|
||||||
loofah (2.2.3)
|
loofah (2.3.1)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
lumberjack (1.0.13)
|
lumberjack (1.0.13)
|
||||||
|
@ -385,7 +385,7 @@ GEM
|
||||||
nenv (0.3.0)
|
nenv (0.3.0)
|
||||||
netrc (0.11.0)
|
netrc (0.11.0)
|
||||||
nio4r (2.3.1)
|
nio4r (2.3.1)
|
||||||
nokogiri (1.10.4)
|
nokogiri (1.10.5)
|
||||||
mini_portile2 (~> 2.4.0)
|
mini_portile2 (~> 2.4.0)
|
||||||
notiffany (0.1.1)
|
notiffany (0.1.1)
|
||||||
nenv (~> 0.1)
|
nenv (~> 0.1)
|
||||||
|
@ -678,6 +678,10 @@ GEM
|
||||||
activemodel (>= 5.0)
|
activemodel (>= 5.0)
|
||||||
bindex (>= 0.4.0)
|
bindex (>= 0.4.0)
|
||||||
railties (>= 5.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)
|
webfinger (1.1.0)
|
||||||
activesupport
|
activesupport
|
||||||
httpclient (>= 2.4)
|
httpclient (>= 2.4)
|
||||||
|
@ -812,6 +816,7 @@ DEPENDENCIES
|
||||||
vcr
|
vcr
|
||||||
warden
|
warden
|
||||||
web-console
|
web-console
|
||||||
|
webdrivers (~> 4.0)
|
||||||
webmock
|
webmock
|
||||||
webpacker
|
webpacker
|
||||||
xray-rails
|
xray-rails
|
||||||
|
|
|
@ -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;
|
> create user tps_test with password 'tps_test' superuser;
|
||||||
> \q
|
> \q
|
||||||
|
|
||||||
|
|
||||||
### Initialisation de l'environnement de développement
|
### 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 :
|
Afin d'initialiser l'environnement de développement, exécutez la commande suivante :
|
||||||
|
|
||||||
bin/setup
|
bin/setup
|
||||||
|
|
|
@ -17,8 +17,9 @@ class Admin::AssignsController < AdminController
|
||||||
|
|
||||||
not_assign_scope = current_administrateur.instructeurs.where.not(id: assign_scope.ids)
|
not_assign_scope = current_administrateur.instructeurs.where.not(id: assign_scope.ids)
|
||||||
|
|
||||||
if params[:filter]
|
if params[:filter].present?
|
||||||
not_assign_scope = not_assign_scope.where("email LIKE ?", "%#{params[:filter]}%")
|
filter = params[:filter].downcase.strip
|
||||||
|
not_assign_scope = not_assign_scope.where('users.email LIKE ?', "%#{filter}%")
|
||||||
end
|
end
|
||||||
|
|
||||||
@instructeurs_not_assign = smart_listing_create :instructeurs_not_assign,
|
@instructeurs_not_assign = smart_listing_create :instructeurs_not_assign,
|
||||||
|
|
|
@ -12,11 +12,14 @@ class ApiCarto::API
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.call(url, geojson)
|
def self.call(url, geojson)
|
||||||
params = geojson.to_s
|
response = Typhoeus.post(url, body: geojson.to_s, headers: { 'content-type' => 'application/json' })
|
||||||
RestClient.post(url, params, content_type: 'application/json')
|
|
||||||
|
|
||||||
rescue RestClient::InternalServerError, RestClient::BadGateway, RestClient::GatewayTimeout, RestClient::ServiceUnavailable => e
|
if response.success?
|
||||||
Rails.logger.error "[ApiCarto] Error on #{url}: #{e}"
|
response.body
|
||||||
raise RestClient::ResourceNotFound
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,8 @@ chdir APP_ROOT do
|
||||||
system('bundle check') || system!('bundle install')
|
system('bundle check') || system!('bundle install')
|
||||||
system! 'bin/yarn install'
|
system! 'bin/yarn install'
|
||||||
|
|
||||||
|
puts "\n== Updating webdrivers =="
|
||||||
|
system! 'RAILS_ENV=test bin/rails webdrivers:chromedriver:update'
|
||||||
|
|
||||||
puts "\n== Copying sample files =="
|
puts "\n== Copying sample files =="
|
||||||
unless File.exist?('.env')
|
unless File.exist?('.env')
|
||||||
|
|
|
@ -18,6 +18,9 @@ chdir APP_ROOT do
|
||||||
system('bundle check') || system!('bundle install')
|
system('bundle check') || system!('bundle install')
|
||||||
system! 'bin/yarn install'
|
system! 'bin/yarn install'
|
||||||
|
|
||||||
|
puts "\n== Updating webdrivers =="
|
||||||
|
system! 'RAILS_ENV=test bin/rails webdrivers:chromedriver:update'
|
||||||
|
|
||||||
puts "\n== Updating database =="
|
puts "\n== Updating database =="
|
||||||
system! 'bin/rails db:migrate'
|
system! 'bin/rails db:migrate'
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,53 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Admin::AssignsController, type: :controller do
|
describe Admin::AssignsController, type: :controller do
|
||||||
let(:admin) { create(:administrateur) }
|
let(:admin) { create(:administrateur) }
|
||||||
let(:procedure) { create :procedure, administrateur: admin }
|
|
||||||
let(:instructeur) { create :instructeur, administrateurs: [admin] }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in(admin.user)
|
sign_in(admin.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
subject { get :show, params: { procedure_id: procedure.id } }
|
let(:procedure) { create :procedure, administrateur: admin, instructeurs: [instructeur_assigned_1, instructeur_assigned_2] }
|
||||||
it { expect(subject.status).to eq(200) }
|
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
|
end
|
||||||
|
|
||||||
describe 'PUT #update' do
|
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' } }
|
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) }
|
it { expect(subject).to redirect_to admin_procedure_assigns_path(procedure_id: procedure.id) }
|
||||||
|
|
|
@ -83,7 +83,7 @@ VCR.configure do |c|
|
||||||
c.hook_into :webmock
|
c.hook_into :webmock
|
||||||
c.cassette_library_dir = 'spec/fixtures/cassettes'
|
c.cassette_library_dir = 'spec/fixtures/cassettes'
|
||||||
c.configure_rspec_metadata!
|
c.configure_rspec_metadata!
|
||||||
c.ignore_hosts 'test.host'
|
c.ignore_hosts 'test.host', 'chromedriver.storage.googleapis.com'
|
||||||
end
|
end
|
||||||
|
|
||||||
DatabaseCleaner.strategy = :transaction
|
DatabaseCleaner.strategy = :transaction
|
||||||
|
|
Loading…
Reference in a new issue