diff options
author | Timo Schilling <timo@schilling.io> | 2014-12-16 11:30:24 +0100 |
---|---|---|
committer | Timo Schilling <timo@schilling.io> | 2014-12-16 11:37:04 +0100 |
commit | e1fb3483d6402bd66c41a12d158fd1c987fac983 (patch) | |
tree | 0b866c170acfb07f15870f28e81a8f304e0f042c /actionpack/test | |
parent | 41dc7fd650b0fcaf8f05f895aab13febac0739ec (diff) | |
download | rails-e1fb3483d6402bd66c41a12d158fd1c987fac983.tar.gz rails-e1fb3483d6402bd66c41a12d158fd1c987fac983.tar.bz2 rails-e1fb3483d6402bd66c41a12d158fd1c987fac983.zip |
allow reseting of request variants
The current implementation of `variants=` don't allow a resetting to nil, wich is the default value.
This results in the following code smell:
```ruby
case request.user_agent
when /iPhone/
request.variants = :phone
when /iPad/
request.variants = :ipad
end
```
With the ability to reset variants to nil, it could be:
```ruby
request.variants = case request.user_agent
when /iPhone/
:phone
when /iPad/
:ipad
end
```
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 7 |
1 files changed, 7 insertions, 0 deletions
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 |