mongo_session_store-rails3 5.0.1 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Gemfile +9 -7
- data/README.md +4 -2
- data/Rakefile +1 -1
- data/lib/mongo_session_store/mongo_store_base.rb +19 -16
- data/lib/mongo_session_store/version.rb +1 -1
- data/spec/integration_with_devise_spec.rb +1 -1
- data/spec/mongo_store_base_spec.rb +42 -0
- data/spec/rails_helper.rb +47 -0
- data/spec/spec_helper.rb +0 -47
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6fb0f3be1ee193468f59e8ceae96d70165c2806
|
4
|
+
data.tar.gz: 57a0d903010ed76a33967e2c8a218c4af890f5e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7024e9286c693e8e68bb8c70818dc85fa3ea56ce9fb62c6789e1c1c63ef82fe41ae41135c9cdb5f209616ac95e7adccd61070bbf5dd0392acb6b5874c7cdf14
|
7
|
+
data.tar.gz: eb4441fbbae34d749b8602a5c44e7bb74beeae362460ac20a86a4b34a772aba508f3694be37356a27cb55b42763efc9fb2dfee199616502eb931b96328cb0f74
|
data/.travis.yml
CHANGED
@@ -3,15 +3,15 @@ script: "rake"
|
|
3
3
|
rvm:
|
4
4
|
- 1.9.3
|
5
5
|
- 2.0.0
|
6
|
-
- 2.1.
|
6
|
+
- 2.1.2
|
7
7
|
- ruby-head
|
8
8
|
- jruby-19mode
|
9
9
|
- jruby-head
|
10
|
-
- rbx
|
10
|
+
- rbx-2.2.9
|
11
11
|
matrix:
|
12
12
|
allow_failures:
|
13
13
|
- rvm: jruby-head
|
14
14
|
- rvm: ruby-head
|
15
|
-
- rvm: rbx
|
15
|
+
- rvm: rbx-2.2.9
|
16
16
|
services:
|
17
17
|
- mongodb
|
data/Gemfile
CHANGED
@@ -2,13 +2,13 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
RAILS_VERS = case ENV['RAILS_VERS']
|
4
4
|
when '3.1'
|
5
|
-
'~>3.1'
|
5
|
+
'~>3.1.12'
|
6
6
|
when '3.2'
|
7
|
-
'~>3.2'
|
7
|
+
'~>3.2.18'
|
8
8
|
when '4.0'
|
9
|
-
'~>4.0'
|
9
|
+
'~>4.0.5'
|
10
10
|
when '4.1'
|
11
|
-
'~>4.1.
|
11
|
+
'~>4.1.2.rc2'
|
12
12
|
when nil
|
13
13
|
nil
|
14
14
|
else
|
@@ -24,10 +24,12 @@ group :development, :test do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if ENV['MONGO_SESSION_STORE_ORM'] == 'mongoid'
|
27
|
-
if ENV['RAILS_VERS'] =~
|
27
|
+
if ENV['RAILS_VERS'] =~ /^4\.\d/
|
28
28
|
gem 'mongoid', '>= 4.0.0.beta1'
|
29
|
-
|
29
|
+
elsif ENV['RAILS_VERS'] =~ /^3\.2\d/
|
30
30
|
gem 'mongoid', '>= 3.1.0'
|
31
|
+
else
|
32
|
+
gem 'mongoid', '>= 3.0.0'
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -35,7 +37,7 @@ group :development, :test do
|
|
35
37
|
gem 'mongo'
|
36
38
|
end
|
37
39
|
|
38
|
-
gem '
|
40
|
+
gem 'pry'
|
39
41
|
|
40
42
|
if RUBY_PLATFORM == 'java'
|
41
43
|
gem 'jdbc-sqlite3'
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# MongoSessionStore [![Build Status](https://travis-ci.org/brianhempel/mongo_session_store.png?branch=master)](https://travis-ci.org/brianhempel/mongo_session_store)
|
1
|
+
# MongoSessionStore [![Build Status](https://travis-ci.org/brianhempel/mongo_session_store.png?branch=master)](https://travis-ci.org/brianhempel/mongo_session_store) [![Gem Version](https://badge.fury.io/rb/mongo_session_store-rails4.svg)](http://badge.fury.io/rb/mongo_session_store-rails4)
|
2
2
|
|
3
3
|
## Description
|
4
4
|
|
5
5
|
MongoSessionStore is a collection of Rails-compatible session stores for MongoMapper and Mongoid, but also included is a generic Mongo store that works with any (or no!) Mongo ODM.
|
6
6
|
|
7
|
-
MongoSessionStore is tested [on Travis CI](https://travis-ci.org/brianhempel/mongo_session_store) against Ruby 1.9.3, 2.0.0, 2.1.
|
7
|
+
MongoSessionStore is tested [on Travis CI](https://travis-ci.org/brianhempel/mongo_session_store) against Ruby 1.9.3, 2.0.0, 2.1.2, and JRuby with Rails 3.1 through 4.1.
|
8
8
|
|
9
9
|
Mongoid users: This gem is compatible with both Mongoid 3 and 4.
|
10
10
|
|
@@ -61,6 +61,8 @@ MongoStore::Session.where('updated_at' => { '$gt' => 2.days.ago })
|
|
61
61
|
|
62
62
|
## Changelog
|
63
63
|
|
64
|
+
5.1.0 generates a new session ID when a session is not found. Previously, when a session ID is provided in the request but the session was not found (because for example, it was removed from Mongo by a sweeper job) a new session with the provided ID would be created. This would cause a write error if two simultaneous requests both create a session with the same ID and both try to insert a new document with that ID.
|
65
|
+
|
64
66
|
5.0.1 suppresses a warning from Mongoid 4 when setting the _id field type to String.
|
65
67
|
|
66
68
|
5.0.0 introduces Rails 4.0 and 4.1 support and Mongoid 4 support alongside the existing Rails 3.1, 3.2, and Mongoid 3 support. Ruby 1.8.7 support is dropped. The database is no longer set automatically for the MongoStore when MongoMapper or Mongoid is present. You have to set the database manually whenever you choose to use the vanilla MongoStore.
|
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require 'action_dispatch/middleware/session/abstract_store'
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
module Session
|
3
5
|
class MongoStoreBase < AbstractStore
|
4
|
-
|
6
|
+
|
5
7
|
SESSION_RECORD_KEY = 'rack.session.record'.freeze
|
6
8
|
begin
|
7
9
|
ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
|
@@ -24,31 +26,31 @@ module ActionDispatch
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def get_session(env, sid)
|
27
|
-
sid
|
28
|
-
|
29
|
-
|
30
|
-
[sid, unpack(session.data)]
|
29
|
+
sid, record = find_or_initialize_session(sid)
|
30
|
+
env[SESSION_RECORD_KEY] = record
|
31
|
+
[sid, unpack(record.data)]
|
31
32
|
end
|
32
33
|
|
33
34
|
def set_session(env, sid, session_data, options = {})
|
34
|
-
record =
|
35
|
+
id, record = get_session_record(env, sid)
|
35
36
|
record.data = pack(session_data)
|
36
37
|
# Rack spec dictates that set_session should return true or false
|
37
38
|
# depending on whether or not the session was saved or not.
|
38
39
|
# However, ActionPack seems to want a session id instead.
|
39
|
-
record.save ?
|
40
|
+
record.save ? id : false
|
40
41
|
end
|
41
42
|
|
42
|
-
def
|
43
|
-
session_class.where(:_id => id).first || session_class.new(:_id =>
|
43
|
+
def find_or_initialize_session(id)
|
44
|
+
session = (id && session_class.where(:_id => id).first) || session_class.new(:_id => generate_sid)
|
45
|
+
[session._id, session]
|
44
46
|
end
|
45
47
|
|
46
|
-
def
|
47
|
-
if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
|
48
|
-
env[SESSION_RECORD_KEY] =
|
49
|
-
else
|
50
|
-
env[SESSION_RECORD_KEY] ||= find_session(sid)
|
48
|
+
def get_session_record(env, sid)
|
49
|
+
if env[ENV_SESSION_OPTIONS_KEY][:id].nil? || !env[SESSION_RECORD_KEY]
|
50
|
+
sid, env[SESSION_RECORD_KEY] = find_or_initialize_session(sid)
|
51
51
|
end
|
52
|
+
|
53
|
+
[sid, env[SESSION_RECORD_KEY]]
|
52
54
|
end
|
53
55
|
|
54
56
|
def destroy_session(env, session_id, options)
|
@@ -58,7 +60,8 @@ module ActionDispatch
|
|
58
60
|
|
59
61
|
def destroy(env)
|
60
62
|
if sid = current_session_id(env)
|
61
|
-
|
63
|
+
_, record = get_session_record(env, sid)
|
64
|
+
record.destroy
|
62
65
|
env[SESSION_RECORD_KEY] = nil
|
63
66
|
end
|
64
67
|
end
|
@@ -74,4 +77,4 @@ module ActionDispatch
|
|
74
77
|
|
75
78
|
end
|
76
79
|
end
|
77
|
-
end
|
80
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'mongo_session_store/mongo_store_base'
|
5
|
+
|
6
|
+
describe ActionDispatch::Session::MongoStoreBase do
|
7
|
+
ENV_SESSION_OPTIONS_KEY = ActionDispatch::Session::MongoStoreBase::ENV_SESSION_OPTIONS_KEY
|
8
|
+
SESSION_RECORD_KEY = ActionDispatch::Session::MongoStoreBase::SESSION_RECORD_KEY
|
9
|
+
|
10
|
+
Session = ActionDispatch::Session::MongoStoreBase::Session = Class.new(OpenStruct)
|
11
|
+
|
12
|
+
before do
|
13
|
+
@app = nil
|
14
|
+
@store = ActionDispatch::Session::MongoStoreBase.new(@app)
|
15
|
+
@env = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#get_session" do
|
19
|
+
it "generates a new session id if given a nil session id" do
|
20
|
+
Session.stub(where: [])
|
21
|
+
|
22
|
+
sid, session_data = @store.send(:get_session, @env, nil)
|
23
|
+
|
24
|
+
sid.should_not == nil
|
25
|
+
session_data.should == nil
|
26
|
+
@env[SESSION_RECORD_KEY].class.should == Session
|
27
|
+
@env[SESSION_RECORD_KEY]._id.should == sid
|
28
|
+
end
|
29
|
+
|
30
|
+
it "generates a new session id if session is not found" do
|
31
|
+
old_sid = SecureRandom.hex
|
32
|
+
Session.stub(where: [])
|
33
|
+
|
34
|
+
sid, session_data = @store.send(:get_session, @env, old_sid)
|
35
|
+
|
36
|
+
sid.should_not == old_sid
|
37
|
+
session_data.should == nil
|
38
|
+
@env[SESSION_RECORD_KEY].class.should == Session
|
39
|
+
@env[SESSION_RECORD_KEY]._id.should == sid
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
rails_version = Rails.version[/^\d\.\d/]
|
5
|
+
require "rails_#{rails_version}_app/config/environment"
|
6
|
+
|
7
|
+
require 'rspec/rails'
|
8
|
+
|
9
|
+
def db
|
10
|
+
if defined?(Mongoid)
|
11
|
+
MongoidStore::Session.mongo_session
|
12
|
+
elsif defined?(MongoMapper)
|
13
|
+
MongoMapper.database
|
14
|
+
elsif defined?(Mongo)
|
15
|
+
Mongo::Connection.new[database_name]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def database_name
|
20
|
+
Rails.application.class.to_s.underscore.sub(/\/.*/, '') + "_" + Rails.env
|
21
|
+
end
|
22
|
+
|
23
|
+
def drop_collections_in(database)
|
24
|
+
database.collections.select { |c| c.name !~ /^system/ }.each(&:drop)
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
config.before :all do
|
29
|
+
unless User.table_exists?
|
30
|
+
load Rails.root.join('db', 'schema.rb')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
config.before :each do
|
35
|
+
drop_collections_in(db)
|
36
|
+
User.delete_all
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "Testing #{ENV["MONGO_SESSION_STORE_ORM"]}_store on Rails #{Rails.version}..."
|
41
|
+
|
42
|
+
case ENV["MONGO_SESSION_STORE_ORM"]
|
43
|
+
when "mongo_mapper"
|
44
|
+
puts "MongoMapper version: #{MongoMapper::Version}"
|
45
|
+
when "mongoid"
|
46
|
+
puts "Mongoid version: #{Mongoid::VERSION}"
|
47
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,50 +3,3 @@ ENV["RAILS_ENV"] = "test"
|
|
3
3
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
$:.unshift File.dirname(__FILE__)
|
6
|
-
|
7
|
-
require 'rails'
|
8
|
-
|
9
|
-
rails_version = Rails.version[/^\d\.\d/]
|
10
|
-
require "rails_#{rails_version}_app/config/environment"
|
11
|
-
|
12
|
-
require 'rspec/rails'
|
13
|
-
|
14
|
-
def db
|
15
|
-
if defined?(Mongoid)
|
16
|
-
MongoidStore::Session.mongo_session
|
17
|
-
elsif defined?(MongoMapper)
|
18
|
-
MongoMapper.database
|
19
|
-
elsif defined?(Mongo)
|
20
|
-
Mongo::Connection.new[database_name]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def database_name
|
25
|
-
Rails.application.class.to_s.underscore.sub(/\/.*/, '') + "_" + Rails.env
|
26
|
-
end
|
27
|
-
|
28
|
-
def drop_collections_in(database)
|
29
|
-
database.collections.select { |c| c.name !~ /^system/ }.each(&:drop)
|
30
|
-
end
|
31
|
-
|
32
|
-
RSpec.configure do |config|
|
33
|
-
config.before :all do
|
34
|
-
unless User.table_exists?
|
35
|
-
load Rails.root.join('db', 'schema.rb')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
config.before :each do
|
40
|
-
drop_collections_in(db)
|
41
|
-
User.delete_all
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
puts "Testing #{ENV["MONGO_SESSION_STORE_ORM"]}_store on Rails #{Rails.version}..."
|
46
|
-
|
47
|
-
case ENV["MONGO_SESSION_STORE_ORM"]
|
48
|
-
when "mongo_mapper"
|
49
|
-
puts "MongoMapper version: #{MongoMapper::Version}"
|
50
|
-
when "mongoid"
|
51
|
-
puts "Mongoid version: #{Mongoid::VERSION}"
|
52
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_session_store-rails3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Hempel
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-06-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: actionpack
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- mongo_session_store-rails4.gemspec
|
54
54
|
- perf/benchmark.rb
|
55
55
|
- spec/integration_with_devise_spec.rb
|
56
|
+
- spec/mongo_store_base_spec.rb
|
56
57
|
- spec/rails_3.1_app/.gitignore
|
57
58
|
- spec/rails_3.1_app/README
|
58
59
|
- spec/rails_3.1_app/Rakefile
|
@@ -289,6 +290,7 @@ files:
|
|
289
290
|
- spec/rails_4.1_app/public/500.html
|
290
291
|
- spec/rails_4.1_app/public/favicon.ico
|
291
292
|
- spec/rails_4.1_app/public/robots.txt
|
293
|
+
- spec/rails_helper.rb
|
292
294
|
- spec/spec_helper.rb
|
293
295
|
homepage: http://github.com/brianhempel/mongo_session_store
|
294
296
|
licenses: []
|
@@ -309,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
309
311
|
version: '0'
|
310
312
|
requirements: []
|
311
313
|
rubyforge_project:
|
312
|
-
rubygems_version: 2.2.
|
314
|
+
rubygems_version: 2.2.2
|
313
315
|
signing_key:
|
314
316
|
specification_version: 4
|
315
317
|
summary: Rails session stores for MongoMapper, Mongoid, or any other ODM. Rails 3.1,
|
@@ -317,6 +319,7 @@ summary: Rails session stores for MongoMapper, Mongoid, or any other ODM. Rails
|
|
317
319
|
test_files:
|
318
320
|
- perf/benchmark.rb
|
319
321
|
- spec/integration_with_devise_spec.rb
|
322
|
+
- spec/mongo_store_base_spec.rb
|
320
323
|
- spec/rails_3.1_app/.gitignore
|
321
324
|
- spec/rails_3.1_app/README
|
322
325
|
- spec/rails_3.1_app/Rakefile
|
@@ -553,4 +556,5 @@ test_files:
|
|
553
556
|
- spec/rails_4.1_app/public/500.html
|
554
557
|
- spec/rails_4.1_app/public/favicon.ico
|
555
558
|
- spec/rails_4.1_app/public/robots.txt
|
559
|
+
- spec/rails_helper.rb
|
556
560
|
- spec/spec_helper.rb
|