diff options
author | brainopia <brainopia@evilmartians.com> | 2012-02-04 01:44:04 +0400 |
---|---|---|
committer | brainopia <brainopia@evilmartians.com> | 2012-02-04 12:07:16 +0400 |
commit | fbd45241ab5db57e6030e2cba19756429035a4b0 (patch) | |
tree | ce8939b8f5cad7e6518a50ed78a1a8077b666fa5 | |
parent | 6831e118ea6949e9d88e457ab6c4ab654de4cb7d (diff) | |
download | rack-fbd45241ab5db57e6030e2cba19756429035a4b0.tar.gz |
Implement Rack::Session::Abstract::SessionHash#destroy
-rw-r--r-- | lib/rack/session/abstract/id.rb | 6 | ||||
-rw-r--r-- | test/spec_session_cookie.rb | 20 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/rack/session/abstract/id.rb b/lib/rack/session/abstract/id.rb index 2baad05a..a5dd1aed 100644 --- a/lib/rack/session/abstract/id.rb +++ b/lib/rack/session/abstract/id.rb @@ -77,6 +77,12 @@ module Rack 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? } diff --git a/test/spec_session_cookie.rb b/test/spec_session_cookie.rb index ffd0d32e..cfea08b2 100644 --- a/test/spec_session_cookie.rb +++ b/test/spec_session_cookie.rb @@ -38,6 +38,11 @@ describe Rack::Session::Cookie do 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 @@ describe Rack::Session::Cookie do 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 |