mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Request#check_method no longer breaks when :en is not available locale
Request#check_method would use to_sentence(locale: :en), which breaks when I18n.available_locales does not include :en and I18n.enforce_available_locales is true (default). Inlined to_sentence functionality to solve this.
This commit is contained in:
parent
344ec1b6a7
commit
e86cadc257
2 changed files with 17 additions and 1 deletions
|
@ -341,7 +341,7 @@ module ActionDispatch
|
|||
|
||||
private
|
||||
def check_method(name)
|
||||
HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
|
||||
HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS[0...-1].join(', ')}, and #{HTTP_METHODS[-1]}")
|
||||
name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -683,6 +683,22 @@ class RequestMethod < BaseRequestTest
|
|||
end
|
||||
end
|
||||
|
||||
test "exception on invalid HTTP method unaffected by I18n settings" do
|
||||
old_locales = I18n.available_locales
|
||||
old_enforce = I18n.config.enforce_available_locales
|
||||
|
||||
begin
|
||||
I18n.available_locales = [:nl]
|
||||
I18n.config.enforce_available_locales = true
|
||||
assert_raise(ActionController::UnknownHttpMethod) do
|
||||
stub_request('REQUEST_METHOD' => '_RANDOM_METHOD').method
|
||||
end
|
||||
ensure
|
||||
I18n.available_locales = old_locales
|
||||
I18n.config.enforce_available_locales = old_enforce
|
||||
end
|
||||
end
|
||||
|
||||
test "post masquerading as patch" do
|
||||
request = stub_request(
|
||||
'REQUEST_METHOD' => 'PATCH',
|
||||
|
|
Loading…
Reference in a new issue