From d7984df7ffc437c4be706ae47874dcae085468fd Mon Sep 17 00:00:00 2001 From: Romain Neuville Date: Tue, 8 Oct 2024 16:54:10 +0200 Subject: [PATCH] fix test --- app/controllers/application_controller.rb | 6 ++++-- app/jobs/application_job.rb | 2 +- app/services/base_service.rb | 2 ++ spec/controllers/users_organisations_controller_spec.rb | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 489e6aad5..21dd00e4a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,8 +36,10 @@ def sync_user_with_rdv_solidarites(user) return if sync.success? respond_to do |format| - format.turbo_stream { flash.now[:error] = "L'usager n'est plus lié à rdv-solidarités: #{sync.errors.join(', ')}" } - format.json { render json: { errors: sync.errors.join(", ") }, status: :unprocessable_entity } + format.turbo_stream do + flash.now[:error] = "L'usager n'est plus lié à rdv-solidarités: #{sync.errors.map(&:to_s)}" + end + format.json { render json: { errors: sync.errors.map(&:to_s) }, status: :unprocessable_entity } end end end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 3ee4d3bcd..5b2d42731 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -22,7 +22,7 @@ def call_service!(service_class, **kwargs) raise( ApplicationJob::FailedServiceError, "Calling service #{service_class} failed in #{self.class}:\n" \ - "Errors: #{service_result.errors.join(', ')}" + "Errors: #{service_result.errors.map(&:to_s)}" ) end end diff --git a/app/services/base_service.rb b/app/services/base_service.rb index df5481a4a..c72265c72 100644 --- a/app/services/base_service.rb +++ b/app/services/base_service.rb @@ -52,6 +52,8 @@ def call private + # On peut ajouter des TemplatedErrorPresenter à errors tout en gardant la possibilité d'ajouter des + # strings simples dans le tableau errors. TemplatedErrorPresenter répond à to_s avec le message def add_custom_error(message:, template_name:, locals: {}) result.errors << TemplatedErrorPresenter.new(message: message, template_name: template_name, locals: locals) end diff --git a/spec/controllers/users_organisations_controller_spec.rb b/spec/controllers/users_organisations_controller_spec.rb index afac5504c..cc6fedcfd 100644 --- a/spec/controllers/users_organisations_controller_spec.rb +++ b/spec/controllers/users_organisations_controller_spec.rb @@ -106,6 +106,7 @@ expect(response).to have_http_status(:see_other) expect(response.location).to eq(department_user_url(department, user)) + expect(flash[:error]).to include("L'usager n'est plus lié à rdv-solidarités: [\"Something went wrong\"]") end end end