From 5c2902bda5cdb03b86a45e1ce97e804dad5742c4 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 14 Jun 2016 15:21:32 +0200 Subject: [PATCH 1/5] Filter procedure on /demo page for staging --- app/controllers/demo_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/demo_controller.rb b/app/controllers/demo_controller.rb index 4007676c9..89f1da027 100644 --- a/app/controllers/demo_controller.rb +++ b/app/controllers/demo_controller.rb @@ -6,7 +6,7 @@ class DemoController < ApplicationController return redirect_to root_path if Rails.env.production? smart_listing_create :procedures, - Procedure.where(archived: false), + Procedure.where(archived: false, published: true), partial: "demo/list", array: true end From f58f9d27d97e6db627d18757916c2dd2ae4951a1 Mon Sep 17 00:00:00 2001 From: Guillaume Lazzara Date: Tue, 14 Jun 2016 15:30:23 +0200 Subject: [PATCH 2/5] Enable password reset for Gestionnaires --- .../gestionnaires/passwords_controller.rb | 32 +++++++++++++++++++ .../gestionnaires/passwords/edit.html.haml | 31 ++++++++++++++++++ .../gestionnaires/passwords/new.html.haml | 22 +++++++++++++ .../gestionnaires/sessions/new.html.haml | 3 +- .../gestionnaires/shared/_links.html.erb | 2 ++ config/routes.rb | 7 ++-- 6 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 app/controllers/gestionnaires/passwords_controller.rb create mode 100644 app/views/gestionnaires/passwords/edit.html.haml create mode 100644 app/views/gestionnaires/passwords/new.html.haml create mode 100644 app/views/gestionnaires/shared/_links.html.erb diff --git a/app/controllers/gestionnaires/passwords_controller.rb b/app/controllers/gestionnaires/passwords_controller.rb new file mode 100644 index 000000000..a7a1d1734 --- /dev/null +++ b/app/controllers/gestionnaires/passwords_controller.rb @@ -0,0 +1,32 @@ +class Gestionnaires::PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end + + # POST /resource/password + # def create + # super + # end + + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end + + # PUT /resource/password + # def update + # super + # end + + # protected + + # def after_resetting_password_path_for(resource) + # super(resource) + # end + + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end +end diff --git a/app/views/gestionnaires/passwords/edit.html.haml b/app/views/gestionnaires/passwords/edit.html.haml new file mode 100644 index 000000000..ff4027fe4 --- /dev/null +++ b/app/views/gestionnaires/passwords/edit.html.haml @@ -0,0 +1,31 @@ += devise_error_messages! + +#form_login + = image_tag('logo-tps.png') + %br + %h2#gestionnaire_login Changement de mot de passe + + %br + %br + #new_user + = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| + = f.hidden_field :reset_password_token + %h4 + = f.label 'Nouveau mot de passe' + + .input-group + .input-group-addon + %span.glyphicon.glyphicon-asterisk + = f.password_field :password, autofocus: true, autocomplete: "off", class: 'form-control' + %br + %h4 + = f.label 'Retaper le mot de passe' + .input-group + .input-group-addon + %span.glyphicon.glyphicon-asterisk + = f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' + %br + %br + .actions + = f.submit "Changer", class:'btn btn-primary' + %br \ No newline at end of file diff --git a/app/views/gestionnaires/passwords/new.html.haml b/app/views/gestionnaires/passwords/new.html.haml new file mode 100644 index 000000000..9c15a8ca9 --- /dev/null +++ b/app/views/gestionnaires/passwords/new.html.haml @@ -0,0 +1,22 @@ += devise_error_messages! + +#form_login + = image_tag('logo-tps.png') + %br + %h2#gestionnaire_login Mot de passe oublié + + %br + %br + #new_user + = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| + %h4 + = f.label :email + .input-group + .input-group-addon + %span.glyphicon.glyphicon-user + = f.email_field :email, class: 'form-control', placeholder: 'Email' + %br + %br + .actions + = f.submit "Renvoyer", class:'btn btn-primary' + %br \ No newline at end of file diff --git a/app/views/gestionnaires/sessions/new.html.haml b/app/views/gestionnaires/sessions/new.html.haml index 3a96664d7..a3de3cd1e 100644 --- a/app/views/gestionnaires/sessions/new.html.haml +++ b/app/views/gestionnaires/sessions/new.html.haml @@ -25,4 +25,5 @@ %br .actions = f.submit "Se connecter", class:'btn btn-primary' - %br \ No newline at end of file + %br + = render "gestionnaires/shared/links" diff --git a/app/views/gestionnaires/shared/_links.html.erb b/app/views/gestionnaires/shared/_links.html.erb new file mode 100644 index 000000000..51021059c --- /dev/null +++ b/app/views/gestionnaires/shared/_links.html.erb @@ -0,0 +1,2 @@ +<%= link_to "Mot de passe oublié ?", new_password_path(resource_name) %>
+ diff --git a/config/routes.rb b/config/routes.rb index 3b5f6ebb2..db74fc87f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,8 +9,9 @@ Rails.application.routes.draw do }, skip: [:password, :registrations] devise_for :gestionnaires, controllers: { - sessions: 'gestionnaires/sessions' - }, skip: [:password, :registrations] + sessions: 'gestionnaires/sessions', + passwords: 'gestionnaires/passwords' + }, skip: [:registrations] devise_for :users, controllers: { sessions: 'users/sessions', @@ -25,6 +26,8 @@ Rails.application.routes.draw do devise_scope :gestionnaire do get '/gestionnaires/sign_in/demo' => 'gestionnaires/sessions#demo' + get '/gestionnaires/edit' => 'gestionnaires/registrations#edit', :as => 'edit_gestionnaires_registration' + put '/gestionnaires' => 'gestionnaires/registrations#update', :as => 'gestionnaires_registration' end devise_scope :administrateur do From 7fd2aa40ca4f57cd5214df0b01903570237d4fa8 Mon Sep 17 00:00:00 2001 From: Guillaume Lazzara Date: Tue, 14 Jun 2016 16:00:37 +0200 Subject: [PATCH 3/5] Do not send notification email when comments cannot be saved. --- app/controllers/commentaires_controller.rb | 5 +++-- .../backoffice/commentaires_controller_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/commentaires_controller.rb b/app/controllers/commentaires_controller.rb index f711a4ab5..4a0b75662 100644 --- a/app/controllers/commentaires_controller.rb +++ b/app/controllers/commentaires_controller.rb @@ -22,10 +22,11 @@ class CommentairesController < ApplicationController end @commentaire.body = params['texte_commentaire'] - @commentaire.save unless flash.alert + saved = false + saved = @commentaire.save unless flash.alert if is_gestionnaire? - NotificationMailer.new_answer(@commentaire.dossier).deliver_now! + NotificationMailer.new_answer(@commentaire.dossier).deliver_now! if saved redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id']) elsif current_user.email != @commentaire.dossier.user.email invite = Invite.where(dossier: @commentaire.dossier, user: current_user).first diff --git a/spec/controllers/backoffice/commentaires_controller_spec.rb b/spec/controllers/backoffice/commentaires_controller_spec.rb index a66229f20..a85f0cc99 100644 --- a/spec/controllers/backoffice/commentaires_controller_spec.rb +++ b/spec/controllers/backoffice/commentaires_controller_spec.rb @@ -91,5 +91,17 @@ describe Backoffice::CommentairesController, type: :controller do end end end + + describe 'comment cannot be saved' do + before do + allow_any_instance_of(Commentaire).to receive(:save).and_return(false) + end + it 'Notification email is not sent' do + expect(NotificationMailer).not_to receive(:new_answer) + expect(NotificationMailer).not_to receive(:deliver_now!) + + post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire + end + end end end From 7af785933471ea10f172d1a02b286cadb39d56a6 Mon Sep 17 00:00:00 2001 From: Guillaume Lazzara Date: Wed, 15 Jun 2016 11:34:05 +0200 Subject: [PATCH 4/5] Implement procedure cloning --- Gemfile | 2 + Gemfile.lock | 5 ++- .../admin/procedures_controller.rb | 17 ++++++++ app/models/procedure.rb | 7 ++++ .../admin/procedures/_draft_list.html.haml | 2 + app/views/admin/procedures/_list.html.haml | 2 + config/routes.rb | 1 + .../admin/procedures_controller_spec.rb | 31 ++++++++++++++ spec/models/procedure_spec.rb | 40 +++++++++++++++++++ spec/spec_helper.rb | 7 ++++ 10 files changed, 113 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5bd2a237d..12229eea2 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,8 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc +# Enable deep clone of active record models +gem 'deep_cloneable', '~> 2.2.1' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index 21f55c50e..31a9b9b55 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -119,6 +119,8 @@ GEM sprockets (>= 2.0.0) database_cleaner (1.4.1) debug_inspector (0.0.2) + deep_cloneable (2.2.1) + activerecord (>= 3.1.0, < 5.2.0) devise (3.4.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -634,6 +636,7 @@ DEPENDENCIES coffee-rails (~> 4.1.0) css_splitter database_cleaner + deep_cloneable (~> 2.2.1) devise draper factory_girl @@ -690,4 +693,4 @@ DEPENDENCIES will_paginate-bootstrap BUNDLED WITH - 1.11.2 + 1.12.5 diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 4539cc02f..19e003a70 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -83,6 +83,23 @@ class Admin::ProceduresController < AdminController change_status({archived: params[:archive]}) end + def clone + @procedure = current_administrateur.procedures.find(params[:procedure_id]) + + new_procedure = @procedure.clone + if new_procedure + flash.notice = 'Procédure clonée' + redirect_to edit_admin_procedure_path(id: new_procedure.id) + else + flash.now.alert = @procedure.errors.full_messages.join('
').html_safe + render 'index' + end + + rescue ActiveRecord::RecordNotFound + flash.alert = 'Procédure inéxistante' + redirect_to admin_procedures_path + end + def active_class @active_class = 'active' end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 00aa073b6..5f4de31f6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -58,4 +58,11 @@ class Procedure < ActiveRecord::Base published? end + def clone + procedure = self.deep_clone(include: [ :types_de_piece_justificative, :types_de_champ, :module_api_carto ]) + procedure.archived = false + procedure.published = false + return procedure if procedure.save + end + end diff --git a/app/views/admin/procedures/_draft_list.html.haml b/app/views/admin/procedures/_draft_list.html.haml index 7d3505614..b169f2fc5 100644 --- a/app/views/admin/procedures/_draft_list.html.haml +++ b/app/views/admin/procedures/_draft_list.html.haml @@ -3,6 +3,7 @@ %thead %th#ID= smart_listing.sortable 'ID', 'id' %th#libelle= smart_listing.sortable 'Libellé', 'libelle' + %th#lien Actions - @procedures.each do |procedure| - procedure = procedure.decorate @@ -10,6 +11,7 @@ %td.col-md-1.col-lg-1= procedure.id %td.col-md-6.col-lg-6 = link_to(procedure.libelle, "/admin/procedures/#{procedure.id}") + %td= link_to('cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-xs btn-primary') = smart_listing.paginate = smart_listing.pagination_per_page_links diff --git a/app/views/admin/procedures/_list.html.haml b/app/views/admin/procedures/_list.html.haml index 651583f12..4735d527f 100644 --- a/app/views/admin/procedures/_list.html.haml +++ b/app/views/admin/procedures/_list.html.haml @@ -4,6 +4,7 @@ %th#ID= smart_listing.sortable 'ID', 'id' %th#libelle= smart_listing.sortable 'Libellé', 'libelle' %th#lien Lien + %th#lien Actions - @procedures.each do |procedure| - procedure = procedure.decorate @@ -12,6 +13,7 @@ %td.col-md-6.col-lg-6 = link_to(procedure.libelle, "/admin/procedures/#{procedure.id}") %td= link_to procedure.lien, procedure.lien + %td= link_to('cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-xs btn-primary') = smart_listing.paginate = smart_listing.pagination_per_page_links diff --git a/config/routes.rb b/config/routes.rb index db74fc87f..764b56da0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -100,6 +100,7 @@ Rails.application.routes.draw do put 'archive' => 'procedures#archive', as: :archive put 'publish' => 'procedures#publish', as: :publish + put 'clone' => 'procedures#clone', as: :clone resource :accompagnateurs, only: [:show, :update] diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 11587b94d..8d8779dc3 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -265,4 +265,35 @@ describe Admin::ProceduresController, type: :controller do it { expect(flash[:alert]).to have_content 'Procédure inéxistante' } end end + + describe 'PUT #clone' do + let!(:procedure) { create(:procedure, administrateur: admin) } + subject { put :clone, procedure_id: procedure.id } + + it { expect{ subject }.to change(Procedure, :count).by(1) } + + context 'when admin is the owner of the procedure' do + before do + subject + end + + it 'creates a new procedure and redirect to it' do + expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id) + expect(flash[:notice]).to have_content 'Procédure clonée' + end + end + + context 'when admin is not the owner of the procedure' do + let(:admin_2) { create(:administrateur) } + + before do + sign_out admin + sign_in admin_2 + subject + end + + it { expect(response).to redirect_to :admin_procedures } + it { expect(flash[:alert]).to have_content 'Procédure inéxistante' } + end + end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index b36e64837..f805f0292 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -122,4 +122,44 @@ describe Procedure do it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } end end + + describe 'clone' do + let(:archived) { false } + let(:published) { false } + let(:procedure) { create(:procedure, archived: archived, published: published) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) } + let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) } + subject { procedure.clone } + + it 'should duplicate specific objects with different id' do + expect(subject.id).not_to eq(procedure.id) + expect(subject).to have_same_attributes_as(procedure) + expect(subject.module_api_carto).to have_same_attributes_as(procedure.module_api_carto) + + subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc| + expect(stc).to have_same_attributes_as(ptc) + end + + subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc| + expect(stc).to have_same_attributes_as(ptc) + end + end + + it 'should not duplicate specific related objects' do + expect(subject.dossiers).to eq([]) + expect(subject.gestionnaires).to eq([]) + expect(subject.assign_to).to eq([]) + end + + describe 'procedure status is reset' do + let(:archived) { true } + let(:published) { true } + it 'sets published and archived to false' do + expect(subject.archived).to be_falsey + expect(subject.published).to be_falsey + end + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7411d7377..bca602fe6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -113,4 +113,11 @@ RSpec.configure do |config| end end } + + RSpec::Matchers.define :have_same_attributes_as do |expected| + match do |actual| + ignored = [:id, :procedure_id, :updated_at, :created_at] + actual.attributes.with_indifferent_access.except(*ignored) == expected.attributes.with_indifferent_access.except(*ignored) + end + end end From cc8d2ef4ee113af8f3ef0fda1b49012d0eda43d7 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 20 Jun 2016 13:57:57 +0200 Subject: [PATCH 5/5] New UI and UX for the dossier initialization --- app/assets/javascripts/dossiers.js | 34 +++++ app/assets/stylesheets/application.scss | 3 +- app/assets/stylesheets/etapes.scss | 29 +++++ app/assets/stylesheets/siret.scss | 7 -- app/controllers/users/dossiers_controller.rb | 74 ++++++----- app/facades/dossier_facades.rb | 2 +- app/models/dossier.rb | 6 + app/models/entreprise.rb | 4 +- app/models/etablissement.rb | 2 +- app/services/dossier_service.rb | 68 ++++++++++ app/views/dossiers/_show.html.haml | 32 +++-- app/views/dossiers/etapes/_etape1.html.haml | 19 +++ app/views/dossiers/etapes/_etape2.html.haml | 39 ++++++ app/views/dossiers/new_siret.js.erb | 7 ++ .../users/dossiers/_title_procedure.html.haml | 11 -- app/views/users/dossiers/new.html.haml | 11 -- app/views/users/sessions/new.html.haml | 15 ++- config/routes.rb | 3 + .../users/dossiers_controller_spec.rb | 119 +++++++++++++++--- spec/factories/exercice.rb | 8 ++ spec/factories/rna_information.rb | 11 ++ spec/features/users/complete_demande_spec.rb | 16 ++- spec/features/users/start_demande_spec.rb | 6 +- spec/models/dossier_spec.rb | 31 +++++ spec/views/dossiers/show.html.haml_spec.rb | 1 + .../users/dossiers/new_html.haml_spec.rb | 49 -------- 26 files changed, 451 insertions(+), 156 deletions(-) create mode 100644 app/assets/javascripts/dossiers.js create mode 100644 app/assets/stylesheets/etapes.scss create mode 100644 app/services/dossier_service.rb create mode 100644 app/views/dossiers/etapes/_etape1.html.haml create mode 100644 app/views/dossiers/etapes/_etape2.html.haml create mode 100644 app/views/dossiers/new_siret.js.erb delete mode 100644 app/views/users/dossiers/_title_procedure.html.haml delete mode 100644 app/views/users/dossiers/new.html.haml create mode 100644 spec/factories/exercice.rb create mode 100644 spec/factories/rna_information.rb delete mode 100644 spec/views/users/dossiers/new_html.haml_spec.rb diff --git a/app/assets/javascripts/dossiers.js b/app/assets/javascripts/dossiers.js new file mode 100644 index 000000000..86764fb01 --- /dev/null +++ b/app/assets/javascripts/dossiers.js @@ -0,0 +1,34 @@ +$(document).on('page:load', the_terms); +$(document).ready(the_terms); + +function the_terms() { + var the_terms = $("#dossier_autorisation_donnees"); + + if(the_terms.size() == 0) + return; + + check_value (the_terms); + + the_terms.click(function () { + check_value (the_terms); + }); + + function check_value (the_terms){ + if (the_terms.is(":checked")) { + $("#etape_suivante").removeAttr("disabled"); + } else { + $("#etape_suivante").attr("disabled", "disabled"); + } + } +} + +function error_form_siret(invalid_siret){ + $("input[type='submit']").removeClass('btn-success').addClass('btn-danger').val('Erreur SIRET'); + $("#dossier_siret").addClass('input-error').val(invalid_siret).on('input', reset_form_siret); + +} + +function reset_form_siret(){ + $("input[type='submit']").removeClass('btn-danger').addClass('btn-success').val('Valider'); + $("#dossier_siret").removeClass('input-error'); +} \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index c28c00141..92fa141f8 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -186,7 +186,8 @@ div.pagination { margin-bottom: 0px; } -.alert.alert-success.move_up { +.alert.alert-success.move_up, +.alert.alert-danger.siret{ position: absolute; top: 0px; left: 0; diff --git a/app/assets/stylesheets/etapes.scss b/app/assets/stylesheets/etapes.scss new file mode 100644 index 000000000..b9f307024 --- /dev/null +++ b/app/assets/stylesheets/etapes.scss @@ -0,0 +1,29 @@ +.etapes_menu{ + h3 { + margin-left: 3%; + } + padding-right: 0 !important; +} + +.etapes_informations { + padding-left: 0 !important; +} + +.etape{ + margin-bottom: 0px; +} + +.etape_2{ + .etapes_menu{ + #dossier_siret{ + width: 200px; + } + + button{ + margin-top: 8px; + } + } + .etapes_informations{ + padding-top: 15px; + } +} \ No newline at end of file diff --git a/app/assets/stylesheets/siret.scss b/app/assets/stylesheets/siret.scss index cfbf10c3c..0bf56056a 100644 --- a/app/assets/stylesheets/siret.scss +++ b/app/assets/stylesheets/siret.scss @@ -6,13 +6,6 @@ display: none; } -#dossier_siret { - margin-bottom: 10px; - margin-left: auto; - margin-right: auto; - width: 200px; -} - #titre_procedure { margin-top: 3%; margin-bottom: 2%; diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index a6aa36f39..50a5d9c9d 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -3,7 +3,7 @@ class Users::DossiersController < UsersController helper SmartListing::Helper before_action :authenticate_user! - before_action :check_siret, only: :create + before_action :check_siret, only: :siret_informations before_action only: [:show] do authorized_routes? self.class @@ -25,50 +25,53 @@ class Users::DossiersController < UsersController def new procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id]) - @dossier = Dossier.new(procedure: procedure) - @siret = params[:siret] || current_user.siret + dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft') + siret = params[:siret] || current_user.siret + update_current_user_siret! siret unless siret.nil? + + redirect_to users_dossier_path(id: dossier.id) rescue ActiveRecord::RecordNotFound error_procedure end def show - @facade = DossierFacades.new params[:id], current_user.email + @facade = facade + @siret = current_user.siret unless current_user.siret.nil? rescue ActiveRecord::RecordNotFound flash.alert = t('errors.messages.dossier_not_found') redirect_to url_for users_dossiers_path end - def create - entreprise_adapter = SIADE::EntrepriseAdapter.new(siren) + def siret_informations + @facade = facade params[:dossier_id] - dossier = Dossier.create(user: current_user, - state: 'draft', - procedure_id: create_params[:procedure_id], - mandataire_social: mandataire_social?(entreprise_adapter.mandataires_sociaux)) + update_current_user_siret! siret - entreprise = dossier.create_entreprise(entreprise_adapter.to_params) + DossierService.new(@facade.dossier, siret, current_user.france_connect_information).dossier_informations! - entreprise.create_rna_information(SIADE::RNAAdapter.new(siret).to_params) - - etablissement = dossier.create_etablissement(SIADE::EtablissementAdapter.new(siret).to_params - .merge({entreprise_id: entreprise.id})) - - etablissement.exercices.create(SIADE::ExercicesAdapter.new(siret).to_params) - - redirect_to url_for(controller: :dossiers, action: :show, id: dossier.id) + @facade = facade params[:dossier_id] + render '/dossiers/new_siret', formats: 'js' rescue RestClient::ResourceNotFound errors_valid_siret rescue ActiveRecord::RecordNotFound flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for(controller: :siret) + redirect_to url_for users_dossiers_path + end + + def change_siret + Dossier.find(params[:dossier_id]).reset! + + @facade = facade params[:dossier_id] + + render '/dossiers/new_siret', formats: :js end def update - @facade = DossierFacades.new params[:id], current_user.email + @facade = facade params[:dossier][:id] if checked_autorisation_donnees? @facade.dossier.update_attributes(update_params) @@ -79,8 +82,8 @@ class Users::DossiersController < UsersController redirect_to url_for(controller: :description, action: :show, dossier_id: @facade.dossier.id) end else - flash.now.alert = 'Les conditions sont obligatoires.' - render 'show' + flash.alert = 'Les conditions sont obligatoires.' + redirect_to users_dossier_path(id: @facade.dossier.id) end end @@ -132,7 +135,9 @@ class Users::DossiersController < UsersController def errors_valid_siret flash.alert = t('errors.messages.invalid_siret') - redirect_to url_for new_users_dossiers_path(procedure_id: create_params[:procedure_id]) + @facade = facade params[:dossier_id] + + render '/dossiers/new_siret', formats: :js, locals: {invalid_siret: siret} end def update_params @@ -147,28 +152,21 @@ class Users::DossiersController < UsersController create_params[:siret] end - def siren - siret[0..8] - end - def create_params - params.require(:dossier).permit(:siret, :procedure_id) + params.require(:dossier).permit(:siret) end def error_procedure flash.alert = t('errors.messages.procedure_not_found') + redirect_to url_for users_dossiers_path end - def mandataire_social? mandataires_list - unless current_user.france_connect_information.nil? - mandataires_list.each do |mandataire| - return true if mandataire[:nom].upcase == current_user.family_name.upcase && - mandataire[:prenom].upcase == current_user.given_name.upcase && - mandataire[:date_naissance_timestamp] == current_user.birthdate.to_time.to_i - end - end + def update_current_user_siret! siret + current_user.update_attributes(siret: siret) + end - false + def facade id = params[:id] + DossierFacades.new id, current_user.email end end diff --git a/app/facades/dossier_facades.rb b/app/facades/dossier_facades.rb index 56b63d39c..55d4728da 100644 --- a/app/facades/dossier_facades.rb +++ b/app/facades/dossier_facades.rb @@ -15,7 +15,7 @@ class DossierFacades end def entreprise - @dossier.entreprise.decorate + @dossier.entreprise.decorate unless @dossier.entreprise.nil? end def etablissement diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 7c00a303f..354cdb661 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -193,4 +193,10 @@ class Dossier < ActiveRecord::Base entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map {|k, v| ["entreprise.#{k}", v] }.to_h dossier_attr.merge(etablissement_attr).merge(entreprise_attr) end + + def reset! + entreprise.destroy unless entreprise.nil? + + update_attributes(autorisation_donnees: false) + end end diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index 0e0ab79eb..382a64c28 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -1,5 +1,5 @@ class Entreprise < ActiveRecord::Base belongs_to :dossier - has_one :etablissement - has_one :rna_information + has_one :etablissement, dependent: :destroy + has_one :rna_information, dependent: :destroy end diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 9fee925cd..9d09b9787 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -2,7 +2,7 @@ class Etablissement < ActiveRecord::Base belongs_to :dossier belongs_to :entreprise - has_many :exercices + has_many :exercices, dependent: :destroy def geo_adresse [numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ') diff --git a/app/services/dossier_service.rb b/app/services/dossier_service.rb new file mode 100644 index 000000000..1c33fd769 --- /dev/null +++ b/app/services/dossier_service.rb @@ -0,0 +1,68 @@ +class DossierService + + def initialize dossier, siret, france_connect_information + @dossier = dossier + @siret = siret + @france_connect_information = france_connect_information + end + + def dossier_informations! + entreprise_thread = Thread.new { + @entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret) + + @dossier.create_entreprise(@entreprise_adapter.to_params) + } + + etablissement_thread = Thread.new { + @etablissement_adapter = SIADE::EtablissementAdapter.new(@siret) + + @dossier.create_etablissement(@etablissement_adapter.to_params) + } + + rna_thread = Thread.new { + @rna_adapter = SIADE::RNAAdapter.new(@siret) + + sleep(0.1) while entreprise_thread.alive? + + @dossier.entreprise.create_rna_information(@rna_adapter.to_params) + } + + exercices_thread = Thread.new { + @exercices_adapter = SIADE::ExercicesAdapter.new(@siret) + + sleep(0.1) while etablissement_thread.alive? + + @dossier.etablissement.exercices.create(@exercices_adapter.to_params) + } + + sleep(0.1) while entreprise_thread.alive? || + etablissement_thread.alive? || + rna_thread.alive? || + exercices_thread.alive? + + @dossier.update_attributes(mandataire_social: mandataire_social?(@entreprise_adapter.mandataires_sociaux)) + @dossier.etablissement.update_attributes(entreprise: @dossier.entreprise) + + @dossier + end + + + def self.siren siret + siret[0..8] + end + + private + + def mandataire_social? mandataires_list + unless @france_connect_information.nil? + + mandataires_list.each do |mandataire| + return true if mandataire[:nom].upcase == @france_connect_information.family_name.upcase && + mandataire[:prenom].upcase == @france_connect_information.given_name.upcase && + mandataire[:date_naissance_timestamp] == @france_connect_information.birthdate.to_time.to_i + end + end + + false + end +end \ No newline at end of file diff --git a/app/views/dossiers/_show.html.haml b/app/views/dossiers/_show.html.haml index 1d1fdf7c8..3b273f41d 100644 --- a/app/views/dossiers/_show.html.haml +++ b/app/views/dossiers/_show.html.haml @@ -1,13 +1,21 @@ -.container#recap_info_entreprise - %h2 Récapitulatif de vos informations (récupérées auprès de l'INSEE et d'INFOGREFFE) - %br +#users_siret_index + + .row.etape.etape_1 + = render partial: '/dossiers/etapes/etape1' + + .row.etape.etape_2 + = render partial: '/dossiers/etapes/etape2' + + -#- if @facade.procedure.module_api_carto.use_api_carto? + -# .row.etape.etape_3 + -# .etape.etapes_menu.col-md-3.col-lg-3 + -# %h3 + -# 3 - Ma zone d'intervention + -# .etape.etapes_informations.col-md-9.col-lg-9 + -# + -#.row.etape.etape_4 + -# .etape.etapes_menu.col-md-3.col-lg-3 + -# %h3 + -# = "#{@facade.procedure.module_api_carto.use_api_carto? ? '4' : '3'} - Mon dossier" + -# .etape.etapes_informations.col-md-9.col-lg-9 - %div.row - = render partial: '/dossiers/infos_entreprise' - %br - = form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f| - %label{ style:'font-weight:normal' } - = f.check_box :autorisation_donnees - J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles. - %br - = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante' \ No newline at end of file diff --git a/app/views/dossiers/etapes/_etape1.html.haml b/app/views/dossiers/etapes/_etape1.html.haml new file mode 100644 index 000000000..917e08b0f --- /dev/null +++ b/app/views/dossiers/etapes/_etape1.html.haml @@ -0,0 +1,19 @@ +.etape.etapes_menu.col-md-3.col-lg-3 + %h3 + Ma procédure + %br + .center + - if @facade.procedure.euro_flag + #euro_flag.flag + =image_tag('drapeau_europe.png') + + #logo_procedure.flag + =image_tag( @facade.procedure.decorate.logo_img ) + +.etape.etapes_informations.col-md-9.col-lg-9 + .row + %h2#titre_procedure.text-info + = @facade.procedure.libelle + + %p{style:'width: 95%;'} + = h @facade.procedure.description.html_safe \ No newline at end of file diff --git a/app/views/dossiers/etapes/_etape2.html.haml b/app/views/dossiers/etapes/_etape2.html.haml new file mode 100644 index 000000000..cb14a694c --- /dev/null +++ b/app/views/dossiers/etapes/_etape2.html.haml @@ -0,0 +1,39 @@ +.etape.etapes_menu.col-md-3.col-lg-3 + %h3 + Mes informations + %br + - unless @facade.entreprise.nil? + .center{style:'margin-left: -5%'} + Vous êtes authentifié avec le SIRET + + %h3.text-success + = @facade.etablissement.siret + = form_for @facade.dossier, url: users_dossier_change_siret_path(dossier_id: @facade.dossier.id), method: :put, remote: true do |f| + = f.submit 'Changer de SIRET', class: %w(btn btn-xs btn-primary) + + +.etape.etapes_informations.col-md-9.col-lg-9 + .row + - if @facade.entreprise.nil? + #new_siret{style:'margin-left: 20%; margin-top: 5%'} + = form_for @facade.dossier, html: {class: 'form-inline'}, url: users_dossier_siret_informations_path(dossier_id: @facade.dossier.id), method: :post, remote: true do |f| + .form-group.form-group-lg + = f.text_field :siret, class: "form-control", placeholder: "Entrez votre Siret", value: @siret + = f.hidden_field :dossier_id, value: @facade.dossier.id + = f.submit 'Valider', class: %w(btn btn-lg btn-success), data: { disable_with: "Recherche en cours ..." } + - else + #recap_info_entreprise + = render partial: '/dossiers/infos_entreprise' + + %p#insee_infogreffe{style:'color:grey; float:right'} + %i + Informations récupérées auprès de l'INSEE et d'INFOGREFFE + + %br + = form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f| + = f.hidden_field :id + %label{ style:'font-weight:normal' } + = f.check_box :autorisation_donnees + J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles. + %br + = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante', disabled: :disabled diff --git a/app/views/dossiers/new_siret.js.erb b/app/views/dossiers/new_siret.js.erb new file mode 100644 index 000000000..803581a3c --- /dev/null +++ b/app/views/dossiers/new_siret.js.erb @@ -0,0 +1,7 @@ +$('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2', locals: { facade: @facade } ) %>"); +the_terms(); + +<% unless flash.empty? %> +error_form_siret('<%= invalid_siret %>'); +<% end %> +<% flash.clear %> \ No newline at end of file diff --git a/app/views/users/dossiers/_title_procedure.html.haml b/app/views/users/dossiers/_title_procedure.html.haml deleted file mode 100644 index 160a05412..000000000 --- a/app/views/users/dossiers/_title_procedure.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -- if @dossier.procedure.euro_flag - #euro_flag.flag - =image_tag('drapeau_europe.png') - -#logo_procedure.flag - =image_tag( @dossier.procedure.decorate.logo_img ) - -%h2#titre_procedure.text-info - = @dossier.procedure.libelle -%p - = h @dossier.procedure.description.html_safe diff --git a/app/views/users/dossiers/new.html.haml b/app/views/users/dossiers/new.html.haml deleted file mode 100644 index 992b2f842..000000000 --- a/app/views/users/dossiers/new.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -.container.center#users_siret_index - .row - %p.lead{id: 'pro_section', style:'padding-top: 120px'} - = render partial: 'title_procedure' - %br - - = form_for @dossier, url: {controller: 'users/dossiers', action: :create}, method: :post do |f| - .form-group.form-group-lg - = f.text_field :siret, class: "form-control", placeholder: "Entrez votre Siret", value: @siret - = f.hidden_field :procedure_id - = f.submit 'Commencer', class: %w(btn btn-lg btn-success), style: 'margin-top:20px;' \ No newline at end of file diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index 028fd6d2a..0cade0fe2 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -2,7 +2,20 @@ %br - if @dossier = link_to 'X', users_no_procedure_url, class: 'btn btn-xs', style:'float: right' - = render partial: 'users/dossiers/title_procedure' + + - if @dossier.procedure.euro_flag + #euro_flag.flag + =image_tag('drapeau_europe.png') + + #logo_procedure.flag + =image_tag( @dossier.procedure.decorate.logo_img ) + + %h2#titre_procedure.text-info + = @dossier.procedure.libelle + %p + = h @dossier.procedure.description.html_safe + + - else = image_tag('logo-tps.png', {id: 'logo_tps'}) %br diff --git a/config/routes.rb b/config/routes.rb index 3b5f6ebb2..d142cadda 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -73,6 +73,9 @@ Rails.application.routes.draw do post '/carte' => 'carte#save' put '/archive' => 'dossiers#archive' + + post '/siret_informations' => 'dossiers#siret_informations' + put '/change_siret' => 'dossiers#change_siret' end resource :dossiers end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 55b311b8b..4514cf689 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -5,18 +5,20 @@ describe Users::DossiersController, type: :controller do let(:procedure) { create(:procedure, :published) } let(:procedure_id) { procedure.id } - let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + let(:dossier) { create(:dossier, user: user, procedure: procedure) } let(:dossier_id) { dossier.id } let(:siret_not_found) { 999_999_999_999 } let(:rna_status) { 404 } let(:rna_body) { '' } + let(:user) { create :user } + let(:exercices_status) { 200 } let(:exercices_body) { File.read('spec/support/files/exercices.json') } - let(:siren) { dossier.siren } - let(:siret) { dossier.siret } + let(:siren) { '440117620' } + let(:siret) { '44011762001530' } let(:siret_with_whitespaces) { '440 1176 2001 530' } let(:bad_siret) { 1 } @@ -55,10 +57,66 @@ describe Users::DossiersController, type: :controller do context 'when procedure_id is valid' do context 'when user is logged in' do before do - sign_in create(:user) + sign_in user end - it { is_expected.to have_http_status(:success) } + it { is_expected.to have_http_status(302) } + it { is_expected.to redirect_to users_dossier_path(id: Dossier.last) } + + it { expect { subject }.to change(Dossier, :count).by 1 } + + describe 'save user siret' do + + context 'when user have not a saved siret' do + context 'when siret is present on request' do + subject { get :new, procedure_id: procedure_id, siret: siret } + + before do + subject + user.reload + end + + it { expect(user.siret).to eq siret } + end + + context 'when siret is not present on the request' do + before do + subject + user.reload + end + + it { expect(user.siret).to eq nil } + end + end + + context 'when user have a saved siret' do + before do + user.siret = '53029478400026' + user.save + user.reload + end + + context 'when siret is present on request' do + subject { get :new, procedure_id: procedure_id, siret: siret } + + before do + subject + user.reload + end + + it { expect(user.siret).to eq siret } + end + + context 'when siret is not present on the request' do + before do + subject + user.reload + end + + it { expect(user.siret).to eq '53029478400026' } + end + end + end context 'when procedure is archived' do let(:procedure) { create(:procedure, archived: 'true') } @@ -68,6 +126,7 @@ describe Users::DossiersController, type: :controller do end context 'when user is not logged' do it { is_expected.to have_http_status(302) } + it { is_expected.to redirect_to new_user_session_path } end end @@ -75,7 +134,7 @@ describe Users::DossiersController, type: :controller do let(:procedure_id) { 0 } before do - sign_in create(:user) + sign_in user end it { is_expected.to redirect_to users_dossiers_path } @@ -85,7 +144,7 @@ describe Users::DossiersController, type: :controller do let(:procedure) { create(:procedure, published: false) } before do - sign_in create(:user) + sign_in user end it { is_expected.to redirect_to users_dossiers_path } @@ -93,7 +152,7 @@ describe Users::DossiersController, type: :controller do end end - describe 'POST #create' do + describe 'POST #siret_informations' do before do stub_request(:get, "https://api-dev.apientreprise.fr/v2/etablissements/#{siret_not_found}?token=#{SIADETOKEN}") .to_return(status: 404, body: 'fake body') @@ -109,6 +168,8 @@ describe Users::DossiersController, type: :controller do stub_request(:get, "https://api-dev.apientreprise.fr/v1/associations/#{siret}?token=#{SIADETOKEN}") .to_return(status: rna_status, body: rna_body) + + dossier end describe 'dossier attributs' do @@ -119,10 +180,10 @@ describe Users::DossiersController, type: :controller do sign_in user end - subject { post :create, dossier: {siret: example_siret, procedure_id: Procedure.last} } + subject { post :siret_informations, dossier_id: dossier.id, dossier: {siret: example_siret} } it 'create a dossier' do - expect { subject }.to change { Dossier.count }.by(1) + expect { subject }.to change { Dossier.count }.by(0) end it 'creates entreprise' do @@ -238,27 +299,32 @@ describe Users::DossiersController, type: :controller do context 'with non existant siret' do before do - sign_in create(:user) + sign_in user + subject end let(:siret_not_found) { '11111111111111' } - subject { post :create, dossier: {siret: siret_not_found, procedure_id: procedure.id} } + subject { post :siret_informations, dossier_id: dossier.id, dossier: {siret: siret_not_found} } + it 'does not create new dossier' do expect { subject }.not_to change { Dossier.count } end - it 'redirects to show' do - expect(subject).to redirect_to new_users_dossiers_path(procedure_id: procedure_id) - end + it { expect(response.status).to eq 200 } + it { expect(flash.alert).to eq 'Le siret est incorrect' } + it { expect(response.to_a[2]).to be_an_instance_of ActionDispatch::Response::RackBody } end end end describe 'PUT #update' do + subject { put :update, id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: autorisation_donnees} } + before do sign_in dossier.user - put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees} + subject end + context 'when Checkbox is checked' do let(:autorisation_donnees) { '1' } @@ -272,7 +338,7 @@ describe Users::DossiersController, type: :controller do let(:procedure) { create(:procedure, :with_api_carto) } before do - put :update, id: dossier_id, dossier: {autorisation_donnees: autorisation_donnees} + subject end it 'redirects to carte' do expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id) @@ -295,6 +361,25 @@ describe Users::DossiersController, type: :controller do dossier.reload expect(dossier.autorisation_donnees).to be_falsy end + + it { is_expected.to redirect_to users_dossier_path(id: dossier.id) } + end + end + + describe 'PUT #change_siret' do + let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } + + subject { put :change_siret, dossier_id: dossier.id } + + before do + sign_in user + end + + it { expect(subject.status).to eq 200 } + + it 'function dossier.reset! is call' do + expect_any_instance_of(Dossier).to receive(:reset!) + subject end end diff --git a/spec/factories/exercice.rb b/spec/factories/exercice.rb new file mode 100644 index 000000000..bf804d551 --- /dev/null +++ b/spec/factories/exercice.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :exercice do + ca '12345678' + dateFinExercice "2014-12-30 23:00:00" + date_fin_exercice_timestamp 1419980400 + association :etablissement, factory: [:etablissement] + end +end diff --git a/spec/factories/rna_information.rb b/spec/factories/rna_information.rb new file mode 100644 index 000000000..70aef163d --- /dev/null +++ b/spec/factories/rna_information.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :rna_information do + association_id "W072000535" + titre "ASSOCIATION POUR LA PROMOTION DE SPECTACLES AU CHATEAU DE ROCHEMAURE" + objet "mise en oeuvre et réalisation de spectacles au chateau de rochemaure" + date_creation "1990-04-24" + date_declaration "2014-11-28" + date_publication "1990-05-16" + association :entreprise, factory: [:entreprise] + end +end diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb index 0f219c031..c028bd2a2 100644 --- a/spec/features/users/complete_demande_spec.rb +++ b/spec/features/users/complete_demande_spec.rb @@ -6,7 +6,7 @@ feature 'user path for dossier creation' do let(:siret) { '53272417600013' } let(:siren) { siret[0...9] } - context 'user arrives on siret page' do + context 'user arrives on siret page', js: true do before do visit new_users_dossiers_path(procedure_id: procedure.id) end @@ -39,11 +39,23 @@ feature 'user path for dossier creation' do .to_return(status: 404, body: '') page.find_by_id('dossier_siret').set siret - page.click_on 'Commencer' + page.click_on 'Valider' end + scenario 'user is on page recap info entreprise' do expect(page).to have_css('#recap_info_entreprise') end + + context 'when user would like change siret' do + before do + page.click_on('Changer de SIRET') + end + + scenario 'redirects to siret page' do + expect(page).to have_css('#dossier_siret') + end + end + context 'when validating info entreprise recap page' do before do page.check('dossier_autorisation_donnees') diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb index 56c52d81b..664fc8729 100644 --- a/spec/features/users/start_demande_spec.rb +++ b/spec/features/users/start_demande_spec.rb @@ -6,7 +6,7 @@ feature 'user arrive on siret page' do let(:siret) { '42149333900020' } let(:siren) { siret[0...9] } - context 'when user is not logged in' do + context 'when user is not logged in', js: true do before do visit new_users_dossiers_path(procedure_id: procedure.id) end @@ -22,7 +22,7 @@ feature 'user arrive on siret page' do end end scenario 'he is redirected to siret page to enter a siret' do - expect(page).to have_css('#pro_section') + expect(page).to have_css('#new_siret') end context 'when enter a siret' do before do @@ -36,7 +36,7 @@ feature 'user arrive on siret page' do .to_return(status: 404, body: '') page.find_by_id('dossier_siret').set siret - page.click_on 'Commencer' + page.click_on 'Valider' end scenario 'he is redirected to recap info entreprise page' do expect(page).to have_css('#recap_info_entreprise') diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 0952b3592..ff1ba94a7 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -563,4 +563,35 @@ describe Dossier do it { expect(subject['entreprise.prenom']).to be_nil } end + describe '#reset!' do + let!(:dossier) { create :dossier, :with_entreprise, autorisation_donnees: true } + let!(:rna_information) { create :rna_information, entreprise: dossier.entreprise } + let!(:exercice) { create :exercice, etablissement: dossier.etablissement } + + subject { dossier.reset! } + + it { expect(dossier.entreprise).not_to be_nil } + it { expect(dossier.etablissement).not_to be_nil } + it { expect(dossier.etablissement.exercices).not_to be_empty } + it { expect(dossier.etablissement.exercices.size).to eq 1 } + it { expect(dossier.entreprise.rna_information).not_to be_nil } + it { expect(dossier.autorisation_donnees).to be_truthy } + + it { expect{subject}.to change(RNAInformation, :count).by(-1) } + it { expect{subject}.to change(Exercice, :count).by(-1) } + + it { expect{subject}.to change(Entreprise, :count).by(-1) } + it { expect{subject}.to change(Etablissement, :count).by(-1) } + + context 'when method reset! is call' do + before do + subject + dossier.reload + end + + it { expect(dossier.entreprise).to be_nil } + it { expect(dossier.etablissement).to be_nil } + it { expect(dossier.autorisation_donnees).to be_falsey } + end + end end diff --git a/spec/views/dossiers/show.html.haml_spec.rb b/spec/views/dossiers/show.html.haml_spec.rb index dd79af9bb..7c5bfba17 100644 --- a/spec/views/dossiers/show.html.haml_spec.rb +++ b/spec/views/dossiers/show.html.haml_spec.rb @@ -9,6 +9,7 @@ describe 'dossiers/show.html.haml', type: :view do render end + it 'have autorisation_donnees check box' do expect(rendered).to have_css('#dossier_autorisation_donnees') end diff --git a/spec/views/users/dossiers/new_html.haml_spec.rb b/spec/views/users/dossiers/new_html.haml_spec.rb deleted file mode 100644 index f2fa59422..000000000 --- a/spec/views/users/dossiers/new_html.haml_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'spec_helper' - -describe 'users/dossiers/new.html.haml', type: :view, vcr: { cassette_name: 'user_dossier_new_html' } do - let(:user) { create(:user) } - let(:euro_flag) { false } - let(:cerfa_flag) { false } - let(:logo) { '' } - let(:procedure) { create(:procedure, euro_flag: euro_flag, cerfa_flag: cerfa_flag, logo: logo) } - let!(:dossier) { create(:dossier, procedure: procedure, user: user).decorate } - - before do - sign_in user - - assign(:dossier, dossier.decorate) - render - end - - subject { rendered } - - it { is_expected.to have_css('#users_siret_index') } - - describe 'euro flag' do - context 'euro flag is not present' do - it { is_expected.not_to have_css('#euro_flag.flag') } - end - - context 'euro flag is present' do - let(:euro_flag) { true } - it { is_expected.to have_css('#euro_flag.flag') } - end - end - - describe 'logo procedure' do - context 'procedure have no logo' do - it 'TPS logo is present' do - is_expected.to match(/src="\/assets\/logo-tps-.*\.png"/) - end - end - - context 'procedure have logo' do - # let(:logo) { fixture_file_upload('spec/support/files/logo_test_procedure.png', 'image/png') } - let(:logo) { File.new(File.join(::Rails.root.to_s, "/spec/support/files", "logo_test_procedure.png")) } - - it 'Procedure logo is present' do - is_expected.to have_css("img[src='#{procedure.logo}']") - end - end - end -end \ No newline at end of file