Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modify cookie[]= to accept a hash of options

Based on [issue #66](sinatra#66)
  • Loading branch information...
commit 9c7240dc945f516781fb0063a84b6f8f67a16cd3 1 parent 1107072
@kylewlacy authored
Showing with 9 additions and 1 deletion.
  1. +2 −1  lib/sinatra/cookies.rb
  2. +7 −0 spec/cookies_spec.rb
View
3  lib/sinatra/cookies.rb
@@ -88,7 +88,8 @@ def [](key)
end
def []=(key, value)
- @response.set_cookie key.to_s, @options.merge(:value => value)
+ options = value.is_a?(Hash) ? value : {:value => value}
+ @response.set_cookie key.to_s, @options.merge(options)
end
def assoc(key)
View
7 spec/cookies_spec.rb
@@ -124,6 +124,13 @@ def cookies(*set_cookies)
cookie_jar['foo'].should be == 'bar'
end
+ it 'sets a cookie with extra options' do
+ cookie_route do
+ cookies['foo'] = {:value => 'bar', :path => '/baz'}
+ response['Set-Cookie'].lines.detect { |l| l.start_with? 'foo=' }
+ end.should include('path=/baz')
+ end
+
it 'adds a value to the cookies hash' do
cookie_route do
cookies['foo'] = 'bar'
Please sign in to comment.
Something went wrong with that request. Please try again.