diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-12-16 15:06:01 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-12-16 15:06:01 -0200 |
commit | 3bdd110dfedb2b8c208f32e045919f6d80fe3d14 (patch) | |
tree | 008a7677c6e0fb3458d644a85922233e2866eb44 /actionpack | |
parent | a328014ff2e1adf9f202308f4e48ba6b32507d3a (diff) | |
parent | e1fb3483d6402bd66c41a12d158fd1c987fac983 (diff) | |
download | rails-3bdd110dfedb2b8c208f32e045919f6d80fe3d14.tar.gz rails-3bdd110dfedb2b8c208f32e045919f6d80fe3d14.tar.bz2 rails-3bdd110dfedb2b8c208f32e045919f6d80fe3d14.zip |
Merge pull request #18052 from timoschilling/reset_variants
allow reseting of request variants
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_negotiation.rb | 3 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index 9c8f65deac..53a98c5d0a 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -72,11 +72,12 @@ module ActionDispatch 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}. " \ diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index beb9085abe..ee8e915610 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -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 |