Skip to content

Commit

Permalink
Implement Rack::Session::Abstract::SessionHash#destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
brainopia committed Feb 4, 2012
1 parent 6831e11 commit fbd4524
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rack/session/abstract/id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? }
Expand Down
20 changes: 20 additions & 0 deletions test/spec_session_cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit fbd4524

Please sign in to comment.