From dc524cf61593a07ac62a9ea14fac590d83bad4b9 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 21 Jul 2022 20:05:05 +0200 Subject: [PATCH] fix(spec): broken spec due to TDD and refacto on former code --- app/models/administrateur.rb | 4 ++-- app/views/administrateurs/archives/index.html.haml | 2 +- app/views/administrateurs/exports/download.turbo_stream.haml | 2 +- .../instructeurs/procedures/download_export.turbo_stream.haml | 2 +- spec/controllers/instructeurs/procedures_controller_spec.rb | 4 ++-- spec/models/administrateur_spec.rb | 1 - spec/system/administrateurs/procedure_administrateurs_spec.rb | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 20e816449..0a2a7df23 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -15,7 +15,7 @@ class Administrateur < ApplicationRecord UNUSED_ADMIN_THRESHOLD = 6.months has_and_belongs_to_many :instructeurs - has_many :administrateurs_procedures, dependent: :destroy + has_many :administrateurs_procedures has_many :procedures, through: :administrateurs_procedures has_many :services @@ -103,7 +103,7 @@ class Administrateur < ApplicationRecord # We can't destroy a service if it has procedures, even if those procedures are archived service.destroy unless service.procedures.with_discarded.any? end - + AdministrateursProcedure.where(administrateur_id: self.id).delete_all destroy end diff --git a/app/views/administrateurs/archives/index.html.haml b/app/views/administrateurs/archives/index.html.haml index aad3870b3..61ac49abe 100644 --- a/app/views/administrateurs/archives/index.html.haml +++ b/app/views/administrateurs/archives/index.html.haml @@ -7,7 +7,7 @@ .container %h1.mb-2 Archives - - # index not renderable as administrateur flagged as manager, so render it anyway + -# index not renderable as administrateur flagged as manager, so render it anyway = render Dossiers::ExportComponent.new(procedure: @procedure, exports: @exports, export_url: method(:download_admin_procedure_exports_path)) = render partial: "shared/archives/notice" diff --git a/app/views/administrateurs/exports/download.turbo_stream.haml b/app/views/administrateurs/exports/download.turbo_stream.haml index 0a9ce6583..4f160d415 100644 --- a/app/views/administrateurs/exports/download.turbo_stream.haml +++ b/app/views/administrateurs/exports/download.turbo_stream.haml @@ -1,4 +1,4 @@ -- # not renderable as administrateur flagged as manager, so render it anyway +-# not renderable as administrateur flagged as manager, so render it anyway - if @can_download_dossiers = turbo_stream.update_all '.procedure-actions' do = render Dossiers::ExportComponent.new(procedure: @procedure, exports: @exports, count: @dossiers_count, export_url: method(:admin_procedure_exports_path)) diff --git a/app/views/instructeurs/procedures/download_export.turbo_stream.haml b/app/views/instructeurs/procedures/download_export.turbo_stream.haml index 7ac08123f..f124bd379 100644 --- a/app/views/instructeurs/procedures/download_export.turbo_stream.haml +++ b/app/views/instructeurs/procedures/download_export.turbo_stream.haml @@ -1,4 +1,4 @@ -- # not renderable as instructeur flagged as manager, so render it anyway +-# not renderable as instructeur flagged as manager, so render it anyway - if @can_download_dossiers - if @statut.nil? = turbo_stream.update_all '.procedure-actions' do diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index f26da91c2..b670416d3 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -499,7 +499,7 @@ describe Instructeurs::ProceduresController, type: :controller do end context 'when the export is ready' do - let(:export) { create(:export, groupe_instructeurs: [gi_1], job_status: 'generated') } + let(:export) { create(:export, groupe_instructeurs: [gi_1, gi_0], job_status: 'generated') } before do export.file.attach(io: StringIO.new('export'), filename: 'file.csv') @@ -512,7 +512,7 @@ describe Instructeurs::ProceduresController, type: :controller do end context 'when another export is ready' do - let(:export) { create(:export, groupe_instructeurs: [gi_0, gi_1]) } + let(:export) { create(:export, groupe_instructeurs: [gi_0]) } before do export.file.attach(io: StringIO.new('export'), filename: 'file.csv') diff --git a/spec/models/administrateur_spec.rb b/spec/models/administrateur_spec.rb index 9da4b2c0c..162da0bd6 100644 --- a/spec/models/administrateur_spec.rb +++ b/spec/models/administrateur_spec.rb @@ -3,7 +3,6 @@ describe Administrateur, type: :model do describe 'associations' do it { is_expected.to have_and_belong_to_many(:instructeurs) } - it { is_expected.to have_and_belong_to_many(:procedures) } end describe "#renew_api_token" do diff --git a/spec/system/administrateurs/procedure_administrateurs_spec.rb b/spec/system/administrateurs/procedure_administrateurs_spec.rb index 183f7f2bb..5a3988e6b 100644 --- a/spec/system/administrateurs/procedure_administrateurs_spec.rb +++ b/spec/system/administrateurs/procedure_administrateurs_spec.rb @@ -14,7 +14,7 @@ describe 'Administrateurs can manage administrateurs', js: true do scenario 'card is clickable' do visit admin_procedure_path(procedure) find('#administrateurs').click - expect(page).to have_css("h1", text: "Administrateurs de « #{procedure.libelle} »") + expect(page).to have_css("h1", text: "Gérer les administrateurs de « #{procedure.libelle} »") end context 'as admin not flagged from manager' do