Skip to content

Commit 3deec36

Browse files
authored
Merge pull request rails#53325 from jeromedalbert/fix-controller-tests-content-type-error
Fix `NoMethodError` when content type is set to nil in tests
2 parents b0c929a + a31553c commit 3deec36

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

actionpack/lib/action_controller/test_case.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def assign_parameters(routes, controller_path, action, parameters, generated_pat
108108
set_header k, "application/x-www-form-urlencoded"
109109
end
110110

111-
case content_mime_type.to_sym
111+
case content_mime_type&.to_sym
112112
when nil
113113
raise "Unknown Content-Type: #{content_type}"
114114
when :json

actionpack/test/controller/test_case_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ def test_params_passing_doesnt_modify_in_place
627627
end
628628
end
629629

630+
test "nil Content-Type header with post request" do
631+
@request.headers["Content-Type"] = nil
632+
assert_raises(match: /Unknown Content-Type/) do
633+
post :render_body
634+
end
635+
end
636+
630637
def test_using_as_json_sets_request_content_type_to_json
631638
post :render_body, params: { bool_value: true, str_value: "string", num_value: 2 }, as: :json
632639

0 commit comments

Comments
 (0)