1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Raise in LookupContext#formats= on invalid format

This is a developer quality of life improvement, to ensure that unknown
formats aren't assigned (which it would previously accept, but wouldn't
work 100% correctly due to caching).
This commit is contained in:
John Hawthorn 2019-03-18 10:18:36 -07:00
parent ffc842a099
commit 0eb9e1e51a
2 changed files with 13 additions and 0 deletions

View file

@ -284,6 +284,11 @@ module ActionView
values.concat(default_formats) if values.delete "*/*"
values.uniq!
invalid_types = (values - Template::Types.symbols)
unless invalid_types.empty?
raise ArgumentError, "Invalid formats: #{invalid_types.map(&:inspect).join(", ")}"
end
if values == [:js]
values << :html
@html_fallback_for_js = true

View file

@ -80,6 +80,14 @@ class LookupContextTest < ActiveSupport::TestCase
assert_equal [:js, :html], @lookup_context.formats
end
test "raises on invalid format assignment" do
ex = assert_raises ArgumentError do
@lookup_context.formats = [:html, :javascript]
end
assert_equal "Invalid formats: :javascript", ex.message
end
test "provides getters and setters for locale" do
@lookup_context.locale = :pt
assert_equal :pt, @lookup_context.locale