diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 83a12d83b..59ff595ea 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -131,6 +131,15 @@ class Users::DossiersController < UsersController } end + def destroy + dossier = Dossier.find(params[:id]) + if dossier.brouillon? + dossier.destroy + flash.notice = 'Brouillon supprimé' + end + redirect_to url_for users_dossiers_path + end + private def check_siret diff --git a/app/views/users/dossiers/_list.html.haml b/app/views/users/dossiers/_list.html.haml index b64ade177..34139cce4 100644 --- a/app/views/users/dossiers/_list.html.haml +++ b/app/views/users/dossiers/_list.html.haml @@ -5,6 +5,8 @@ %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' + - if @liste == "brouillon" + %th.col-md-2.col-lg-2= 'Action' - @dossiers.each do |dossier| - if dossier.kind_of? Invite -invite = dossier @@ -20,9 +22,9 @@ = link_to(dossier.procedure.libelle, users_dossier_recapitulatif_path(dossier)) unless dossier.brouillon? = link_to(dossier.procedure.libelle, users_dossier_description_path(dossier)) if dossier.brouillon? - %td{id: "dossier_#{dossier.id}_state"}= dossier.display_state %td= dossier.last_update + %td= link_to('X', url_for(controller: 'dossiers', action: :destroy, id: dossier.id), 'data-method' => :delete, class: 'btn-sm btn-danger') if @liste == "brouillon" = smart_listing.paginate = smart_listing.pagination_per_page_links diff --git a/config/fog_credentials.test.yml b/config/fog_credentials.test.yml new file mode 100644 index 000000000..932151ea1 --- /dev/null +++ b/config/fog_credentials.test.yml @@ -0,0 +1,6 @@ +default: + openstack_tenant: "ovh_fake_tenant_name" + openstack_api_key: "ovh_fake_password" + openstack_username: "ovh_fake_username" + openstack_auth_url: "https://auth.cloud.ovh.net/v2.0/tokens" + openstack_region: "SBG1" diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index c4ee69493..d88ae049a 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -388,6 +388,46 @@ describe Users::DossiersController, type: :controller do end end + describe 'DELETE #destroy' do + let(:user) { create(:user) } + let!(:dossier_draft) { create :dossier, state: "draft", user: user } + let!(:dossier_not_draft) { create :dossier, state: "initiated", user: user } + + subject { delete :destroy, id: dossier.id } + + before do + sign_in user + end + + context 'when dossier is draft' do + let(:dossier) { dossier_draft } + + it { expect(subject.status).to eq 302 } + + describe 'flash notice' do + before do + subject + end + + it { expect(flash[:notice]).to be_present } + end + + it 'destroy dossier is call' do + expect_any_instance_of(Dossier).to receive(:destroy) + subject + end + + it { expect { subject }.to change { Dossier.count }.by(-1) } + end + + context 'when dossier is not a draft' do + let(:dossier) { dossier_not_draft } + + it { expect { subject }.to change { Dossier.count }.by(0) } + end + + end + describe 'PUT #change_siret' do let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) } @@ -496,4 +536,4 @@ describe Users::DossiersController, type: :controller do end end -end \ No newline at end of file +end