riak-sessions 0.9.0.beta → 0.9.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,17 +1,18 @@
1
- source "http://rubygems.org/"
1
+ source :rubygems
2
2
 
3
3
  gem 'bundler'
4
4
  gem 'riak-client', :path => "../riak-client"
5
5
  gem 'rack'
6
6
  gem 'rails', '~>3.0.0'
7
- gem 'rspec', '~>2.0.0'
8
- gem 'rspec-rails', '~>2.0.0'
7
+ gem 'rspec', '~>2.4.0'
8
+ gem 'rspec-rails', '~>2.4.0'
9
9
  gem 'rake'
10
10
 
11
- if defined? JRUBY_VERSION
11
+ platforms :mri do
12
+ gem 'yajl-ruby'
13
+ end
14
+
15
+ platforms :jruby do
12
16
  gem 'json'
13
17
  gem 'jruby-openssl'
14
- else
15
- gem 'curb', '>0.6'
16
- gem 'yajl-ruby'
17
18
  end
data/Rakefile CHANGED
@@ -11,8 +11,8 @@ gemspec = Gem::Specification.new do |gem|
11
11
  gem.email = "sean@basho.com"
12
12
  gem.homepage = "http://seancribbs.github.com/ripple"
13
13
  gem.authors = ["Sean Cribbs"]
14
- gem.add_development_dependency "rspec", "~>2.0.0"
15
- gem.add_development_dependency "rspec-rails", "~>2.0.0"
14
+ gem.add_development_dependency "rspec", "~>2.4.0"
15
+ gem.add_development_dependency "rspec-rails", "~>2.4.0"
16
16
  gem.add_development_dependency "yajl-ruby"
17
17
  gem.add_development_dependency "rails", "~>3.0.0"
18
18
  gem.add_development_dependency "rake"
@@ -28,15 +28,15 @@ module Riak
28
28
  # For configuration options, see #initialize.
29
29
  class SessionStore < Rack::Session::Abstract::ID
30
30
  DEFAULT_OPTIONS = Rack::Session::Abstract::ID::DEFAULT_OPTIONS.merge \
31
- :host => "127.0.0.1",
32
- :port => 8098,
33
- :bucket => "_sessions",
34
- :r => 1,
35
- :w => 1,
36
- :dw => 0,
37
- :rw => 1,
38
- :n_val => 2,
39
- :last_write_wins => false
31
+ :host => "127.0.0.1",
32
+ :port => 8098,
33
+ :bucket => "_sessions",
34
+ :r => 1,
35
+ :w => 1,
36
+ :dw => 0,
37
+ :rw => 1,
38
+ :n_val => 2,
39
+ :last_write_wins => false
40
40
 
41
41
 
42
42
  attr_reader :bucket
@@ -68,13 +68,16 @@ module Riak
68
68
 
69
69
  private
70
70
  def get_session(env, session_id)
71
- unless session_id && robject = (bucket.get(session_id) rescue nil)
72
- session_id, robject = generate_sid, bucket.new
73
- robject.key = session_id
74
- robject.data = {}
75
- robject.store
71
+ if session_id && robject = (bucket.get(session_id) rescue nil)
72
+ if stale?(robject)
73
+ bucket.delete(session_id)
74
+ fresh_session
75
+ else
76
+ [session_id, robject.data]
77
+ end
78
+ else
79
+ fresh_session
76
80
  end
77
- [session_id, robject.data]
78
81
  end
79
82
 
80
83
  def set_session(env, session_id, session, options)
@@ -84,6 +87,7 @@ module Riak
84
87
  session_id = generate_sid
85
88
  end
86
89
  robject = bucket.get_or_new(session_id)
90
+ robject.meta['expire-after'] = (Time.now + options[:expire_after]).httpdate if options[:expire_after]
87
91
  robject.data = session
88
92
  robject.store
89
93
  session_id
@@ -91,5 +95,26 @@ module Riak
91
95
  env['rack.errors'].puts $!.inspect
92
96
  false
93
97
  end
98
+
99
+ def destroy_session(env, sid, options)
100
+ bucket.delete(sid)
101
+ generate_sid unless options[:drop]
102
+ end
103
+
104
+ def stale?(robject)
105
+ if robject.meta['expire-after'] && threshold = (Time.httpdate(robject.meta['expire-after'].first) rescue nil)
106
+ threshold < Time.now
107
+ else
108
+ false
109
+ end
110
+ end
111
+
112
+ def fresh_session
113
+ session_id, robject = generate_sid, bucket.new
114
+ robject.key = session_id
115
+ robject.data = {}
116
+ robject.store
117
+ [session_id, robject.data]
118
+ end
94
119
  end
95
120
  end
@@ -47,7 +47,7 @@ module Ripple
47
47
  begin
48
48
  session = @bucket.get(sid).data
49
49
  rescue Riak::FailedRequest => fr
50
- raise fr unless fr.code.to_i == 404
50
+ raise fr unless fr.not_found?
51
51
  end
52
52
  [sid, session]
53
53
  end
