From d67d32e3c25a2a7f811e335e8337755e39ff4464 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 20 Dec 2016 11:35:16 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20bug=20get=5Fposition=20when=20=C3=A9t?= =?UTF-8?q?ablissement=20is=20nil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/carte_controller.rb | 3 ++- .../users/carte_controller_shared_example.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/carte_controller.rb b/app/controllers/users/carte_controller.rb index 302b8149a..0b8a328e9 100644 --- a/app/controllers/users/carte_controller.rb +++ b/app/controllers/users/carte_controller.rb @@ -32,7 +32,8 @@ class Users::CarteController < UsersController end def get_position - point = Carto::Geocodeur.convert_adresse_to_point(current_user_dossier.etablissement.geo_adresse) rescue nil + etablissement = current_user_dossier.etablissement + point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) unless etablissement.nil? lon = '2.428462' lat = '46.538192' diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb index f94f77b1e..438964660 100644 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ b/spec/controllers/users/carte_controller_shared_example.rb @@ -179,6 +179,24 @@ shared_examples 'carte_controller_spec' do end describe '#get_position' do + + context 'when etablissement is nil' do + before 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: {}) + get :get_position, params: {dossier_id: dossier.id} + end + + subject { JSON.parse(response.body) } + + it 'on enregistre des coordonnées lat et lon avec les valeurs par defaut' do + expect(subject['lat']).to eq('46.538192') + expect(subject['lon']).to eq('2.428462') + end + end + context 'Geocodeur renvoie les positions par defaut' do let(:etablissement) { create(:etablissement, adresse: bad_adresse, numero_voie: 'dzj', type_voie: 'fzjfk', nom_voie: 'hdidjkz', complement_adresse: 'fjef', code_postal: 'fjeiefk', localite: 'zjfkfz') } let(:dossier) { create(:dossier, etablissement: etablissement) } From 39a023b3e2a70d61c0de05c5690faf095dec715d Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 20 Dec 2016 11:58:17 +0100 Subject: [PATCH 2/3] Features tests about user: index of dossiers, sorting and using pagination --- app/views/users/dossiers/_list.html.haml | 12 +++--- spec/features/users/dossier_edition_spec.rb | 22 +++++----- spec/features/users/dossier_index_spec.rb | 48 +++++++++++++++++++++ 3 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 spec/features/users/dossier_index_spec.rb diff --git a/app/views/users/dossiers/_list.html.haml b/app/views/users/dossiers/_list.html.haml index 65ccc2198..4ec01e39b 100644 --- a/app/views/users/dossiers/_list.html.haml +++ b/app/views/users/dossiers/_list.html.haml @@ -1,16 +1,16 @@ - unless smart_listing.empty? %table#dossiers_list.table %thead - %th.col-md-1.col-lg-1= smart_listing.sortable 'Numéro', 'id' - %th.col-md-5.col-lg-5= smart_listing.sortable 'Procédure', 'procedure.libelle' - %th.col-md-2.col-lg-2= smart_listing.sortable 'État', 'state' - %th.col-md-2.col-lg-2= smart_listing.sortable 'Date de mise à jour', 'updated_at' + %th#sort-id.col-md-1.col-lg-1= smart_listing.sortable 'Numéro', 'id' + %th#sort-libelle.col-md-5.col-lg-5= smart_listing.sortable 'Procédure', 'procedure.libelle' + %th#sort-state.col-md-2.col-lg-2= smart_listing.sortable 'État', 'state' + %th#sort-updated.col-md-2.col-lg-2= smart_listing.sortable 'Date de mise à jour', 'updated_at' - if @liste == "brouillon" %th.col-md-2.col-lg-2= 'Action' - @dossiers.each do |dossier| - if dossier.kind_of? Invite - -invite = dossier - -dossier = invite.dossier.decorate + - invite = dossier + - dossier = invite.dossier.decorate - else - dossier = dossier.decorate diff --git a/spec/features/users/dossier_edition_spec.rb b/spec/features/users/dossier_edition_spec.rb index deeeb2acd..9a81a8ae7 100644 --- a/spec/features/users/dossier_edition_spec.rb +++ b/spec/features/users/dossier_edition_spec.rb @@ -2,20 +2,20 @@ require 'spec_helper' feature 'As a User I want to edit a dossier I own', js: true do - let(:user) { create(:user) } + let(:user) { create(:user) } let(:procedure_for_individual) { create(:procedure, :published, :for_individual, :with_api_carto, :with_type_de_champ, :with_two_type_de_piece_justificative) } before "Create dossier" do - login_as user, scope: :user - visit commencer_path(procedure_path: procedure_for_individual.path) - fill_in 'dossier_individual_attributes_nom', with: 'Nom' - fill_in 'dossier_individual_attributes_prenom', with: 'Prenom' - fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987' - find(:css, "#dossier_autorisation_donnees[value='1']").set(true) - page.find_by_id('etape_suivante').click - page.find_by_id('etape_suivante').click - page.find_by_id('suivant').click - visit root_path + login_as user, scope: :user + visit commencer_path(procedure_path: procedure_for_individual.path) + fill_in 'dossier_individual_attributes_nom', with: 'Nom' + fill_in 'dossier_individual_attributes_prenom', with: 'Prenom' + fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987' + find(:css, "#dossier_autorisation_donnees[value='1']").set(true) + page.find_by_id('etape_suivante').click + page.find_by_id('etape_suivante').click + page.find_by_id('suivant').click + visit root_path end context 'After sign_in, I can navigate through dossiers indexes and edit a dossier' do diff --git a/spec/features/users/dossier_index_spec.rb b/spec/features/users/dossier_index_spec.rb new file mode 100644 index 000000000..2ff4fcb15 --- /dev/null +++ b/spec/features/users/dossier_index_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +feature 'As a User I want to sort and paginate dossiers', js: true do + + let(:user) { create(:user) } + let(:procedure_for_individual) { create(:procedure, :published, :for_individual) } + + before "Create dossier" do + login_as user, scope: :user + visit commencer_path(procedure_path: procedure_for_individual.path) + fill_in 'dossier_individual_attributes_nom', with: 'Nom' + fill_in 'dossier_individual_attributes_prenom', with: 'Prenom' + fill_in 'dossier_individual_attributes_birthdate', with: '14/10/1987' + find(:css, "#dossier_autorisation_donnees[value='1']").set(true) + page.find_by_id('etape_suivante').click + page.find_by_id('suivant').click + 50.times do + Dossier.create(procedure_id: 1, user_id: 1, state: "initiated") + end + visit root_path + end + + context 'After sign_in, I can see my 51 dossiers on the index' do + + scenario 'Using sort' do + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('1') + expect(page.all(:css, '#dossiers_list tr')[2].text.split(" ").first).to eq('2') + visit "/users/dossiers?dossiers_smart_listing[sort][id]=desc" + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('51') + expect(page.all(:css, '#dossiers_list tr')[2].text.split(" ").first).to eq('50') + visit "/users/dossiers?dossiers_smart_listing[sort][id]=asc" + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('1') + expect(page.all(:css, '#dossiers_list tr')[2].text.split(" ").first).to eq('2') + end + + scenario 'Using pagination' do + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('1') + page.find('.next_page a').click + wait_for_ajax + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('8') + page.find('.next_page a').click + wait_for_ajax + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('15') + end + end + + +end From 83444ab54c619d801c066576a45f590bae8b8e3f Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 20 Dec 2016 12:27:53 +0100 Subject: [PATCH 3/3] Catch error 500 for quartier prioritaire --- app/lib/carto/sgmap/api.rb | 3 +++ spec/lib/carto/sgmap/api_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/lib/carto/sgmap/api.rb b/app/lib/carto/sgmap/api.rb index 39cef144d..db29d7d0b 100644 --- a/app/lib/carto/sgmap/api.rb +++ b/app/lib/carto/sgmap/api.rb @@ -21,6 +21,9 @@ class CARTO::SGMAP::API url, verify_ssl: verify_ssl_mode, ).post params[:geojson], content_type: 'application/json' + + rescue RestClient::InternalServerError + raise RestClient::ResourceNotFound end def self.base_url diff --git a/spec/lib/carto/sgmap/api_spec.rb b/spec/lib/carto/sgmap/api_spec.rb index fb9e5a49b..1a383a96f 100644 --- a/spec/lib/carto/sgmap/api_spec.rb +++ b/spec/lib/carto/sgmap/api_spec.rb @@ -20,6 +20,16 @@ describe CARTO::SGMAP::API do end end + context 'when request return 500' do + let(:geojson) { File.read('spec/support/files/geojson/request_qp.json') } + let(:status) { 500 } + let(:body) { 'toto' } + + it 'raises RestClient::ResourceNotFound' do + expect { subject }.to raise_error(RestClient::ResourceNotFound) + end + end + context 'when geojson exist' do let(:geojson) { File.read('spec/support/files/geojson/request_qp.json') } let(:status) { 200 }