mongo_session_store-rails4 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/install.log +768 -0
  3. data/.gitignore +10 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +16 -0
  6. data/Gemfile +54 -0
  7. data/README.md +124 -0
  8. data/Rakefile +77 -0
  9. data/lib/mongo_session_store-rails3.rb +1 -0
  10. data/lib/mongo_session_store-rails4.rb +1 -0
  11. data/lib/mongo_session_store.rb +49 -0
  12. data/lib/mongo_session_store/mongo_mapper_store.rb +22 -0
  13. data/lib/mongo_session_store/mongo_store.rb +78 -0
  14. data/lib/mongo_session_store/mongo_store_base.rb +77 -0
  15. data/lib/mongo_session_store/mongoid_store.rb +53 -0
  16. data/lib/mongo_session_store/version.rb +3 -0
  17. data/mongo_session_store-rails3.gemspec +17 -0
  18. data/mongo_session_store-rails4.gemspec +17 -0
  19. data/perf/benchmark.rb +92 -0
  20. data/spec/integration_with_devise_spec.rb +89 -0
  21. data/spec/rails_3.1_app/.gitignore +5 -0
  22. data/spec/rails_3.1_app/README +261 -0
  23. data/spec/rails_3.1_app/Rakefile +7 -0
  24. data/spec/rails_3.1_app/app/assets/javascripts/application.js +7 -0
  25. data/spec/rails_3.1_app/app/assets/stylesheets/application.css +7 -0
  26. data/spec/rails_3.1_app/app/controllers/application_controller.rb +3 -0
  27. data/spec/rails_3.1_app/app/controllers/home_controller.rb +4 -0
  28. data/spec/rails_3.1_app/app/helpers/application_helper.rb +2 -0
  29. data/spec/rails_3.1_app/app/mailers/.gitkeep +0 -0
  30. data/spec/rails_3.1_app/app/models/.gitkeep +0 -0
  31. data/spec/rails_3.1_app/app/models/user.rb +6 -0
  32. data/spec/rails_3.1_app/app/views/devise/confirmations/new.html.erb +12 -0
  33. data/spec/rails_3.1_app/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  34. data/spec/rails_3.1_app/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  35. data/spec/rails_3.1_app/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  36. data/spec/rails_3.1_app/app/views/devise/passwords/edit.html.erb +16 -0
  37. data/spec/rails_3.1_app/app/views/devise/passwords/new.html.erb +12 -0
  38. data/spec/rails_3.1_app/app/views/devise/registrations/edit.html.erb +25 -0
  39. data/spec/rails_3.1_app/app/views/devise/registrations/new.html.erb +18 -0
  40. data/spec/rails_3.1_app/app/views/devise/sessions/new.html.erb +17 -0
  41. data/spec/rails_3.1_app/app/views/devise/shared/_links.erb +25 -0
  42. data/spec/rails_3.1_app/app/views/devise/unlocks/new.html.erb +12 -0
  43. data/spec/rails_3.1_app/app/views/home/index.html.erb +10 -0
  44. data/spec/rails_3.1_app/app/views/layouts/application.html.erb +15 -0
  45. data/spec/rails_3.1_app/config.ru +4 -0
  46. data/spec/rails_3.1_app/config/application.rb +47 -0
  47. data/spec/rails_3.1_app/config/boot.rb +6 -0
  48. data/spec/rails_3.1_app/config/database.yml +11 -0
  49. data/spec/rails_3.1_app/config/environment.rb +5 -0
  50. data/spec/rails_3.1_app/config/environments/development.rb +27 -0
  51. data/spec/rails_3.1_app/config/environments/production.rb +54 -0
  52. data/spec/rails_3.1_app/config/environments/test.rb +39 -0
  53. data/spec/rails_3.1_app/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/rails_3.1_app/config/initializers/devise.rb +201 -0
  55. data/spec/rails_3.1_app/config/initializers/inflections.rb +10 -0
  56. data/spec/rails_3.1_app/config/initializers/mime_types.rb +5 -0
  57. data/spec/rails_3.1_app/config/initializers/secret_token.rb +7 -0
  58. data/spec/rails_3.1_app/config/initializers/session_store.rb +9 -0
  59. data/spec/rails_3.1_app/config/initializers/wrap_parameters.rb +12 -0
  60. data/spec/rails_3.1_app/config/locales/devise.en.yml +55 -0
  61. data/spec/rails_3.1_app/config/locales/en.yml +5 -0
  62. data/spec/rails_3.1_app/config/mongo.yml +18 -0
  63. data/spec/rails_3.1_app/config/mongoid.yml +13 -0
  64. data/spec/rails_3.1_app/config/routes.rb +4 -0
  65. data/spec/rails_3.1_app/db/migrate/20120222195914_create_users_table.rb +12 -0
  66. data/spec/rails_3.1_app/db/schema.rb +20 -0
  67. data/spec/rails_3.1_app/lib/tasks/.gitkeep +0 -0
  68. data/spec/rails_3.1_app/log/.gitkeep +0 -0
  69. data/spec/rails_3.1_app/public/404.html +26 -0
  70. data/spec/rails_3.1_app/public/422.html +26 -0
  71. data/spec/rails_3.1_app/public/500.html +26 -0
  72. data/spec/rails_3.1_app/public/favicon.ico +0 -0
  73. data/spec/rails_3.1_app/public/robots.txt +5 -0
  74. data/spec/rails_3.1_app/script/rails +6 -0
  75. data/spec/rails_3.1_app/vendor/assets/stylesheets/.gitkeep +0 -0
  76. data/spec/rails_3.1_app/vendor/plugins/.gitkeep +0 -0
  77. data/spec/rails_3.2_app/.gitignore +5 -0
  78. data/spec/rails_3.2_app/README +261 -0
  79. data/spec/rails_3.2_app/Rakefile +7 -0
  80. data/spec/rails_3.2_app/app/assets/javascripts/application.js +7 -0
  81. data/spec/rails_3.2_app/app/assets/stylesheets/application.css +7 -0
  82. data/spec/rails_3.2_app/app/controllers/application_controller.rb +3 -0
  83. data/spec/rails_3.2_app/app/controllers/home_controller.rb +4 -0
  84. data/spec/rails_3.2_app/app/helpers/application_helper.rb +2 -0
  85. data/spec/rails_3.2_app/app/mailers/.gitkeep +0 -0
  86. data/spec/rails_3.2_app/app/models/.gitkeep +0 -0
  87. data/spec/rails_3.2_app/app/models/user.rb +6 -0
  88. data/spec/rails_3.2_app/app/views/devise/confirmations/new.html.erb +12 -0
  89. data/spec/rails_3.2_app/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  90. data/spec/rails_3.2_app/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  91. data/spec/rails_3.2_app/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  92. data/spec/rails_3.2_app/app/views/devise/passwords/edit.html.erb +16 -0
  93. data/spec/rails_3.2_app/app/views/devise/passwords/new.html.erb +12 -0
  94. data/spec/rails_3.2_app/app/views/devise/registrations/edit.html.erb +25 -0
  95. data/spec/rails_3.2_app/app/views/devise/registrations/new.html.erb +18 -0
  96. data/spec/rails_3.2_app/app/views/devise/sessions/new.html.erb +17 -0
  97. data/spec/rails_3.2_app/app/views/devise/shared/_links.erb +25 -0
  98. data/spec/rails_3.2_app/app/views/devise/unlocks/new.html.erb +12 -0
  99. data/spec/rails_3.2_app/app/views/home/index.html.erb +10 -0
  100. data/spec/rails_3.2_app/app/views/layouts/application.html.erb +15 -0
  101. data/spec/rails_3.2_app/config.ru +4 -0
  102. data/spec/rails_3.2_app/config/application.rb +47 -0
  103. data/spec/rails_3.2_app/config/boot.rb +6 -0
  104. data/spec/rails_3.2_app/config/database.yml +11 -0
  105. data/spec/rails_3.2_app/config/environment.rb +5 -0
  106. data/spec/rails_3.2_app/config/environments/development.rb +27 -0
  107. data/spec/rails_3.2_app/config/environments/production.rb +54 -0
  108. data/spec/rails_3.2_app/config/environments/test.rb +39 -0
  109. data/spec/rails_3.2_app/config/initializers/backtrace_silencers.rb +7 -0
  110. data/spec/rails_3.2_app/config/initializers/devise.rb +203 -0
  111. data/spec/rails_3.2_app/config/initializers/inflections.rb +10 -0
  112. data/spec/rails_3.2_app/config/initializers/mime_types.rb +5 -0
  113. data/spec/rails_3.2_app/config/initializers/secret_token.rb +7 -0
  114. data/spec/rails_3.2_app/config/initializers/session_store.rb +9 -0
  115. data/spec/rails_3.2_app/config/initializers/wrap_parameters.rb +12 -0
  116. data/spec/rails_3.2_app/config/locales/devise.en.yml +55 -0
  117. data/spec/rails_3.2_app/config/locales/en.yml +5 -0
  118. data/spec/rails_3.2_app/config/mongo.yml +18 -0
  119. data/spec/rails_3.2_app/config/mongoid.yml +13 -0
  120. data/spec/rails_3.2_app/config/routes.rb +4 -0
  121. data/spec/rails_3.2_app/db/migrate/20120222195914_create_users_table.rb +12 -0
  122. data/spec/rails_3.2_app/db/schema.rb +20 -0
  123. data/spec/rails_3.2_app/lib/tasks/.gitkeep +0 -0
  124. data/spec/rails_3.2_app/log/.gitkeep +0 -0
  125. data/spec/rails_3.2_app/public/404.html +26 -0
  126. data/spec/rails_3.2_app/public/422.html +26 -0
  127. data/spec/rails_3.2_app/public/500.html +26 -0
  128. data/spec/rails_3.2_app/public/favicon.ico +0 -0
  129. data/spec/rails_3.2_app/public/robots.txt +5 -0
  130. data/spec/rails_3.2_app/script/rails +6 -0
  131. data/spec/rails_3.2_app/vendor/assets/stylesheets/.gitkeep +0 -0
  132. data/spec/rails_3.2_app/vendor/plugins/.gitkeep +0 -0
  133. data/spec/rails_4.0_app/.gitignore +16 -0
  134. data/spec/rails_4.0_app/Rakefile +6 -0
  135. data/spec/rails_4.0_app/app/assets/images/.keep +0 -0
  136. data/spec/rails_4.0_app/app/assets/javascripts/application.js +13 -0
  137. data/spec/rails_4.0_app/app/assets/stylesheets/application.css +13 -0
  138. data/spec/rails_4.0_app/app/controllers/application_controller.rb +5 -0
  139. data/spec/rails_4.0_app/app/controllers/concerns/.keep +0 -0
  140. data/spec/rails_4.0_app/app/controllers/home_controller.rb +4 -0
  141. data/spec/rails_4.0_app/app/helpers/application_helper.rb +2 -0
  142. data/spec/rails_4.0_app/app/mailers/.keep +0 -0
  143. data/spec/rails_4.0_app/app/models/.keep +0 -0
  144. data/spec/rails_4.0_app/app/models/concerns/.keep +0 -0
  145. data/spec/rails_4.0_app/app/models/user.rb +5 -0
  146. data/spec/rails_4.0_app/app/views/devise/confirmations/new.html.erb +12 -0
  147. data/spec/rails_4.0_app/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  148. data/spec/rails_4.0_app/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  149. data/spec/rails_4.0_app/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  150. data/spec/rails_4.0_app/app/views/devise/passwords/edit.html.erb +16 -0
  151. data/spec/rails_4.0_app/app/views/devise/passwords/new.html.erb +12 -0
  152. data/spec/rails_4.0_app/app/views/devise/registrations/edit.html.erb +29 -0
  153. data/spec/rails_4.0_app/app/views/devise/registrations/new.html.erb +18 -0
  154. data/spec/rails_4.0_app/app/views/devise/sessions/new.html.erb +17 -0
  155. data/spec/rails_4.0_app/app/views/devise/shared/_links.erb +25 -0
  156. data/spec/rails_4.0_app/app/views/devise/unlocks/new.html.erb +12 -0
  157. data/spec/rails_4.0_app/app/views/home/index.html.erb +10 -0
  158. data/spec/rails_4.0_app/app/views/layouts/application.html.erb +17 -0
  159. data/spec/rails_4.0_app/bin/bundle +3 -0
  160. data/spec/rails_4.0_app/bin/rails +4 -0
  161. data/spec/rails_4.0_app/bin/rake +4 -0
  162. data/spec/rails_4.0_app/config.ru +4 -0
  163. data/spec/rails_4.0_app/config/application.rb +26 -0
  164. data/spec/rails_4.0_app/config/boot.rb +4 -0
  165. data/spec/rails_4.0_app/config/database.yml +11 -0
  166. data/spec/rails_4.0_app/config/environment.rb +5 -0
  167. data/spec/rails_4.0_app/config/environments/development.rb +29 -0
  168. data/spec/rails_4.0_app/config/environments/production.rb +80 -0
  169. data/spec/rails_4.0_app/config/environments/test.rb +36 -0
  170. data/spec/rails_4.0_app/config/initializers/backtrace_silencers.rb +7 -0
  171. data/spec/rails_4.0_app/config/initializers/devise.rb +254 -0
  172. data/spec/rails_4.0_app/config/initializers/filter_parameter_logging.rb +4 -0
  173. data/spec/rails_4.0_app/config/initializers/inflections.rb +16 -0
  174. data/spec/rails_4.0_app/config/initializers/mime_types.rb +5 -0
  175. data/spec/rails_4.0_app/config/initializers/secret_token.rb +12 -0
  176. data/spec/rails_4.0_app/config/initializers/session_store.rb +5 -0
  177. data/spec/rails_4.0_app/config/initializers/wrap_parameters.rb +14 -0
  178. data/spec/rails_4.0_app/config/locales/devise.en.yml +59 -0
  179. data/spec/rails_4.0_app/config/locales/en.yml +23 -0
  180. data/spec/rails_4.0_app/config/mongo.yml +11 -0
  181. data/spec/rails_4.0_app/config/mongoid.yml +13 -0
  182. data/spec/rails_4.0_app/config/routes.rb +4 -0
  183. data/spec/rails_4.0_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  184. data/spec/rails_4.0_app/db/schema.rb +25 -0
  185. data/spec/rails_4.0_app/db/seeds.rb +7 -0
  186. data/spec/rails_4.0_app/lib/assets/.keep +0 -0
  187. data/spec/rails_4.0_app/lib/tasks/.keep +0 -0
  188. data/spec/rails_4.0_app/log/.keep +0 -0
  189. data/spec/rails_4.0_app/public/404.html +58 -0
  190. data/spec/rails_4.0_app/public/422.html +58 -0
  191. data/spec/rails_4.0_app/public/500.html +57 -0
  192. data/spec/rails_4.0_app/public/favicon.ico +0 -0
  193. data/spec/rails_4.0_app/public/robots.txt +5 -0
  194. data/spec/rails_4.1_app/.gitignore +16 -0
  195. data/spec/rails_4.1_app/Rakefile +6 -0
  196. data/spec/rails_4.1_app/app/assets/images/.keep +0 -0
  197. data/spec/rails_4.1_app/app/assets/javascripts/application.js +13 -0
  198. data/spec/rails_4.1_app/app/assets/stylesheets/application.css +15 -0
  199. data/spec/rails_4.1_app/app/controllers/application_controller.rb +5 -0
  200. data/spec/rails_4.1_app/app/controllers/concerns/.keep +0 -0
  201. data/spec/rails_4.1_app/app/controllers/home_controller.rb +4 -0
  202. data/spec/rails_4.1_app/app/helpers/application_helper.rb +2 -0
  203. data/spec/rails_4.1_app/app/mailers/.keep +0 -0
  204. data/spec/rails_4.1_app/app/models/.keep +0 -0
  205. data/spec/rails_4.1_app/app/models/concerns/.keep +0 -0
  206. data/spec/rails_4.1_app/app/models/user.rb +5 -0
  207. data/spec/rails_4.1_app/app/views/devise/confirmations/new.html.erb +12 -0
  208. data/spec/rails_4.1_app/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  209. data/spec/rails_4.1_app/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  210. data/spec/rails_4.1_app/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  211. data/spec/rails_4.1_app/app/views/devise/passwords/edit.html.erb +16 -0
  212. data/spec/rails_4.1_app/app/views/devise/passwords/new.html.erb +12 -0
  213. data/spec/rails_4.1_app/app/views/devise/registrations/edit.html.erb +29 -0
  214. data/spec/rails_4.1_app/app/views/devise/registrations/new.html.erb +18 -0
  215. data/spec/rails_4.1_app/app/views/devise/sessions/new.html.erb +17 -0
  216. data/spec/rails_4.1_app/app/views/devise/shared/_links.erb +25 -0
  217. data/spec/rails_4.1_app/app/views/devise/unlocks/new.html.erb +12 -0
  218. data/spec/rails_4.1_app/app/views/home/index.html.erb +10 -0
  219. data/spec/rails_4.1_app/app/views/layouts/application.html.erb +17 -0
  220. data/spec/rails_4.1_app/bin/bundle +3 -0
  221. data/spec/rails_4.1_app/bin/rails +8 -0
  222. data/spec/rails_4.1_app/bin/rake +8 -0
  223. data/spec/rails_4.1_app/bin/spring +18 -0
  224. data/spec/rails_4.1_app/config.ru +4 -0
  225. data/spec/rails_4.1_app/config/application.rb +23 -0
  226. data/spec/rails_4.1_app/config/boot.rb +4 -0
  227. data/spec/rails_4.1_app/config/database.yml +11 -0
  228. data/spec/rails_4.1_app/config/environment.rb +5 -0
  229. data/spec/rails_4.1_app/config/environments/development.rb +37 -0
  230. data/spec/rails_4.1_app/config/environments/production.rb +83 -0
  231. data/spec/rails_4.1_app/config/environments/test.rb +39 -0
  232. data/spec/rails_4.1_app/config/initializers/backtrace_silencers.rb +7 -0
  233. data/spec/rails_4.1_app/config/initializers/cookies_serializer.rb +3 -0
  234. data/spec/rails_4.1_app/config/initializers/devise.rb +254 -0
  235. data/spec/rails_4.1_app/config/initializers/filter_parameter_logging.rb +4 -0
  236. data/spec/rails_4.1_app/config/initializers/inflections.rb +16 -0
  237. data/spec/rails_4.1_app/config/initializers/mime_types.rb +5 -0
  238. data/spec/rails_4.1_app/config/initializers/session_store.rb +5 -0
  239. data/spec/rails_4.1_app/config/initializers/wrap_parameters.rb +14 -0
  240. data/spec/rails_4.1_app/config/locales/devise.en.yml +59 -0
  241. data/spec/rails_4.1_app/config/locales/en.yml +23 -0
  242. data/spec/rails_4.1_app/config/mongo.yml +11 -0
  243. data/spec/rails_4.1_app/config/mongoid.yml +13 -0
  244. data/spec/rails_4.1_app/config/routes.rb +4 -0
  245. data/spec/rails_4.1_app/config/secrets.yml +22 -0
  246. data/spec/rails_4.1_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  247. data/spec/rails_4.1_app/db/schema.rb +25 -0
  248. data/spec/rails_4.1_app/db/seeds.rb +7 -0
  249. data/spec/rails_4.1_app/lib/assets/.keep +0 -0
  250. data/spec/rails_4.1_app/lib/tasks/.keep +0 -0
  251. data/spec/rails_4.1_app/log/.keep +0 -0
  252. data/spec/rails_4.1_app/public/404.html +67 -0
  253. data/spec/rails_4.1_app/public/422.html +67 -0
  254. data/spec/rails_4.1_app/public/500.html +66 -0
  255. data/spec/rails_4.1_app/public/favicon.ico +0 -0
  256. data/spec/rails_4.1_app/public/robots.txt +5 -0
  257. data/spec/spec_helper.rb +52 -0
  258. metadata +556 -0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ /pkg