@@ -2,48 +2,47 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{riak-sessions}
5
- s.version = "0.9.0.beta"
5
+ s.version = "0.9.0.beta2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sean Cribbs"]
9
- s.date = %q{2010-12-29}
9
+ s.date = %q{2011-03-28}
10
10
  s.description = %q{riak-sessions is a session store backed by Riak, the distributed database by Basho. It includes session implementations for both Rack and Rails 3.}
11
11
  s.email = %q{sean@basho.com}
12
12
  s.files = ["Gemfile", "lib/riak/session_store.rb", "lib/riak-sessions.rb", "lib/ripple/session_store.rb", "Rakefile", "riak-sessions.gemspec", "spec/fixtures/session_autoload_test/session_autoload_test/foo.rb", "spec/riak_session_store_spec.rb", "spec/ripple_session_store_spec.rb", "spec/spec_helper.rb", "spec/support/ripple_session_support.rb", "spec/support/rspec-rails-neuter.rb", "spec/support/test_server.rb", "spec/support/test_server.yml.example"]
13
13
  s.homepage = %q{http://seancribbs.github.com/ripple}
14
14
  s.require_paths = ["lib"]
15
- s.rubygems_version = %q{1.3.7}
15
+ s.rubygems_version = %q{1.6.1}
16
16
  s.summary = %q{riak-sessions is a session store backed by Riak, the distributed database by Basho.}
17
17
  s.test_files = ["spec/riak_session_store_spec.rb", "spec/ripple_session_store_spec.rb"]
18
18
 
19
19
  if s.respond_to? :specification_version then
20
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
21
20
  s.specification_version = 3
22
21
 
23
22
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
- s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
25
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.0.0"])
23
+ s.add_development_dependency(%q<rspec>, ["~> 2.4.0"])
24
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.4.0"])
26
25
  s.add_development_dependency(%q<yajl-ruby>, [">= 0"])
27
26
  s.add_development_dependency(%q<rails>, ["~> 3.0.0"])
28
27
  s.add_development_dependency(%q<rake>, [">= 0"])
29
- s.add_runtime_dependency(%q<riak-client>, ["~> 0.9.0.beta"])
28
+ s.add_runtime_dependency(%q<riak-client>, ["~> 0.9.0.beta2"])
30
29
  s.add_runtime_dependency(%q<rack>, [">= 1.0"])
31
30
  else
32
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
33
- s.add_dependency(%q<rspec-rails>, ["~> 2.0.0"])
31
+ s.add_dependency(%q<rspec>, ["~> 2.4.0"])
32
+ s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
34
33
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
35
34
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
36
35
  s.add_dependency(%q<rake>, [">= 0"])
37
- s.add_dependency(%q<riak-client>, ["~> 0.9.0.beta"])
36
+ s.add_dependency(%q<riak-client>, ["~> 0.9.0.beta2"])
38
37
  s.add_dependency(%q<rack>, [">= 1.0"])
39
38
  end
40
39
  else
41
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
42
- s.add_dependency(%q<rspec-rails>, ["~> 2.0.0"])
40
+ s.add_dependency(%q<rspec>, ["~> 2.4.0"])
41
+ s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
43
42
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
44
43
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
45
44
  s.add_dependency(%q<rake>, [">= 0"])
46
- s.add_dependency(%q<riak-client>, ["~> 0.9.0.beta"])
45
+ s.add_dependency(%q<riak-client>, ["~> 0.9.0.beta2"])
47
46
  s.add_dependency(%q<rack>, [">= 1.0"])
48
47
  end
49
48
  end
@@ -65,20 +65,20 @@ describe Riak::SessionStore do
65
65
  cookie.should_not match(/#{bad_cookie}/)
66
66
  end
67
67
 
68
- # it "maintains freshness" do
69
- # pool = Riak::SessionStore.new(incrementor, :expire_after => 3)
70
- # res = Rack::MockRequest.new(pool).get('/')
71
- # res.body.should include '"counter"=>1'
72
- # cookie = res["Set-Cookie"]
73
- # res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
74
- # res["Set-Cookie"].should == cookie
75
- # res.body.should include '"counter"=>2'
76
- # puts 'Sleeping to expire session' if $DEBUG
77
- # sleep 4
78
- # res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
79
- # res["Set-Cookie"].should_not == cookie
80
- # res.body.should include '"counter"=>1'
81
- # end
68
+ it "maintains freshness" do
69
+ pool = Riak::SessionStore.new(incrementor, :expire_after => 3)
70
+ res = Rack::MockRequest.new(pool).get('/')
71
+ res.body.should include '"counter"=>1'
72
+ cookie = res["Set-Cookie"]
73
+ res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
74
+ res["Set-Cookie"].should == cookie
75
+ res.body.should include '"counter"=>2'
76
+ puts 'Sleeping to expire session' if $DEBUG
77
+ sleep 4
78
+ res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
79
+ res["Set-Cookie"].should_not == cookie
80
+ res.body.should include '"counter"=>1'
81
+ end
82
82
 
83
83
  it "deletes cookies with :drop option" do
84
84
  pool = Riak::SessionStore.new(incrementor)
@@ -12,7 +12,9 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ require 'action_mailer' # Bah, fails on MailerExampleGroup
15
16
  require 'support/rspec-rails-neuter'
17
+ require 'rspec/rails/example/rails_example_group'
16
18
  require 'rspec/rails/example/request_example_group'
17
19
 
18
20
  class RoutedRackApp
@@ -12,12 +12,13 @@ module RSpec
12
12
  end
13
13
  end
14
14
 
15
+ require 'rspec/core'
16
+
15
17
  RSpec::configure do |c|
16
18
  c.backtrace_clean_patterns << /vendor\//
17
19
  c.backtrace_clean_patterns << /lib\/rspec\/rails/
18
20
  end
19
21
 
20
- require 'rspec/core'
21
22
  require 'rspec/rails/extensions'
22
23
  require 'rspec/rails/view_rendering'
23
24
  require 'rspec/rails/adapters'
metadata CHANGED
@@ -1,14 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riak-sessions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31098121
5
- prerelease: true
6
- segments:
7
- - 0
8
- - 9
9
- - 0
10
- - beta
11
- version: 0.9.0.beta
4
+ prerelease: 6
5
+ version: 0.9.0.beta2
12
6
  platform: ruby
13
7
  authors:
14
8
  - Sean Cribbs
@@ -16,7 +10,7 @@ autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
12
 
19
- date: 2010-12-29 00:00:00 -06:00
13
+ date: 2011-03-28 00:00:00 -04:00
20
14
  default_executable:
21
15
  dependencies:
22
16
  - !ruby/object:Gem::Dependency
@@ -27,12 +21,7 @@ dependencies:
27
21
  requirements:
28
22
  - - ~>
29
23
  - !ruby/object:Gem::Version
30
- hash: 15
31
- segments:
32
- - 2
33
- - 0
34
- - 0
35
- version: 2.0.0
24
+ version: 2.4.0
36
25
  type: :development
37
26
  version_requirements: *id001
38
27
  - !ruby/object:Gem::Dependency
@@ -43,12 +32,7 @@ dependencies:
43
32
  requirements:
44
33
  - - ~>
45
34
  - !ruby/object:Gem::Version
46
- hash: 15
47
- segments:
48
- - 2
49
- - 0
50
- - 0
51
- version: 2.0.0
35
+ version: 2.4.0
52
36
  type: :development
53
37
  version_requirements: *id002
54
38
  - !ruby/object:Gem::Dependency
@@ -59,9 +43,6 @@ dependencies:
59
43
  requirements:
60
44
  - - ">="
61
45
  - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
46
  version: "0"
66
47
  type: :development
67
48
  version_requirements: *id003
@@ -73,11 +54,6 @@ dependencies:
73
54
  requirements:
74
55
  - - ~>
75
56
  - !ruby/object:Gem::Version
76
- hash: 7
77
- segments:
78
- - 3
79
- - 0
80
- - 0
81
57
  version: 3.0.0
82
58
  type: :development
83
59
  version_requirements: *id004
@@ -89,9 +65,6 @@ dependencies:
89
65
  requirements:
90
66
  - - ">="
91
67
  - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
68
  version: "0"
96
69
  type: :development
97
70
  version_requirements: *id005
@@ -103,13 +76,7 @@ dependencies:
103
76
  requirements:
104
77
  - - ~>
105
78
  - !ruby/object:Gem::Version
106
- hash: 31098121
107
- segments:
108
- - 0
109
- - 9
110
- - 0
111
- - beta
112
- version: 0.9.0.beta
79
+ version: 0.9.0.beta2
113
80
  type: :runtime
114
81
  version_requirements: *id006
115
82
  - !ruby/object:Gem::Dependency
@@ -120,10 +87,6 @@ dependencies:
120
87
  requirements:
121
88
  - - ">="
122
89
  - !ruby/object:Gem::Version
123
- hash: 15
124
- segments:
125
- - 1
126
- - 0
127
90
  version: "1.0"
128
91
  type: :runtime
129
92
  version_requirements: *id007
@@ -164,25 +127,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
127
  requirements:
165
128
  - - ">="
166
129
  - !ruby/object:Gem::Version
167
- hash: 3
168
- segments:
169
- - 0
170
130
  version: "0"
171
131
  required_rubygems_version: !ruby/object:Gem::Requirement
172
132
  none: false
173
133
  requirements:
174
134
  - - ">"
175
135
  - !ruby/object:Gem::Version
176
- hash: 25
177
- segments:
178
- - 1
179
- - 3
180
- - 1
181
136
  version: 1.3.1
182
137
  requirements: []
183
138
 
184
139
  rubyforge_project:
185
- rubygems_version: 1.3.7
140
+ rubygems_version: 1.6.1
186
141
  signing_key:
187
142
  specification_version: 3
188
143
  summary: riak-sessions is a session store backed by Riak, the distributed database by Basho.