Skip to content

Commit

Permalink
Merge pull request #18052 from timoschilling/reset_variants
Browse files Browse the repository at this point in the history
allow reseting of request variants
  • Loading branch information
rafaelfranca committed Dec 16, 2014
2 parents a328014 + e1fb348 commit 3bdd110
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion actionpack/lib/action_dispatch/http/mime_negotiation.rb
Expand Up @@ -72,11 +72,12 @@ def formats
end
end
end

# Sets the \variant for template.
def variant=(variant)
if variant.is_a?(Symbol)
@variant = [variant]
elsif variant.is_a?(Array) && variant.any? && variant.all?{ |v| v.is_a?(Symbol) }
elsif variant.nil? || variant.is_a?(Array) && variant.any? && variant.all?{ |v| v.is_a?(Symbol) }
@variant = variant
else
raise ArgumentError, "request.variant must be set to a Symbol or an Array of Symbols, not a #{variant.class}. " \
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/dispatch/request_test.rb
Expand Up @@ -1143,6 +1143,13 @@ class RequestVariant < BaseRequestTest
end
end

test "reset variant" do
request = stub_request

request.variant = nil
assert_equal nil, request.variant
end

test "setting variant with non symbol value" do
request = stub_request
assert_raise ArgumentError do
Expand Down

0 comments on commit 3bdd110

Please sign in to comment.