3
+ /doc
4
+ /coverage
5
+ Gemfile.lock
6
+ Gemfile_Rails_*.lock
7
+ *.gem
8
+ .rvmrc
9
+ *.swo
10
+ *.swp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ script: "rake"
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.1
7
+ - ruby-head
8
+ - jruby-19mode
9
+ - jruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: jruby-head
13
+ - rvm: ruby-head
14
+ - rvm: rbx
15
+ services:
16
+ - mongodb
data/Gemfile ADDED
@@ -0,0 +1,54 @@
1
+ source 'https://rubygems.org'
2
+
3
+ RAILS_VERS = case ENV['RAILS_VERS']
4
+ when '3.1'
5
+ '~>3.1'
6
+ when '3.2'
7
+ '~>3.2'
8
+ when '4.0'
9
+ '~>4.0'
10
+ when '4.1'
11
+ '~>4.1.0.rc1'
12
+ when nil
13
+ nil
14
+ else
15
+ raise "Invalid RAILS_VERS. Available versions are 3.2 and 4.0."
16
+ end
17
+
18
+ gemspec :name => 'mongo_session_store-rails4'
19
+
20
+ group :development, :test do
21
+ gem 'rake'
22
+ if ENV['MONGO_SESSION_STORE_ORM'] == 'mongo_mapper'
23
+ gem 'mongo_mapper', '>= 0.13.0.beta2'
24
+ end
25
+
26
+ if ENV['MONGO_SESSION_STORE_ORM'] == 'mongoid'
27
+ if ENV['RAILS_VERS'] =~ /4\.\d/
28
+ gem 'mongoid', '>= 4.0.0.beta1'
29
+ else
30
+ gem 'mongoid', '>= 3.1.0'
31
+ end
32
+ end
33
+
34
+ if ENV['MONGO_SESSION_STORE_ORM'] == 'mongo'
35
+ gem 'mongo'
36
+ end
37
+
38
+ gem 'debugger', :platforms => [:ruby_19, :ruby_20, :ruby_21] unless ENV['TRAVIS']
39
+
40
+ if RUBY_PLATFORM == 'java'
41
+ gem 'jdbc-sqlite3'
42
+ gem 'activerecord-jdbc-adapter'
43
+ gem 'activerecord-jdbcsqlite3-adapter'
44
+ gem 'jruby-openssl'
45
+ gem 'jruby-rack'
46
+ else
47
+ gem 'sqlite3' # for devise User storage
48
+ end
49
+ RAILS_VERS ? gem('rails', RAILS_VERS) : gem('rails')
50
+ gem 'minitest' if ENV['RAILS_VERS'] == '4.1'
51
+
52
+ gem 'rspec-rails', '2.12.0'
53
+ gem 'devise'
54
+ end
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # MongoSessionStore [![Build Status](https://travis-ci.org/brianhempel/mongo_session_store.png?branch=master)](https://travis-ci.org/brianhempel/mongo_session_store)
2
+
3
+ ## Description
4
+
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
+
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.
8
+
9
+ Mongoid users: This gem is compatible with both Mongoid 3 and 4.
10
+
11
+ If this gem doesn't work for you, you might next try [mongo_sessions](https://github.com/biilmann/mongo_sessions).
12
+
13
+ See the [Changelog](#changelog) if you need support for an older version of Ruby, Rails, or Mongoid.
14
+
15
+ ## Usage
16
+
17
+ MongoSessionStore is compatible with Rails 3.1 through 4.1.
18
+
19
+ In your Gemfile:
20
+
21
+ ```ruby
22
+ gem "mongo_mapper"
23
+ # or gem "mongoid"
24
+ # or gem "mongo"
25
+ gem "mongo_session_store-rails4"
26
+ # or gem "mongo_session_store-rails3"
27
+ ```
28
+
29
+ In the session_store initializer (config/initializers/session_store.rb):
30
+
31
+ ```ruby
32
+ # MongoMapper
33
+ MyApp::Application.config.session_store :mongo_mapper_store
34
+
35
+ # Mongoid
36
+ MyApp::Application.config.session_store :mongoid_store
37
+
38
+ # anything else
39
+ MyApp::Application.config.session_store :mongo_store
40
+ MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')
41
+ ```
42
+
43
+ By default, the sessions will be stored in the "sessions" collection in MongoDB. If you want to use a different collection, you can set that in the initializer:
44
+
45
+ ```ruby
46
+ MongoSessionStore.collection_name = "client_sessions"
47
+ ```
48
+
49
+ And if for some reason you want to query your sessions:
50
+
51
+ ```ruby
52
+ # MongoMapper
53
+ MongoMapperStore::Session.where(:updated_at.gt => 2.days.ago)
54
+
55
+ # Mongoid
56
+ MongoidStore::Session.where(:updated_at.gt => 2.days.ago)
57
+
58
+ # Plain old Mongo
59
+ MongoStore::Session.where('updated_at' => { '$gt' => 2.days.ago })
60
+ ```
61
+
62
+ ## Changelog
63
+
64
+ 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.
65
+
66
+ The last version to support Ruby 1.8.7 is [version 4.1.1](https://rubygems.org/gems/mongo_session_store-rails3/versions/4.1.1).
67
+
68
+ The last version to support Rails 3.0 or Mongoid 2 is [version 3.0.6](https://rubygems.org/gems/mongo_session_store-rails3/versions/3.0.6).
69
+
70
+ ## Development
71
+
72
+ To run all the tests:
73
+
74
+ rake
75
+
76
+ To run the tests for a specific store (examples):
77
+
78
+ rake test_31_mongo
79
+ rake test_32_mongoid
80
+ rake test_40_mongoid
81
+ rake test_41_mongo_mapper
82
+
83
+ To see a list of all options for running tests, run
84
+
85
+ rake -T
86
+
87
+ ## Previous contributors
88
+
89
+ MongoSessionStore started as a fork of the DataMapper session store, modified to work with MongoMapper and Mongoid. Much thanks to all the previous contributors:
90
+
91
+ * Nicolas Mérouze
92
+ * Chris Brickley
93
+ * Tony Pitale
94
+ * Nicola Racco
95
+ * Matt Powell
96
+ * Ryan Fitzgerald
97
+
98
+ ## License
99
+
100
+ Copyright (c) 2011-2014 Brian Hempel
101
+ Copyright (c) 2010 Nicolas Mérouze
102
+ Copyright (c) 2009 Chris Brickley
103
+ Copyright (c) 2009 Tony Pitale
104
+
105
+ Permission is hereby granted, free of charge, to any person
106
+ obtaining a copy of this software and associated documentation
107
+ files (the "Software"), to deal in the Software without
108
+ restriction, including without limitation the rights to use,
109
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
110
+ copies of the Software, and to permit persons to whom the
111
+ Software is furnished to do so, subject to the following
112
+ conditions:
113
+
114
+ The above copyright notice and this permission notice shall be
115
+ included in all copies or substantial portions of the Software.
116
+
117
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
118
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
119
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
120
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
121
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
122
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
123
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
124
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks :name => 'mongo_session_store-rails4'
5
+
6
+ def run_with_output(command)
7
+ puts "Running: #{command}"
8
+ system(command)
9
+ end
10
+
11
+ def set_versions(rails_vers, orm)
12
+ success = true
13
+ unless File.exists?("Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock")
14
+ success &&= run_with_output("export RAILS_VERS=#{rails_vers}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle update")
15
+ success &&= run_with_output("cp Gemfile.lock Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock")
16
+ else
17
+ success &&= run_with_output("rm Gemfile.lock")
18
+ success &&= run_with_output("cp Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock Gemfile.lock")
19
+ end
20
+ success
21
+ end
22
+
23
+ @rails_versions = ['3.1', '3.2', '4.0', '4.1']
24
+ @orms = ['mongo_mapper', 'mongoid', 'mongo']
25
+
26
+ task :default => :test_all
27
+
28
+ desc 'Test each session store against Rails 3.1, 3.2, 4.0, and 4.1'
29
+ task :test_all do
30
+ # inspired by http://pivotallabs.com/users/jdean/blog/articles/1728-testing-your-gem-against-multiple-rubies-and-rails-versions-with-rvm
31
+
32
+
33
+ @failed_suites = []
34
+
35
+ @rails_versions.each do |rails_version|
36
+ @orms.each do |orm|
37
+ success = set_versions(rails_version, orm)
38
+
39
+ unless success && run_with_output("export RAILS_VERS=#{rails_version}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle exec rspec spec")
40
+ @failed_suites << "Rails #{rails_version} / #{orm}"
41
+ end
42
+ end
43
+ end
44
+
45
+ if @failed_suites.any?
46
+ puts "\033[0;31mFailed:"
47
+ puts @failed_suites.join("\n")
48
+ print "\033[0m"
49
+ exit(1)
50
+ else
51
+ print "\033[0;32mAll passed! Success! "
52
+ "Yahoooo!!!".chars.each { |c| sleep 0.4; print c; STDOUT.flush }
53
+ puts "\033[0m"
54
+ end
55
+ end
56
+
57
+ @rails_versions.each do |rails_version|
58
+ @orms.each do |orm|
59
+ desc "Set Gemfile.lock to #{rails_version} with #{orm}"
60
+ task :"use_#{rails_version.gsub('.', '')}_#{orm}" do
61
+ set_versions(rails_version, orm)
62
+ end
63
+
64
+ desc "Test against #{rails_version} with #{orm}"
65
+ task :"test_#{rails_version.gsub('.', '')}_#{orm}" do
66
+ set_versions(rails_version, orm)
67
+ success = run_with_output("export RAILS_VERS=#{rails_version}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle exec rspec spec")
68
+ exit(1) unless success
69
+ end
70
+
71
+ desc "Rebundle for #{rails_version} with #{orm}"
72
+ task :"rebundle_#{rails_version.gsub('.', '')}_#{orm}" do
73
+ run_with_output "rm Gemfile_Rails_#{rails_version}_#{orm}_#{RUBY_VERSION}.lock Gemfile.lock"
74
+ set_versions(rails_version, orm)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1 @@
1
+ require 'mongo_session_store'
@@ -0,0 +1 @@
1
+ require 'mongo_session_store'
@@ -0,0 +1,49 @@
1
+ require 'securerandom'
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ module MongoSessionStore
6
+ autoload :VERSION, 'mongo_session_store/version'
7
+
8
+ def self.collection_name=(name)
9
+ @collection_name = name
10
+
11
+ if defined?(MongoStore::Session)
12
+ MongoStore::Session.reset_collection
13
+ end
14
+
15
+ if defined?(MongoMapperStore::Session)
16
+ MongoMapperStore::Session.set_collection_name(name)
17
+ end
18
+
19
+ if defined?(MongoidStore::Session)
20
+ MongoidStore::Session.store_in :collection => MongoSessionStore.collection_name
21
+ end
22
+
23
+ @collection_name
24
+ end
25
+
26
+ def self.collection_name
27
+ @collection_name
28
+ end
29
+
30
+ # default collection name for all the stores
31
+ self.collection_name = "sessions"
32
+ end
33
+
34
+ # we don't use autoloading because of thread concerns
35
+ # hence, this mess
36
+ load_errors = []
37
+
38
+ %w(mongo_mapper_store mongoid_store mongo_store).each do |store_name|
39
+ begin
40
+ require "mongo_session_store/#{store_name}"
41
+ rescue LoadError => e
42
+ load_errors << e
43
+ end
44
+ end
45
+
46
+ if load_errors.count == 3
47
+ message = "Could not load any session store!\n" + load_errors.map(&:message).join("\n")
48
+ raise LoadError, message
49
+ end
@@ -0,0 +1,22 @@
1
+ require 'mongo_mapper'
2
+ require 'mongo_session_store/mongo_store_base'
3
+
4
+ module ActionDispatch
5
+ module Session
6
+ class MongoMapperStore < MongoStoreBase
7
+
8
+ class Session
9
+ include MongoMapper::Document
10
+ set_collection_name MongoSessionStore.collection_name
11
+
12
+ key :_id, String
13
+ key :data, Binary, :default => Marshal.dump({})
14
+
15
+ timestamps!
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
22
+ MongoMapperStore = ActionDispatch::Session::MongoMapperStore
@@ -0,0 +1,78 @@
1
+ require 'mongo'
2
+ require 'mongo_session_store/mongo_store_base'
3
+
4
+ module ActionDispatch
5
+ module Session
6
+ class MongoStore < MongoStoreBase
7
+ class Session
8
+ attr_accessor :_id, :data, :created_at, :updated_at
9
+
10
+ def initialize(options = {})
11
+ @_id = options[:_id]
12
+ @data = options[:data] || BSON::Binary.new(Marshal.dump({}))
13
+ @created_at = options[:created_at]
14
+ @updated_at = options[:updated_at]
15
+ end
16
+
17
+ def self.load(options = {})
18
+ options[:data] = options["data"] if options["data"]
19
+ new(options)
20
+ end
21
+
22
+ def destroy
23
+ collection.remove :_id => _id
24
+ end
25
+
26
+ def save
27
+ @created_at ||= Time.now
28
+ @updated_at = Time.now
29
+
30
+ collection.save(
31
+ :_id => @_id,
32
+ :data => BSON::Binary.new(@data),
33
+ :created_at => @created_at,
34
+ :updated_at => @updated_at
35
+ )
36
+ end
37
+
38
+ def data=(stuff)
39
+ @data = stuff.to_s
40
+ end
41
+
42
+ def self.where(query = {})
43
+ collection.find(query).map { |doc| load(doc) }
44
+ end
45
+
46
+ def self.last
47
+ where.last
48
+ end
49
+
50
+ def self.database
51
+ if @database
52
+ @database
53
+ else
54
+ raise "MongoStore needs a database, e.g. MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')"
55
+ end
56
+ end
57
+
58
+ def self.database=(database)
59
+ @database = database
60
+ end
61
+
62
+ def self.collection
63
+ @collection ||= database[MongoSessionStore.collection_name]
64
+ end
65
+
66
+ def self.reset_collection
67
+ @collection = nil
68
+ end
69
+
70
+ def collection
71
+ self.class.collection
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ MongoStore = ActionDispatch::Session::MongoStore