From 927d977541267b8291ad7c631bf2d4145626efd1 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 20 Dec 2016 17:01:16 +0100 Subject: [PATCH 1/6] Add tests and validator for individual model. --- app/models/individual.rb | 1 + spec/models/individual_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/models/individual.rb b/app/models/individual.rb index 324438c48..761553f61 100644 --- a/app/models/individual.rb +++ b/app/models/individual.rb @@ -3,6 +3,7 @@ class Individual < ActiveRecord::Base validates_uniqueness_of :dossier_id + validates :gender, presence: true, allow_nil: false, allow_blank: false validates :nom, presence: true, allow_nil: false, allow_blank: false validates :prenom, presence: true, allow_nil: false, allow_blank: false validates :birthdate, presence: true, allow_nil: false, allow_blank: false diff --git a/spec/models/individual_spec.rb b/spec/models/individual_spec.rb index e0d02e03b..b8d20aa42 100644 --- a/spec/models/individual_spec.rb +++ b/spec/models/individual_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Individual do + it { is_expected.to have_db_column(:gender) } it { is_expected.to have_db_column(:nom) } it { is_expected.to have_db_column(:prenom) } it { is_expected.to have_db_column(:birthdate) } From 90804c8a334682bd0f32239c9cb4d669abc8cdf2 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 20 Dec 2016 17:02:36 +0100 Subject: [PATCH 2/6] Add tests for individual information saving but TEST FAILED --- app/controllers/users/dossiers_controller.rb | 2 +- .../controllers/users/dossiers_controller_spec.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index b48f72c93..968faf8b3 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -119,7 +119,7 @@ class Users::DossiersController < UsersController @facade.dossier.update_attributes!(update_params) rescue flash.now.alert = @facade.dossier.errors.full_messages.join('
').html_safe - return render 'show' + return redirect_to users_dossier_path(id: @facade.dossier.id) end if @facade.dossier.procedure.module_api_carto.use_api_carto redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id) diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 618b36ce3..3aee0f00e 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -350,13 +350,26 @@ describe Users::DossiersController, type: :controller do end describe 'PUT #update' do - subject { put :update, params: {id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: autorisation_donnees}} } + let(:params) { {id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: autorisation_donnees}} } + subject { put :update, params: params } before do sign_in dossier.user subject end + context 'when procedure is for individual' do + let(:params) { {id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: '1', individual_attributes: individual_params}} } + let(:individual_params) { {id: dossier.individual.id, gender: 'Mr', nom: 'Julien', prenom: 'Xavier', birthdate: '20/01/1991', dossier_id: dossier.id} } + let(:procedure) { create(:procedure, :published, for_individual: true) } + + it { expect(dossier.individual.gender).to eq 'Mr' } + it { expect(dossier.individual.nom).to eq 'Xavier' } + it { expect(dossier.individual.prenom).to eq 'Julien' } + it { expect(dossier.individual.birthdate).to eq '20/01/1991' } + it { expect(dossier.procedure.for_individual).to eq true } + end + context 'when Checkbox is checked' do let(:autorisation_donnees) { '1' } From 646fc37daf3fde35b282246acfe40322b0c5e9d1 Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 20 Dec 2016 17:26:46 +0100 Subject: [PATCH 3/6] Adding feature tests for Accompagnateur, continue on page features, then on dossier show --- app/models/preference_list_dossier.rb | 26 ++++--- .../dossiers_list_gestionnaire_service.rb | 22 +++--- .../backoffice/dossiers/_pref_list.html.haml | 25 +++---- .../backoffice/index_show_procedure_spec.rb | 68 +++++++++++++++++++ .../backoffice/navigate_to_dossier_spec.rb | 2 +- spec/features/users/dossier_index_spec.rb | 6 +- 6 files changed, 114 insertions(+), 35 deletions(-) create mode 100644 spec/features/backoffice/index_show_procedure_spec.rb diff --git a/app/models/preference_list_dossier.rb b/app/models/preference_list_dossier.rb index 0fa14f24e..b7880d5c1 100644 --- a/app/models/preference_list_dossier.rb +++ b/app/models/preference_list_dossier.rb @@ -96,22 +96,26 @@ class PreferenceListDossier < ActiveRecord::Base def self.columns_champs_procedure procedure_id table = 'champs' - Procedure.find(procedure_id).types_de_champ.inject({}) do |acc, type_de_champ| - acc = acc.merge({ - "type_de_champ_#{type_de_champ.id}" => create_column(type_de_champ.libelle, table, type_de_champ.id, 'value', 2) - }) if type_de_champ.field_for_list? - acc + if procedure = Procedure.find_by(id: procedure_id) + procedure.types_de_champ.inject({}) do |acc, type_de_champ| + acc = acc.merge({ + "type_de_champ_#{type_de_champ.id}" => create_column(type_de_champ.libelle, table, type_de_champ.id, 'value', 2) + }) if type_de_champ.field_for_list? + acc + end end end def self.columns_champs_private_procedure procedure_id table = 'champs_private' - Procedure.find(procedure_id).types_de_champ_private.inject({}) do |acc, type_de_champ| - acc = acc.merge({ - "type_de_champ_private_#{type_de_champ.id}" => create_column(type_de_champ.libelle, table, type_de_champ.id, 'value', 2) - }) if type_de_champ.field_for_list? - acc + if procedure = Procedure.find_by(id: procedure_id) + procedure.types_de_champ_private.inject({}) do |acc, type_de_champ| + acc = acc.merge({ + "type_de_champ_private_#{type_de_champ.id}" => create_column(type_de_champ.libelle, table, type_de_champ.id, 'value', 2) + }) if type_de_champ.field_for_list? + acc + end end end @@ -126,4 +130,4 @@ class PreferenceListDossier < ActiveRecord::Base filter: nil } end -end \ No newline at end of file +end diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index 2eb286ea8..85d0b32e5 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -89,20 +89,22 @@ class DossiersListGestionnaireService def change_page! new_page pref = current_preference_smart_listing_page - unless pref.liste == @liste && pref.procedure == @procedure - pref.liste = @liste - pref.procedure = @procedure + if pref + unless pref.liste == @liste && pref.procedure == @procedure + pref.liste = @liste + pref.procedure = @procedure - if new_page.nil? - pref.page = 1 + if new_page.nil? + pref.page = 1 + pref.save + end + end + + unless new_page.nil? + pref.page = new_page pref.save end end - - unless new_page.nil? - pref.page = new_page - pref.save - end end def change_sort! new_sort diff --git a/app/views/backoffice/dossiers/_pref_list.html.haml b/app/views/backoffice/dossiers/_pref_list.html.haml index 3f43e9f93..c410c21b8 100644 --- a/app/views/backoffice/dossiers/_pref_list.html.haml +++ b/app/views/backoffice/dossiers/_pref_list.html.haml @@ -30,17 +30,18 @@ %td.col-sm-5.col-md-5.col-lg-5{style: 'vertical-align: top', colspan: (tables.first == :champs ? 2 : 1)} %h5= tables.first.to_s.gsub('_', ' ').capitalize %ul - - tables.second.each do |columns| - %li - = form_tag backoffice_preference_list_dossier_add_path, method: :post, remote: true do - = hidden_field_tag :libelle, columns.second[:libelle] - = hidden_field_tag :table, columns.second[:table] - = hidden_field_tag :attr, columns.second[:attr] - = hidden_field_tag :attr_decorate, columns.second[:attr_decorate] - = hidden_field_tag :bootstrap_lg, columns.second[:bootstrap_lg] - = hidden_field_tag :procedure_id, @facade_data_view.procedure_id + - if tables.second + - tables.second.each do |columns| + %li + = form_tag backoffice_preference_list_dossier_add_path, method: :post, remote: true do + = hidden_field_tag :libelle, columns.second[:libelle] + = hidden_field_tag :table, columns.second[:table] + = hidden_field_tag :attr, columns.second[:attr] + = hidden_field_tag :attr_decorate, columns.second[:attr_decorate] + = hidden_field_tag :bootstrap_lg, columns.second[:bootstrap_lg] + = hidden_field_tag :procedure_id, @facade_data_view.procedure_id - = columns.second[:libelle] - %button.btn.btn-default.btn-xs{type: :submit, id: "add_pref_list_#{columns.second[:table]}_#{columns.second[:attr]}"} - %i.fa.fa-plus + = columns.second[:libelle] + %button.btn.btn-default.btn-xs{type: :submit, id: "add_pref_list_#{columns.second[:table]}_#{columns.second[:attr]}"} + %i.fa.fa-plus diff --git a/spec/features/backoffice/index_show_procedure_spec.rb b/spec/features/backoffice/index_show_procedure_spec.rb new file mode 100644 index 000000000..b38a37832 --- /dev/null +++ b/spec/features/backoffice/index_show_procedure_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +feature 'As an Accompagnateur I can navigate and use each functionnality around procedures and their dossiers', js: true do + + let(:user) { create(:user) } + let(:gestionnaire) { create(:gestionnaire) } + let(:procedure_1) { create(:procedure, :with_type_de_champ, libelle: 'procedure 1') } + let(:procedure_2) { create(:procedure, :with_type_de_champ, libelle: 'procedure 2') } + + before 'Assign procedures to Accompagnateur and generating dossiers for each' do + create :assign_to, gestionnaire: gestionnaire, procedure: procedure_1 + create :assign_to, gestionnaire: gestionnaire, procedure: procedure_2 + 20.times do + Dossier.create(procedure_id: procedure_1.id.to_s, user: user, state: 'validated') + end + 15.times do + Dossier.create(procedure_id: procedure_2.id.to_s, user: user, state: 'validated') + end + login_as gestionnaire, scope: :gestionnaire + visit backoffice_path + end + + context 'On index' do + + if false + scenario 'Switching between procedures' do + page.all('#procedure_list a').first.click + expect(page).to have_current_path(backoffice_dossiers_procedure_path(id: procedure_1.id.to_s), only_path: true) + expect(page.find('#all_dossiers .count').text).to eq('20 dossiers') + page.all('#procedure_list a').last.click + expect(page).to have_current_path(backoffice_dossiers_procedure_path(id: procedure_2.id.to_s), only_path: true) + expect(page.find('#all_dossiers .count').text).to eq('15 dossiers') + #save_and_open_page + end + + scenario 'Searching with search bar' do + page.find_by_id('search_area').trigger('click') + fill_in 'q', with: '15' + page.find_by_id('search_button').click + page.find_by_id('tr_dossier_15').click + expect(page).to have_current_path("/backoffice/dossiers/15") + end + + scenario 'Following dossier' do + page.all('#procedure_list a').first.click + expect(page.all('#follow_dossiers .smart-listing')[0]['data-item-count']).to eq ("0") + page.find_by_id('all_dossiers').click + expect(page.all('#dossiers_list a').first.text).to eq('Suivre') + page.all('#dossiers_list a').first.click + expect(page.all('#follow_dossiers .smart-listing')[0]['data-item-count']).to eq ("1") + end + end + + scenario 'Using sort' do + end + + if false + scenario 'Using pagination' do + end + + scenario 'Using filter' do + end + + scenario 'Have an export button' do + end + end + end +end diff --git a/spec/features/backoffice/navigate_to_dossier_spec.rb b/spec/features/backoffice/navigate_to_dossier_spec.rb index d65e6d99a..3cb14cbf6 100644 --- a/spec/features/backoffice/navigate_to_dossier_spec.rb +++ b/spec/features/backoffice/navigate_to_dossier_spec.rb @@ -48,4 +48,4 @@ feature 'on backoffice page' do end end end -end \ No newline at end of file +end diff --git a/spec/features/users/dossier_index_spec.rb b/spec/features/users/dossier_index_spec.rb index 2ff4fcb15..b2ee2b601 100644 --- a/spec/features/users/dossier_index_spec.rb +++ b/spec/features/users/dossier_index_spec.rb @@ -41,8 +41,12 @@ feature 'As a User I want to sort and paginate dossiers', js: true do page.find('.next_page a').click wait_for_ajax expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('15') + page.find('.prev a').click + wait_for_ajax + page.find('.prev a').click + wait_for_ajax + expect(page.all(:css, '#dossiers_list tr')[1].text.split(" ").first).to eq('1') end end - end From decde2ee6c704a5ae4988bab94706ffe78485545 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 21 Dec 2016 11:00:05 +0100 Subject: [PATCH 4/6] Fix bug publish procedure with same path --- app/controllers/admin/procedures_controller.rb | 1 + spec/controllers/admin/procedures_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 4d8e44af3..2f7f11d1b 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -105,6 +105,7 @@ class Admin::ProceduresController < AdminController if procedure_path if procedure_path.administrateur_id == current_administrateur.id procedure_path.procedure.archive + procedure_path.delete else @mine = false return render '/admin/procedures/publish', formats: 'js' diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 18fecb450..0ccbbbdb1 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -299,7 +299,7 @@ describe Admin::ProceduresController, type: :controller do it 'archive previous procedure' do expect(procedure2.published).to be_truthy expect(procedure2.archived).to be_truthy - expect(procedure2.path).not_to be_nil + expect(procedure2.path).to be_nil end end From 20a4febeccc1a5cad8abe6a963a84c935e5f2597 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 21 Dec 2016 11:26:33 +0100 Subject: [PATCH 5/6] Adapt UI list for procedure list in admin interface. --- app/views/admin/procedures/_list.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/procedures/_list.html.haml b/app/views/admin/procedures/_list.html.haml index 96be7bd49..f7f00893e 100644 --- a/app/views/admin/procedures/_list.html.haml +++ b/app/views/admin/procedures/_list.html.haml @@ -1,5 +1,5 @@ - unless smart_listing.empty? - %table.table + %table.table#dossiers_list %thead %th#ID= smart_listing.sortable 'ID', 'id' %th#libelle= smart_listing.sortable 'Libellé', 'libelle' @@ -10,12 +10,12 @@ - @procedures.each do |procedure| - procedure = procedure.decorate - %tr + %tr{id: "tr_dossier_#{procedure.id}", 'data-dossier_url' => admin_procedure_path(id: procedure.id)} %td= procedure.id %td.col-md-6.col-lg-6 - = link_to(procedure.libelle, "/admin/procedures/#{procedure.id}") + = procedure.libelle - if @active_class - %td= link_to procedure.lien, procedure.lien, class: 'procedure-lien' + %td= link_to procedure.lien, procedure.lien, class: 'procedure-lien', 'data-method' => :get %td = procedure.created_at_fr %td From e98fc64bcb71a81c2bef26fa39d7fb4d2c567cf1 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 21 Dec 2016 14:00:50 +0100 Subject: [PATCH 6/6] Fix display bug with scrollbar into UI --- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/dossiers.scss | 1 - app/assets/stylesheets/left_pannel.scss | 7 ++++--- app/assets/stylesheets/pref_list_menu.scss | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 00b4d9b93..3748b8f5e 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -46,6 +46,7 @@ form { #wrap { min-height: 100%; margin-bottom: -50px; + overflow: hidden; } #wrap:after { diff --git a/app/assets/stylesheets/dossiers.scss b/app/assets/stylesheets/dossiers.scss index c0804e990..61dcf0a52 100644 --- a/app/assets/stylesheets/dossiers.scss +++ b/app/assets/stylesheets/dossiers.scss @@ -44,7 +44,6 @@ h5 span { #procedure_list { margin-left: -10px; - overflow: scroll; margin-top: 20px; a, a:hover { color: #FFFFFF; diff --git a/app/assets/stylesheets/left_pannel.scss b/app/assets/stylesheets/left_pannel.scss index a4d363495..7debdf58c 100644 --- a/app/assets/stylesheets/left_pannel.scss +++ b/app/assets/stylesheets/left_pannel.scss @@ -1,13 +1,14 @@ #left-pannel { - padding: 60px 0 0 10px; + margin-top: 60px; + padding: 0 0 0 10px; background-color: #003189; - height: 100%; + height: calc(100% - 60px); position: fixed; top: 0; left: 0; bottom: 0; color: white; - overflow: scroll; + overflow-y: scroll; #first-block { font-family: Arial; diff --git a/app/assets/stylesheets/pref_list_menu.scss b/app/assets/stylesheets/pref_list_menu.scss index 0ab24a30d..3251d69fb 100644 --- a/app/assets/stylesheets/pref_list_menu.scss +++ b/app/assets/stylesheets/pref_list_menu.scss @@ -11,7 +11,7 @@ width: 470px; height: calc(100% - 25px); padding: 15px; - overflow: scroll; + overflow-y: scroll; } .open_pref_list {