From 65809f8ea0b1df793812859c158bbffc8637b806 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 13 Jul 2020 17:36:28 +0200 Subject: [PATCH] config: flip action_dispatch_return_only_media_type_on_content_type This makes `ActionDispatch::Controller#content_type` return not only the MIME type, but also in some circumstances the charset. Example: ```ruby reponse.content_type == 'text/html; charset=utf-8' ``` The MIME type-only fragment can now be accessed using `#media_type`. Changes to the tests are not stricly necessary (because no charset is present in the actual value), but represent the intent better. --- config/initializers/new_framework_defaults_6_0.rb | 2 +- spec/controllers/instructeurs/procedures_controller_spec.rb | 4 ++-- .../attestation_templates_controller_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/initializers/new_framework_defaults_6_0.rb b/config/initializers/new_framework_defaults_6_0.rb index d5667abbf..38c836561 100644 --- a/config/initializers/new_framework_defaults_6_0.rb +++ b/config/initializers/new_framework_defaults_6_0.rb @@ -17,7 +17,7 @@ Rails.application.config.action_view.default_enforce_utf8 = false Rails.application.config.action_dispatch.use_cookies_with_metadata = true # Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. -# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false +Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false # Return false instead of self when enqueuing is aborted from a callback. # Rails.application.config.active_job.return_false_on_aborted_enqueue = true diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index d32d7dffa..7e5f2e561 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -540,8 +540,8 @@ describe Instructeurs::ProceduresController, type: :controller do format: :js end - it "responses in the correct format" do - expect(response.content_type).to eq "text/javascript" + it 'responds in the correct format' do + expect(response.media_type).to eq('text/javascript') expect(response).to have_http_status(:ok) end end diff --git a/spec/controllers/new_administrateur/attestation_templates_controller_spec.rb b/spec/controllers/new_administrateur/attestation_templates_controller_spec.rb index 83079adc6..4e50739e9 100644 --- a/spec/controllers/new_administrateur/attestation_templates_controller_spec.rb +++ b/spec/controllers/new_administrateur/attestation_templates_controller_spec.rb @@ -23,7 +23,7 @@ describe NewAdministrateur::AttestationTemplatesController, type: :controller do render_views it 'renders a PDF' do expect(subject.status).to eq(200) - expect(subject.content_type).to eq('application/pdf') + expect(subject.media_type).to eq('application/pdf') end end