mongo_session_store 2.0.0 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +43 -0
  5. data/.travis.yml +37 -0
  6. data/CHANGELOG.md +49 -0
  7. data/Dangerfile +1 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE +23 -0
  10. data/README.md +106 -43
  11. data/Rakefile +90 -0
  12. data/gemfiles/rails-4.0-mongo.gemfile +9 -0
  13. data/gemfiles/rails-4.0-mongoid.gemfile +9 -0
  14. data/gemfiles/rails-4.1-mongo.gemfile +9 -0
  15. data/gemfiles/rails-4.1-mongoid.gemfile +9 -0
  16. data/gemfiles/rails-4.2-mongo.gemfile +9 -0
  17. data/gemfiles/rails-4.2-mongoid.gemfile +9 -0
  18. data/lib/mongo_session_store.rb +27 -1
  19. data/lib/mongo_session_store/mongo_store.rb +102 -0
  20. data/lib/mongo_session_store/mongo_store_base.rb +65 -0
  21. data/lib/mongo_session_store/mongoid_store.rb +52 -0
  22. data/lib/mongo_session_store/version.rb +3 -0
  23. data/mongo_session_store.gemspec +25 -0
  24. data/perf/benchmark.rb +101 -0
  25. data/spec/.rubocop.yml +4 -0
  26. data/spec/integrations/devise_spec.rb +109 -0
  27. data/spec/lib/mongo_session_store/mongo_store/session_spec.rb +247 -0
  28. data/spec/lib/mongo_session_store/mongo_store_base_spec.rb +269 -0
  29. data/spec/lib/mongo_session_store/mongo_store_spec.rb +13 -0
  30. data/spec/lib/mongo_session_store/mongoid_store/session_spec.rb +82 -0
  31. data/spec/lib/mongo_session_store/mongoid_store_spec.rb +13 -0
  32. data/spec/lib/mongo_session_store_spec.rb +64 -0
  33. data/spec/rails_helper.rb +19 -0
  34. data/spec/spec_helper.rb +53 -0
  35. data/spec/support/apps/rails_4.0_app/Rakefile +6 -0
  36. data/spec/support/apps/rails_4.0_app/app/controllers/application_controller.rb +5 -0
  37. data/spec/support/apps/rails_4.0_app/app/controllers/home_controller.rb +4 -0
  38. data/spec/support/apps/rails_4.0_app/app/models/user.rb +5 -0
  39. data/spec/support/apps/rails_4.0_app/app/views/home/index.html.erb +10 -0
  40. data/spec/support/apps/rails_4.0_app/app/views/layouts/application.html.erb +17 -0
  41. data/spec/support/apps/rails_4.0_app/bin/bundle +3 -0
  42. data/spec/support/apps/rails_4.0_app/bin/rails +4 -0
  43. data/spec/support/apps/rails_4.0_app/bin/rake +4 -0
  44. data/spec/support/apps/rails_4.0_app/config.ru +4 -0
  45. data/spec/support/apps/rails_4.0_app/config/application.rb +11 -0
  46. data/spec/support/apps/rails_4.0_app/config/boot.rb +4 -0
  47. data/spec/support/apps/rails_4.0_app/config/database.yml +11 -0
  48. data/spec/support/apps/rails_4.0_app/config/environment.rb +5 -0
  49. data/spec/support/apps/rails_4.0_app/config/environments/development.rb +12 -0
  50. data/spec/support/apps/rails_4.0_app/config/environments/test.rb +19 -0
  51. data/spec/support/apps/rails_4.0_app/config/initializers/devise.rb +254 -0
  52. data/spec/support/apps/rails_4.0_app/config/initializers/secret_token.rb +12 -0
  53. data/spec/support/apps/rails_4.0_app/config/initializers/session_store.rb +1 -0
  54. data/spec/support/apps/rails_4.0_app/config/locales/devise.en.yml +59 -0
  55. data/spec/support/apps/rails_4.0_app/config/locales/en.yml +23 -0
  56. data/spec/support/apps/rails_4.0_app/config/mongo.yml +11 -0
  57. data/spec/support/apps/rails_4.0_app/config/mongoid.yml +13 -0
  58. data/spec/support/apps/rails_4.0_app/config/routes.rb +4 -0
  59. data/spec/support/apps/rails_4.0_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  60. data/spec/support/apps/rails_4.0_app/db/schema.rb +25 -0
  61. data/spec/support/apps/rails_4.0_app/db/seeds.rb +7 -0
  62. data/spec/support/apps/rails_4.0_app/lib/assets/.keep +0 -0
  63. data/spec/support/apps/rails_4.0_app/lib/tasks/.keep +0 -0
  64. data/spec/support/apps/rails_4.0_app/log/.keep +0 -0
  65. data/spec/support/apps/rails_4.0_app/public/404.html +58 -0
  66. data/spec/support/apps/rails_4.0_app/public/422.html +58 -0
  67. data/spec/support/apps/rails_4.0_app/public/500.html +57 -0
  68. data/spec/support/apps/rails_4.0_app/public/favicon.ico +0 -0
  69. data/spec/support/apps/rails_4.0_app/public/robots.txt +5 -0
  70. data/spec/support/apps/rails_4.1_app/Rakefile +3 -0
  71. data/spec/support/apps/rails_4.1_app/app/controllers/application_controller.rb +5 -0
  72. data/spec/support/apps/rails_4.1_app/app/controllers/home_controller.rb +4 -0
  73. data/spec/support/apps/rails_4.1_app/app/models/user.rb +5 -0
  74. data/spec/support/apps/rails_4.1_app/app/views/home/index.html.erb +10 -0
  75. data/spec/support/apps/rails_4.1_app/app/views/layouts/application.html.erb +17 -0
  76. data/spec/support/apps/rails_4.1_app/bin/bundle +3 -0
  77. data/spec/support/apps/rails_4.1_app/bin/rails +4 -0
  78. data/spec/support/apps/rails_4.1_app/bin/rake +4 -0
  79. data/spec/support/apps/rails_4.1_app/config.ru +2 -0
  80. data/spec/support/apps/rails_4.1_app/config/application.rb +11 -0
  81. data/spec/support/apps/rails_4.1_app/config/boot.rb +4 -0
  82. data/spec/support/apps/rails_4.1_app/config/database.yml +11 -0
  83. data/spec/support/apps/rails_4.1_app/config/environment.rb +5 -0
  84. data/spec/support/apps/rails_4.1_app/config/environments/development.rb +12 -0
  85. data/spec/support/apps/rails_4.1_app/config/environments/test.rb +19 -0
  86. data/spec/support/apps/rails_4.1_app/config/initializers/devise.rb +254 -0
  87. data/spec/support/apps/rails_4.1_app/config/initializers/session_store.rb +1 -0
  88. data/spec/support/apps/rails_4.1_app/config/locales/devise.en.yml +59 -0
  89. data/spec/support/apps/rails_4.1_app/config/locales/en.yml +23 -0
  90. data/spec/support/apps/rails_4.1_app/config/mongo.yml +11 -0
  91. data/spec/support/apps/rails_4.1_app/config/mongoid.yml +13 -0
  92. data/spec/support/apps/rails_4.1_app/config/routes.rb +4 -0
  93. data/spec/support/apps/rails_4.1_app/config/secrets.yml +22 -0
  94. data/spec/support/apps/rails_4.1_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  95. data/spec/support/apps/rails_4.1_app/db/schema.rb +25 -0
  96. data/spec/support/apps/rails_4.1_app/db/seeds.rb +7 -0
  97. data/spec/support/apps/rails_4.1_app/lib/assets/.keep +0 -0
  98. data/spec/support/apps/rails_4.1_app/lib/tasks/.keep +0 -0
  99. data/spec/support/apps/rails_4.1_app/log/.keep +0 -0
  100. data/spec/support/apps/rails_4.1_app/public/404.html +67 -0
  101. data/spec/support/apps/rails_4.1_app/public/422.html +67 -0
  102. data/spec/support/apps/rails_4.1_app/public/500.html +66 -0
  103. data/spec/support/apps/rails_4.1_app/public/favicon.ico +0 -0
  104. data/spec/support/apps/rails_4.1_app/public/robots.txt +5 -0
  105. data/spec/support/apps/rails_4.2_app/Rakefile +2 -0
  106. data/spec/support/apps/rails_4.2_app/app/controllers/application_controller.rb +5 -0
  107. data/spec/support/apps/rails_4.2_app/app/controllers/home_controller.rb +4 -0
  108. data/spec/support/apps/rails_4.2_app/app/models/user.rb +5 -0
  109. data/spec/support/apps/rails_4.2_app/app/views/home/index.html.erb +10 -0
  110. data/spec/support/apps/rails_4.2_app/app/views/layouts/application.html.erb +15 -0
  111. data/spec/support/apps/rails_4.2_app/bin/bundle +3 -0
  112. data/spec/support/apps/rails_4.2_app/bin/rails +8 -0
  113. data/spec/support/apps/rails_4.2_app/bin/rake +4 -0
  114. data/spec/support/apps/rails_4.2_app/config.ru +4 -0
  115. data/spec/support/apps/rails_4.2_app/config/application.rb +11 -0
  116. data/spec/support/apps/rails_4.2_app/config/boot.rb +3 -0
  117. data/spec/support/apps/rails_4.2_app/config/database.yml +11 -0
  118. data/spec/support/apps/rails_4.2_app/config/environment.rb +5 -0
  119. data/spec/support/apps/rails_4.2_app/config/environments/development.rb +12 -0
  120. data/spec/support/apps/rails_4.2_app/config/environments/test.rb +19 -0
  121. data/spec/support/apps/rails_4.2_app/config/initializers/devise.rb +254 -0
  122. data/spec/support/apps/rails_4.2_app/config/initializers/session_store.rb +1 -0
  123. data/spec/support/apps/rails_4.2_app/config/locales/en.yml +23 -0
  124. data/spec/support/apps/rails_4.2_app/config/mongo.yml +11 -0
  125. data/spec/support/apps/rails_4.2_app/config/mongoid.yml +13 -0
  126. data/spec/support/apps/rails_4.2_app/config/routes.rb +4 -0
  127. data/spec/support/apps/rails_4.2_app/config/secrets.yml +22 -0
  128. data/spec/support/apps/rails_4.2_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  129. data/spec/support/apps/rails_4.2_app/db/schema.rb +25 -0
  130. data/spec/support/apps/rails_4.2_app/db/seeds.rb +7 -0
  131. data/spec/support/helpers/session_id_helper.rb +5 -0
  132. data/spec/support/helpers/test_database_helper.rb +22 -0
  133. metadata +360 -92
  134. data/lib/mongo_session_store/mongo_mapper.rb +0 -60
  135. data/lib/mongo_session_store/mongoid.rb +0 -59
