mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
modify cookie[]= to support extra cookie options
Using the syntax `cookie[:key, :options => 'hash']='value'`` will now merge the provided hash with the existing @options hash (which allows for changing cookie options on a per-cookie basis).
This commit is contained in:
parent
5d0a23fdcd
commit
f69d7fad03
2 changed files with 11 additions and 2 deletions
|
@ -87,8 +87,10 @@ module Sinatra
|
|||
response_cookies[key.to_s] || request_cookies[key.to_s]
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
@response.set_cookie key.to_s, @options.merge(:value => value)
|
||||
def []=(key, options = {}, value)
|
||||
options = @options.merge(options).merge(:value => value)
|
||||
|
||||
@response.set_cookie key.to_s, options
|
||||
end
|
||||
|
||||
def assoc(key)
|
||||
|
|
|
@ -124,6 +124,13 @@ describe Sinatra::Cookies do
|
|||
cookie_jar['foo'].should be == 'bar'
|
||||
end
|
||||
|
||||
it 'sets a cookie with extra options' do
|
||||
cookie_route do
|
||||
cookies['foo', :path => '/baz'] = 'bar'
|
||||
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'
|
||||
|
|
Loading…
Reference in a new issue