Permalink
Browse files

adds #expire_cookies to the api

tests for rack-test showing ephemeral and stale cookies are expired #1
  • Loading branch information...
1 parent ebc0191 commit cd30d4507c3bf64b7bd61f2a4ab16afb28d47c6b @nruth committed Oct 15, 2011
Showing with 34 additions and 0 deletions.
  1. +4 −0 lib/show_me_the_cookies.rb
  2. +10 −0 spec/app/set_cookie.rb
  3. +20 −0 spec/request/rack-test_spec.rb
@@ -26,6 +26,10 @@ def show_me_the_cookies
def delete_cookie(cookie_name)
current_driver_adapter.delete_cookie(cookie_name)
end
+
+ def expire_cookies
+ current_driver_adapter.expire_cookies
+ end
private
@@session_cookie_name = nil
@@ -12,4 +12,14 @@
get '/delete/:key' do
response.delete_cookie params[:key], :path => '/'
"Deleting #{params[:key]}"
+end
+
+get '/set_persistent/:key/:value' do
+ response.set_cookie params[:key], {:value => params[:value], :path => '/', :expires => Time.now + 60*60*24*365}
+ "Setting #{params[:key]}=#{params[:value]}"
+end
+
+get '/set_stale/:key/:value' do
+ response.set_cookie params[:key], {:value => params[:value], :path => '/', :expires => Time.now}
+ "Setting #{params[:key]}=#{params[:value]}"
end
@@ -36,5 +36,25 @@
inspect_cookies.should_not match /choc=milk/
end
end
+
+ describe "expire_cookies" do
+ it "removes cookies without expiry times set" do
+ visit '/set/choc/milk'; inspect_cookies.should match /choc=milk/
+ visit '/set/extras/hazlenut'; inspect_cookies.should match /extras=hazlenut/
+ visit '/set/myopic/mice'; inspect_cookies.should match /myopic=mice/
+ expire_cookies
+ inspect_cookies.should_not match /choc=milk/
+ inspect_cookies.should_not match /extras=hazlenut/
+ inspect_cookies.should_not match /myopic=mice/
+ end
+
+ it "removes cookies which are past their expiry time" do
+ visit '/set_stale/rotting/fruit'; inspect_cookies.should match /rotting=fruit/
+ visit '/set_persistent/fresh/vegetables'; inspect_cookies.should match /fresh=vegetables/
+ expire_cookies
+ inspect_cookies.should_not match /rotting=fruit/
+ inspect_cookies.should match /fresh=vegetables/
+ end
+ end
end
end

0 comments on commit cd30d45

Please sign in to comment.