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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 978d92ad561316e9b239b0fad9d24b40f60e1177
4
- data.tar.gz: c7544b18a3b886640cf398e8ce972eaa1634b586
3
+ metadata.gz: c6fb0f3be1ee193468f59e8ceae96d70165c2806
4
+ data.tar.gz: 57a0d903010ed76a33967e2c8a218c4af890f5e5
5
5
  SHA512:
6
- metadata.gz: 270987e7655190e6c605ffe5a72554faf38a1139e8033c95dfcff15719ada252b93ba3e2cacf37d995837f4fa7370478e1a178b93ad2b4a0b455759f4d9a1607
7
- data.tar.gz: 5356afb1a2a500fa6a25bf1e96201635b97e66ca0c32ad6f22d0208737cf5b2508f694ae4d6e2c59db3195cc790d094753c524915f75c36891e5b42145d41163
6
+ metadata.gz: d7024e9286c693e8e68bb8c70818dc85fa3ea56ce9fb62c6789e1c1c63ef82fe41ae41135c9cdb5f209616ac95e7adccd61070bbf5dd0392acb6b5874c7cdf14
7
+ data.tar.gz: eb4441fbbae34d749b8602a5c44e7bb74beeae362460ac20a86a4b34a772aba508f3694be37356a27cb55b42763efc9fb2dfee199616502eb931b96328cb0f74
@@ -3,15 +3,15 @@ script: "rake"
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.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.0.rc1'
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'] =~ /4\.\d/
27
+ if ENV['RAILS_VERS'] =~ /^4\.\d/
28
28
  gem 'mongoid', '>= 4.0.0.beta1'
29
- else
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 'debugger', :platforms => [:ruby_19, :ruby_20, :ruby_21] unless ENV['TRAVIS']
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.1, and JRuby with Rails 3.1 through 4.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,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
  require 'bundler'
4
- Bundler::GemHelper.install_tasks :name => 'mongo_session_store-rails3'
4
+ Bundler::GemHelper.install_tasks :name => 'mongo_session_store-rails4'
5
5
 
6
6
  def run_with_output(command)
7
7
  puts "Running: #{command}"
@@ -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 ||= generate_sid
28
- session = find_session(sid)
29
- env[SESSION_RECORD_KEY] = session
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 = get_session_model(env, sid)
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 ? sid : false
40
+ record.save ? id : false
40
41
  end
41
42
 
42
- def find_session(id)
43
- session_class.where(:_id => id).first || session_class.new(:_id => 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 get_session_model(env, sid)
47
- if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
48
- env[SESSION_RECORD_KEY] = find_session(sid)
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
- get_session_model(env, sid).destroy
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
@@ -1,3 +1,3 @@
1
1
  module MongoSessionStore
2
- VERSION = "5.0.1"
2
+ VERSION = "5.1.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  describe Devise::SessionsController do
4
4
  def create_user
@@ -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
@@ -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.1
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-03-06 00:00:00.000000000 Z
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.0
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