diff options
author | John Hawthorn <john@hawthorn.email> | 2019-03-18 10:12:41 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2019-03-18 11:10:52 -0700 |
commit | c555e28a4cf3690a95b5ed108d174f39cedd19b1 (patch) | |
tree | 4c089513e5fb87ce11790ae55c0f04f3f8a70e9b | |
parent | 98d0f93506b0b97804d0d510ffcc435af9b2a2d5 (diff) | |
download | rails-c555e28a4cf3690a95b5ed108d174f39cedd19b1.tar.gz rails-c555e28a4cf3690a95b5ed108d174f39cedd19b1.tar.bz2 rails-c555e28a4cf3690a95b5ed108d174f39cedd19b1.zip |
Ignore nil in LookupContext#formats=
This also removes the mutation we were performing on the values being
passed in.
-rw-r--r-- | actionview/lib/action_view/lookup_context.rb | 1 | ||||
-rw-r--r-- | actionview/test/template/lookup_context_test.rb | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index 2eaf188ecf..a0a2d41948 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -280,6 +280,7 @@ module ActionView # add :html as fallback to :js. def formats=(values) if values + values = values.compact values.concat(default_formats) if values.delete "*/*" if values == [:js] values << :html diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index 537f8ee163..8b61302c32 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -65,6 +65,11 @@ class LookupContextTest < ActiveSupport::TestCase assert_equal Mime::SET.to_a, @lookup_context.formats end + test "ignores nil format" do + @lookup_context.formats = [:html, nil, :text] + assert_equal [:html, :text], @lookup_context.formats + end + test "handles explicitly defined */* formats fallback to :js" do @lookup_context.formats = [:js, Mime::ALL] assert_equal [:js, *Mime::SET.symbols], @lookup_context.formats |