Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix drop bug, bump version

  • Loading branch information...
commit 0c731f8d4bddd405a73b3813c01a520fa1884e70 1 parent 1fad7a2
@nofxx authored
View
2  VERSION
@@ -1 +1 @@
-0.1.7
+0.1.8
View
17 lib/rack/session/tokyo.rb
@@ -5,8 +5,6 @@ class Tokyo < Abstract::ID
DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :tyrant_server => "localhost:1978"
def initialize(app, options = {})
- #options[:expire_after] ||= options[:expires]
- # @default_options = { # :namespace => 'rack:session', # }.merge(@default_options)
super
@mutex = Mutex.new
host, port = *options[:tyrant_server] || @default_options[:tyrant_server].split(":") # @default_options) #options[:cache] ||
@@ -26,9 +24,9 @@ def generate_sid
private
def get_session(env, sid)
- session = Marshal.load(@pool[sid]) if sid
@mutex.lock if env['rack.multithread']
- unless sid and session
+ session = Marshal.load(@pool[sid]) rescue session if sid
+ unless sid && session
env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
session = {}
sid = generate_sid
@@ -45,16 +43,16 @@ def get_session(env, sid)
def set_session(env, sid, new_session, options)
@mutex.lock if env['rack.multithread']
- session = Marshal.load(@pool[sid]) rescue {}
- if options[:renew] or options[:drop]
+ session = Marshal.load(session) if session = @pool[sid]
+ if options[:renew] || options[:drop]
@pool.delete sid
return false if options[:drop]
sid = generate_sid
- @pool[sid] = "0"
+ @pool[sid] = ""
end
old_session = new_session.instance_variable_get('@old') || {}
session = merge_sessions sid, old_session, new_session, session
- @pool[sid] = Marshal.dump(session) #, options])
+ @pool[sid] = options && options[:raw] ? session : Marshal.dump(session)
return sid
rescue => e
warn "#{self} is unable to find server, error: #{e}"
@@ -64,8 +62,7 @@ def set_session(env, sid, new_session, options)
@mutex.unlock if env['rack.multithread']
end
- def merge_sessions(sid, old, new, cur=nil)
- cur ||= {}
+ def merge_sessions(sid, old, new, cur={})
unless Hash === old and Hash === new
warn 'Bad old or new sessions provided.'
return cur
View
37 spec/rack/session/tokyo_spec.rb
@@ -53,7 +53,7 @@ module Session
end
it "survives nonexistant cookies" do
- bad_cookie = "rack.session=blarghfasel"
+ bad_cookie = "rack.session=blsarghfasel"
pool = Rack::Session::Tokyo.new(@incrementor)
res = Rack::MockRequest.new(pool).get("/", "HTTP_COOKIE" => bad_cookie)
res.body.should eql('{"counter"=>1}')
@@ -61,22 +61,21 @@ module Session
cookie.should_not match(/#{bad_cookie}/)
end
- if ENV['SLEEP']
- it "should maintain freshness" do
- pool = Rack::Session::Tokyo.new(@incrementor, :expire_after => 3)
- res = Rack::MockRequest.new(pool).get('/')
- res.body.should include('"counter"=>1')
- cookie = res["Set-Cookie"]
- res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
- res["Set-Cookie"].should == cookie
- res.body.should include('"counter"=>2')
- puts 'Sleeping to expire session' if $DEBUG
- sleep 4
- res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
- res["Set-Cookie"].should_not == cookie
- res.body.should include('"counter"=>1')
- end
- end
+ # Expire isn't supported by cabinet. Implement in ruby?
+ # it "should maintain freshness" do
+ # pool = Rack::Session::Tokyo.new(@incrementor, :expire_after => 3)
+ # res = Rack::MockRequest.new(pool).get('/')
+ # res.body.should include('"counter"=>1')
+ # cookie = res["Set-Cookie"]
+ # res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
+ # res["Set-Cookie"].should == cookie
+ # res.body.should include('"counter"=>2')
+ # puts 'Sleeping to expire session' if $DEBUG
+ # sleep 4
+ # res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
+ # res["Set-Cookie"].should_not == cookie
+ # res.body.should include('"counter"=>1')
+ # end
it "deletes cookies with :drop option" do
pool = Rack::Session::Tokyo.new(@incrementor)
@@ -232,6 +231,10 @@ module Session
session['counter'].should be_nil
session['foo'].should == 'bar'
end
+
+ after(:all) do
+ Rack::Session::Tokyo.new(@incrementor).pool.clear
+ end
end
end
end
View
16 tokyo_store.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{tokyo_store}
- s.version = "0.1.7"
+ s.version = "0.1.8"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marcos Piccinini"]
- s.date = %q{2009-07-03}
+ s.date = %q{2009-07-04}
s.email = %q{x@nofxx.com}
s.extra_rdoc_files = [
"LICENSE",
@@ -19,11 +19,14 @@ Gem::Specification.new do |s|
"README.rdoc",
"Rakefile",
"VERSION",
- "benchmark/tokyo_store.rb",
- "lib/rack/cache/tokyo_cache_store.rb",
+ "benchmark/cache.rb",
+ "lib/cache/tokyo_store.rb",
+ "lib/rack/cache/tokyo_entitystore.rb",
+ "lib/rack/cache/tokyo_metastore.rb",
"lib/rack/session/tokyo.rb",
"lib/tokyo_store.rb",
- "spec/rack/cache/tokyo_cache_spec.rb",
+ "spec/cache/tokyo_store_spec.rb",
+ "spec/rack/cache/tokyo_spec.rb",
"spec/rack/session/tokyo_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
@@ -36,9 +39,10 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.4}
s.summary = %q{Tokyo Tyrant rails session store}
s.test_files = [
- "spec/rack/cache/tokyo_cache_spec.rb",
+ "spec/rack/cache/tokyo_spec.rb",
"spec/rack/session/tokyo_spec.rb",
"spec/tokyo_store_spec.rb",
+ "spec/cache/tokyo_store_spec.rb",
"spec/spec_helper.rb"
]
Please sign in to comment.
Something went wrong with that request. Please try again.