@@ -1,60 +0,0 @@
1
- require 'mongo_mapper'
2
-
3
- module ActionDispatch
4
- module Session
5
- class MongoMapperStore < AbstractStore
6
-
7
- class Session
8
- include MongoMapper::Document
9
- key :data, String, :default => [Marshal.dump({})].pack("m*")
10
- timestamps!
11
-
12
- ensure_index :updated_at if MongoMapper.class_variables.include? '@@database'
13
- end
14
-
15
- # The class used for session storage.
16
- cattr_accessor :session_class
17
- self.session_class = Session
18
-
19
- SESSION_RECORD_KEY = 'rack.session.record'.freeze
20
-
21
- private
22
- def generate_sid
23
- BSON::ObjectId.new
24
- end
25
-
26
- 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)]
31
- end
32
-
33
- def set_session(env, sid, session_data)
34
- record = env[SESSION_RECORD_KEY] ||= find_session(sid)
35
- record.data = pack(session_data)
36
- # Rack spec dictates that set_session should return true or false
37
- # depending on whether or not the session was saved or not.
38
- # However, ActionPack seems to want a session id instead.
39
- record.save ? sid : false
40
- end
41
-
42
- def find_session(id)
43
- @@session_class.find(id) ||
44
- @@session_class.new(:id=>id)
45
- rescue BSON::InvalidObjectId
46
- @@session_class.new(:id => generate_sid)
47
- end
48
-
49
- def pack(data)
50
- [Marshal.dump(data)].pack("m*")
51
- end
52
-
53
- def unpack(packed)
54
- return nil unless packed
55
- Marshal.load(packed.unpack("m*").first)
56
- end
57
-
58
- end
59
- end
60
- end
@@ -1,59 +0,0 @@
1
- require 'mongoid'
2
-
3
- module ActionDispatch
4
- module Session
5
- class MongoidStore < AbstractStore
6
-
7
- class Session
8
- include Mongoid::Document
9
- include Mongoid::Timestamps
10
-
11
- field :data, :type => String, :default => [Marshal.dump({})].pack("m*")
12
- index :updated_at
13
- end
14
-
15
- # The class used for session storage.
16
- cattr_accessor :session_class
17
- self.session_class = Session
18
-
19
- SESSION_RECORD_KEY = 'rack.session.record'.freeze
20
-
21
- private
22
- def generate_sid
23
- BSON::ObjectId.new
24
- end
25
-
26
- 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)]
31
- end
32
-
33
- def set_session(env, sid, session_data)
34
- record = env[SESSION_RECORD_KEY] ||= find_session(sid)
35
- record.data = pack(session_data)
36
- # Rack spec dictates that set_session should return true or false
37
- # depending on whether or not the session was saved or not.
38
- # However, ActionPack seems to want a session id instead.
39
- record.save ? sid : false
40
- end
41
-
42
- def find_session(id)
43
- id = BSON::ObjectId.from_string(id.to_s)
44
- @@session_class.first(:conditions => { :_id => id }) ||
45
- @@session_class.new(:id => id)
46
- end
47
-
48
- def pack(data)
49
- [Marshal.dump(data)].pack("m*")
50
- end
51
-
52
- def unpack(packed)
53
- return nil unless packed
54
- Marshal.load(packed.unpack("m*").first)
55
- end
56
-
57
- end
58
- end
59
- end