Always expand */*

This commit is contained in:
José Valim 2011-05-07 23:43:25 +02:00
parent fadd1fa3d3
commit 0a1ba4eab0
2 changed files with 5 additions and 8 deletions

View File

@ -167,15 +167,12 @@ module ActionView
@frozen_formats = true
end
# Overload formats= to reject ["*/*"] values.
# Overload formats= to expand ["*/*"] values and automatically
# add :html as fallback to :js.
def formats=(values)
if values
values.pop if values.last == "*/*"
if values.size == 0
values = nil
elsif values == [:js]
values << :html
end
values.concat(_formats_defaults) if values.delete "*/*"
values << :html if values == [:js]
end
super(values)
end

View File

@ -53,7 +53,7 @@ class LookupContextTest < ActiveSupport::TestCase
test "handles explicitly defined */* formats fallback to :js" do
@lookup_context.formats = [:js, Mime::ALL]
assert_equal [:js, :html], @lookup_context.formats
assert_equal [:js, *Mime::SET.symbols], @lookup_context.formats
end
test "adds :html fallback to :js formats" do