Permalink
Browse files

Implement Rack::Session::Abstract::SessionHash#destroy

  • Loading branch information...
1 parent 6831e11 commit fbd45241ab5db57e6030e2cba19756429035a4b0 @brainopia brainopia committed Feb 3, 2012
Showing with 26 additions and 0 deletions.
  1. +6 −0 lib/rack/session/abstract/id.rb
  2. +20 −0 test/spec_session_cookie.rb
@@ -77,6 +77,12 @@ def clear
super
end
+ def destroy
+ clear
+ options = @env[ENV_SESSION_OPTIONS_KEY]
+ options[:id] = @by.send(:destroy_session, @env, options[:id], options)
+ end
+
def to_hash
load_for_read!
Hash[self].delete_if { |k,v| v.nil? }
@@ -38,6 +38,11 @@
Rack::Response.new(env["rack.session"].inspect).to_a
end
+ destroy_session = lambda do |env|
+ env["rack.session"].destroy
+ Rack::Response.new("Nothing").to_a
+ end
+
def response_for(options={})
request_options = options.fetch(:request, {})
request_options["HTTP_COOKIE"] = options[:cookie].is_a?(Rack::Response) ?
@@ -124,6 +129,21 @@ def decode(str); @calls << :decode; str; end
response = response_for(:app => renewer, :cookie => response)
response = response_for(:app => only_session_id, :cookie => response)
+ response.body.should.not.equal ""
+ response.body.should.not.equal old_session_id
+ end
+
+ it "destroys session" do
+ response = response_for(:app => incrementor)
+ response = response_for(:app => only_session_id, :cookie => response)
+
+ response.body.should.not.equal ""
+ old_session_id = response.body
+
+ response = response_for(:app => destroy_session, :cookie => response)
+ response = response_for(:app => only_session_id, :cookie => response)
+
+ response.body.should.not.equal ""
response.body.should.not.equal old_session_id
end

0 comments on commit fbd4524

Please sign in to comment.