mongo_session_store 3.2.2 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +37 -20
- data/.github/workflows/danger-comment.yml +10 -2
- data/.github/workflows/danger.yml +14 -37
- data/.github/workflows/lint.yml +29 -0
- data/.github/workflows/release.yml +31 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +152 -8
- data/.rubocop_todo.yml +224 -0
- data/.spellcheck.txt +54 -0
- data/CHANGELOG.md +26 -13
- data/CONTRIBUTING.md +80 -0
- data/Gemfile +10 -1
- data/Gemfile.danger +3 -3
- data/README.md +31 -75
- data/RELEASING.md +20 -22
- data/Rakefile +19 -58
- data/gemfiles/rails-8.1-mongo.gemfile +1 -0
- data/gemfiles/rails-8.1-mongoid.gemfile +1 -0
- data/gemfiles/rails-current-mongo.gemfile +21 -0
- data/gemfiles/rails-current-mongoid.gemfile +3 -0
- data/lib/mongo_session_store/mongo_store.rb +1 -1
- data/lib/mongo_session_store/mongo_store_base.rb +6 -0
- data/lib/mongo_session_store/version.rb +1 -1
- data/mongo_session_store.gemspec +1 -1
- data/script/release.rb +16 -0
- data/spec/.rubocop.yml +7 -1
- data/spec/lib/mongo_session_store/legacy_serialization_spec.rb +17 -0
- data/spec/lib/mongo_session_store/serialization_spec.rb +36 -0
- data/spec/lib/mongo_session_store/stale_sessions_spec.rb +77 -0
- data/spec/lib/mongo_session_store/version_spec.rb +8 -0
- data/spec/rails_helper.rb +4 -2
- data/spec/release/release_spec.rb +85 -0
- data/spec/spec_helper.rb +12 -2
- data/spec/support/helpers/test_database_helper.rb +1 -3
- metadata +19 -141
data/.spellcheck.txt
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
ActionDispatch
|
|
2
|
+
ActionPack
|
|
3
|
+
brianhempel
|
|
4
|
+
Brickley
|
|
5
|
+
Bruijn
|
|
6
|
+
BSON
|
|
7
|
+
Bundler
|
|
8
|
+
capybara
|
|
9
|
+
CHANGELOG
|
|
10
|
+
CLI
|
|
11
|
+
DataMapper
|
|
12
|
+
dblock
|
|
13
|
+
de
|
|
14
|
+
ENV
|
|
15
|
+
Gemfile
|
|
16
|
+
Gemfiles
|
|
17
|
+
gemspec
|
|
18
|
+
Hempel
|
|
19
|
+
hsbt
|
|
20
|
+
html
|
|
21
|
+
initializer
|
|
22
|
+
ismaster
|
|
23
|
+
JRuby
|
|
24
|
+
linter
|
|
25
|
+
lt
|
|
26
|
+
marshalled
|
|
27
|
+
md
|
|
28
|
+
memuller
|
|
29
|
+
middleware
|
|
30
|
+
Mongo
|
|
31
|
+
mongod
|
|
32
|
+
Mongoid
|
|
33
|
+
MongoMapper
|
|
34
|
+
MongoSessionStore
|
|
35
|
+
MongoSessionStoreRelease
|
|
36
|
+
MongoStore
|
|
37
|
+
Mérouze
|
|
38
|
+
nmerouze
|
|
39
|
+
ODM
|
|
40
|
+
Pitale
|
|
41
|
+
Racco
|
|
42
|
+
Rakefile
|
|
43
|
+
rb
|
|
44
|
+
README
|
|
45
|
+
rspec
|
|
46
|
+
RuboCop
|
|
47
|
+
RubyGems
|
|
48
|
+
shingara
|
|
49
|
+
streetlogics
|
|
50
|
+
stringify
|
|
51
|
+
tombruijn
|
|
52
|
+
tpitale
|
|
53
|
+
TTL
|
|
54
|
+
YAML
|
data/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
### 3.3.1 (2026/11/24)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
* [#59](https://github.com/mongoid/mongo_session_store/pull/59): Lint Markdown, YAML, and spelling with rubocop-md, rubocop-prose, rubocop-spellcheck, and rubocop-yaml in a separate Lint workflow, and clean up documentation - [@dblock](https://github.com/dblock).
|
|
4
|
+
* [#60](https://github.com/mongoid/mongo_session_store/pull/60): Run CI pushes only on the default branch, cancel superseded pull request runs, skip duplicate lint in the test matrix, and bound job times - [@dblock](https://github.com/dblock).
|
|
5
|
+
* [#61](https://github.com/mongoid/mongo_session_store/pull/61): Release with ruby-gem-release from a manually dispatched GitHub Actions workflow using RubyGems Trusted Publishing, with dry runs - [@dblock](https://github.com/dblock).
|
|
6
|
+
* [#63](https://github.com/mongoid/mongo_session_store/pull/63): Upgrade danger-pr-comment to 0.3.0 from the `danger` organization and skip empty Danger report comments - [@dblock](https://github.com/dblock).
|
|
7
|
+
* [#64](https://github.com/mongoid/mongo_session_store/pull/64): Ignore `.bundle` in every directory so the release workflow's clean-checkout check passes when Bundler writes `gemfiles/.bundle/config` - [@dblock](https://github.com/dblock).
|
|
8
|
+
|
|
9
|
+
### 3.3.0 (2026/10/18)
|
|
10
|
+
|
|
11
|
+
* [#57](https://github.com/mongoid/mongo_session_store/pull/57): Cover legacy session decoding and fix private decoder delegation in the plain-driver adapter - [@dblock](https://github.com/dblock).
|
|
12
|
+
* [#55](https://github.com/mongoid/mongo_session_store/pull/55): Add explicit bulk stale-session cleanup with an application-selected cutoff for both adapters - [@dblock](https://github.com/dblock).
|
|
13
|
+
* [#54](https://github.com/mongoid/mongo_session_store/pull/54): Document and test storing permitted parameter hashes rather than request-bearing Rails parameter objects in sessions - [@dblock](https://github.com/dblock).
|
|
14
|
+
* [#53](https://github.com/mongoid/mongo_session_store/pull/53): Cover Rails 6.1 through 8.0 in CI, update RuboCop, isolate Danger permissions, and report both adapters' coverage to Coveralls - [@dblock](https://github.com/dblock).
|
|
15
|
+
|
|
16
|
+
### 3.2.2 (2026/10/14)
|
|
4
17
|
|
|
5
18
|
* [#51](https://github.com/mongoid/mongo_session_store/pull/51): Modernize CI through Ruby 4.0, Rails 8.1, Mongoid 9 and MongoDB 8 while retaining legacy Rails combinations - [@dblock](https://github.com/dblock).
|
|
6
|
-
* [#51](https://github.com/mongoid/mongo_session_store/pull/51): Explicitly load ActionDispatch before defining the session store.
|
|
19
|
+
* [#51](https://github.com/mongoid/mongo_session_store/pull/51): Explicitly load ActionDispatch before defining the session store - [@dblock](https://github.com/dblock).
|
|
7
20
|
* [#48](https://github.com/mongoid/mongo_session_store/pull/48): Migrate Danger to danger-pr-comment - [@dblock](https://github.com/dblock).
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
### 3.2.1 (2020/04/27)
|
|
10
23
|
|
|
11
24
|
* [#45](https://github.com/mongoid/mongo_session_store/pull/45): Add Rails 6.0 to test setup - [@tombruijn](https://github.com/tombruijn).
|
|
12
25
|
* [#46](https://github.com/mongoid/mongo_session_store/pull/46): Fix Rack::Session::Cookie middleware bug - [@streetlogics](https://github.com/streetlogics) & [@tombruijn](https://github.com/tombruijn).
|
|
13
26
|
|
|
14
|
-
|
|
27
|
+
### 3.2.0 (2019/04/26)
|
|
15
28
|
|
|
16
29
|
* [#32](https://github.com/mongoid/mongo_session_store/pull/32): Add Rails 5.1 support - [@tombruijn](https://github.com/tombruijn).
|
|
17
30
|
* [#36](https://github.com/mongoid/mongo_session_store/pull/36): Add gem specific main error class - [@tombruijn](https://github.com/tombruijn).
|
|
18
31
|
* [#38](https://github.com/mongoid/mongo_session_store/pull/38): Support rails 5.2 - [@tombruijn](https://github.com/tombruijn).
|
|
19
32
|
* [#41](https://github.com/mongoid/mongo_session_store/pull/41): Add Ruby 2.5 and 2.6 support - [@tombruijn](https://github.com/tombruijn).
|
|
20
33
|
|
|
21
|
-
|
|
34
|
+
### 3.1.0 (2017/05/02)
|
|
22
35
|
|
|
23
36
|
* [#31](https://github.com/mongoid/mongo_session_store/pull/31): Add Rails 5.0 support - [@tombruijn](https://github.com/tombruijn).
|
|
24
37
|
|
|
25
|
-
|
|
38
|
+
### 3.0.0 (2017/04/27)
|
|
26
39
|
|
|
27
40
|
* Drop Ruby 1.8, 1.9 and 2.0 support - [@tombruijn](https://github.com/tombruijn).
|
|
28
41
|
* Drop explicit MongoMapper support - [@tombruijn](https://github.com/tombruijn).
|
|
@@ -41,7 +54,7 @@
|
|
|
41
54
|
* [#28](https://github.com/mongoid/mongo_session_store/pull/28): Support Ruby 2.4 - [@tombruijn](https://github.com/tombruijn).
|
|
42
55
|
* [#29](https://github.com/mongoid/mongo_session_store/pull/29): Use rails default session id generation - [@tombruijn](https://github.com/tombruijn).
|
|
43
56
|
|
|
44
|
-
|
|
57
|
+
### 2.0.0 (2010/10/13)
|
|
45
58
|
|
|
46
59
|
* Fix MongoMapper indexes - [@nmerouze](https://github.com/nmerouze).
|
|
47
60
|
* Add Rails 3 support for Mongoid - [@nmerouze](https://github.com/nmerouze).
|
|
@@ -49,23 +62,23 @@
|
|
|
49
62
|
* Support MongoMapper 0.7.5 - [@hsbt](https://github.com/hsbt).
|
|
50
63
|
* Fix issue where ActionPack expects `set_session` to return the (new) session_id when session is created successfully - [@memuller](https://github.com/memuller).
|
|
51
64
|
|
|
52
|
-
|
|
65
|
+
### 1.1.2 (2010/03/05)
|
|
53
66
|
|
|
54
67
|
* Generate a new session document if the current session document doesn't exist - [@shingara](https://github.com/shingara).
|
|
55
68
|
|
|
56
|
-
|
|
69
|
+
### 1.1.1 (2010/02/21)
|
|
57
70
|
|
|
58
71
|
* Fix `updated_at` index for MongoMapper session documents - [@nmerouze](https://github.com/nmerouze).
|
|
59
72
|
|
|
60
|
-
|
|
73
|
+
### 1.1.0 (2010/02/17)
|
|
61
74
|
|
|
62
75
|
* Add Mongoid support - [@nmerouze](https://github.com/nmerouze).
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
### 1.0.1 (2010/01/22)
|
|
65
78
|
|
|
66
79
|
* Add gemspec and specify actionpack dependency - [@nmerouze](https://github.com/nmerouze).
|
|
67
80
|
|
|
68
|
-
|
|
81
|
+
### 1.0.0 (2010/01/22)
|
|
69
82
|
|
|
70
83
|
* Initial version of the gem - [@tpitale](https://github.com/tpitale), [@compressed](https://github.com/compressed).
|
|
71
84
|
* MongoMapper session store support - [@tpitale](https://github.com/tpitale), [@compressed](https://github.com/compressed).
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Contributing to MongoSessionStore
|
|
2
|
+
|
|
3
|
+
## Test Environment
|
|
4
|
+
|
|
5
|
+
Start MongoDB with this script:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
script/testenv
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Testing
|
|
12
|
+
|
|
13
|
+
To run the tests for a specific store. You must first set a `BUNDLE_GEMFILE` in the environment.
|
|
14
|
+
|
|
15
|
+
You can also use Docker, see the section below this one.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
bundle exec rake
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
BUNDLE_GEMFILE=gemfiles/rails-5.0-mongo.gemfile bundle exec rake
|
|
25
|
+
BUNDLE_GEMFILE=gemfiles/rails-5.0-mongoid.gemfile bundle exec rake
|
|
26
|
+
BUNDLE_GEMFILE=gemfiles/rails-5.1-mongo.gemfile bundle exec rake
|
|
27
|
+
BUNDLE_GEMFILE=gemfiles/rails-5.1-mongoid.gemfile bundle exec rake
|
|
28
|
+
BUNDLE_GEMFILE=gemfiles/rails-5.2-mongo.gemfile bundle exec rake
|
|
29
|
+
BUNDLE_GEMFILE=gemfiles/rails-5.2-mongoid.gemfile bundle exec rake
|
|
30
|
+
BUNDLE_GEMFILE=gemfiles/rails-6.0-mongo.gemfile bundle exec rake
|
|
31
|
+
BUNDLE_GEMFILE=gemfiles/rails-6.0-mongoid.gemfile bundle exec rake
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For Rails 6.1 and newer, use `gemfiles/rails-current-mongo.gemfile` or `gemfiles/rails-current-mongoid.gemfile` with `RAILS_VERSION` and, for Mongoid, `MONGOID_VERSION` constraints:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
RAILS_VERSION='~> 7.2.0' MONGOID_VERSION='~> 9.0' BUNDLE_GEMFILE=gemfiles/rails-current-mongoid.gemfile bundle exec rake test
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
For Rails 8.0, also set `SQLITE_VERSION='~> 2.1'`; the dedicated Rails 8.1 Gemfiles already select SQLite 2.
|
|
41
|
+
|
|
42
|
+
Set `MONGODB_HOST` and `MONGODB_PORT` to use a non-default test server. The default is `127.0.0.1:27017`.
|
|
43
|
+
|
|
44
|
+
### Docker Testing
|
|
45
|
+
|
|
46
|
+
To run tests in a Docker container with a specific Ruby version and gemfile:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
BUNDLE_GEMFILE=gemfiles/rails-6.0-mongo.gemfile script/test
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The `BUNDLE_GEMFILE` environment variable is required. Ruby version defaults to 3.4 but can be customized:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
RUBY_VERSION=2.7 BUNDLE_GEMFILE=gemfiles/rails-6.0-mongo.gemfile script/test
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Performance Benchmark
|
|
59
|
+
|
|
60
|
+
The repository includes a performance benchmark. It runs against all available included stores and outputs the results.
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
bundle exec ruby perf/benchmark.rb
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Releases
|
|
67
|
+
|
|
68
|
+
To create a new release checkout the `master` branch and make sure it's in the right state to release. Run the `release` Rake task and follow the instructions.
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
bundle exec rake release
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Run `bundle exec rake lint` on MRI Ruby 3.3 or newer to check Ruby, Markdown, YAML, and spelling, and add reviewed project vocabulary to `.spellcheck.txt`.
|
|
75
|
+
|
|
76
|
+
[mongodb]: https://www.mongodb.com/
|
|
77
|
+
[mongo]: https://github.com/mongodb/mongo-ruby-driver
|
|
78
|
+
[mongoid]: https://www.mongodb.com/docs/mongoid/current/
|
|
79
|
+
[rails]: https://rubyonrails.org/
|
|
80
|
+
[issue-rails3]: https://github.com/mongoid/mongo_session_store/issues/17
|
data/Gemfile
CHANGED
|
@@ -2,4 +2,13 @@ source "https://rubygems.org"
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
group :development, :test do
|
|
6
|
+
if RUBY_ENGINE == "ruby" && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3")
|
|
7
|
+
gem "rubocop", "~> 1.92"
|
|
8
|
+
gem "rubocop-md", "~> 3.0", :require => false
|
|
9
|
+
gem "rubocop-prose", "~> 0.2", :require => false
|
|
10
|
+
gem "rubocop-rake", "~> 0.7", :require => false
|
|
11
|
+
gem "rubocop-spellcheck", "~> 0.2", :require => false
|
|
12
|
+
gem "rubocop-yaml", "~> 0.1.0", :require => false
|
|
13
|
+
end
|
|
14
|
+
end
|
data/Gemfile.danger
CHANGED
data/README.md
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
# MongoSessionStore
|
|
2
2
|
|
|
3
|
-
[](http://badge.fury.io/rb/mongo_session_store)
|
|
5
|
-
[](https://codeclimate.com/github/mongoid/mongo_session_store)
|
|
3
|
+
[](https://github.com/mongoid/mongo_session_store/actions/workflows/ci.yml?query=branch%3Amain) [](https://badge.fury.io/rb/mongo_session_store) [](https://coveralls.io/github/mongoid/mongo_session_store?branch=main)
|
|
6
4
|
|
|
7
5
|
## Description
|
|
8
6
|
|
|
9
|
-
MongoSessionStore is a [Rails][rails]-compatible session store for
|
|
10
|
-
|
|
11
|
-
Driver][mongo]. It also allows for custom Mongo session store that works with
|
|
12
|
-
any (or no!) Mongo ODM.
|
|
7
|
+
MongoSessionStore is a [Rails][rails]-compatible session store for [MongoDB][mongodb] using either [Mongoid][mongoid] or the [MongoDB Ruby
|
|
8
|
+
Driver][mongo]. It also allows for custom Mongo session store that works with any (or no!) Mongo ODM.
|
|
13
9
|
|
|
14
|
-
MongoSessionStore version 3 is compatible with Rails 5.0+. For Rails
|
|
15
|
-
3 support please check out issue [#17][issue-rails3] for options and let us
|
|
16
|
-
know if you need support.
|
|
10
|
+
MongoSessionStore version 3 is compatible with Rails 5.0+. For Rails 3 support please check out issue [#17][issue-rails3] for options and let us know if you need support.
|
|
17
11
|
|
|
18
12
|
## Installation
|
|
19
13
|
|
|
20
|
-
Add the `mongo_session_store` gem to your `Gemfile`.
|
|
21
|
-
Use either the `mongo` or `mongoid` gems in combination with this gem.
|
|
14
|
+
Add the `mongo_session_store` gem to your `Gemfile`. Use either the `mongo` or `mongoid` gems in combination with this gem.
|
|
22
15
|
|
|
23
16
|
```ruby
|
|
24
17
|
# Gemfile
|
|
@@ -28,8 +21,7 @@ gem "mongoid"
|
|
|
28
21
|
gem "mongo_session_store"
|
|
29
22
|
```
|
|
30
23
|
|
|
31
|
-
Configure the session store in the session_store initializer in your Rails
|
|
32
|
-
project.
|
|
24
|
+
Configure the session store in the session_store initializer in your Rails project.
|
|
33
25
|
|
|
34
26
|
```ruby
|
|
35
27
|
# config/initializers/session_store.rb
|
|
@@ -38,15 +30,13 @@ project.
|
|
|
38
30
|
MyApp::Application.config.session_store :mongoid_store
|
|
39
31
|
|
|
40
32
|
# MongoDB Ruby Driver/anything else
|
|
41
|
-
MongoStore::Session.database = Mongo::Client.new(["127.0.0.1:27017"], database
|
|
33
|
+
MongoStore::Session.database = Mongo::Client.new(["127.0.0.1:27017"], :database => "my_app_development")
|
|
42
34
|
MyApp::Application.config.session_store :mongo_store
|
|
43
35
|
```
|
|
44
36
|
|
|
45
37
|
## Configuration
|
|
46
38
|
|
|
47
|
-
By default, the sessions will be stored in the "sessions" collection in
|
|
48
|
-
MongoDB. If you want to use a different collection, you can set that in the
|
|
49
|
-
session_store initializer.
|
|
39
|
+
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 session_store initializer.
|
|
50
40
|
|
|
51
41
|
```ruby
|
|
52
42
|
# config/initializers/session_store.rb
|
|
@@ -55,8 +45,7 @@ MongoSessionStore.collection_name = "client_sessions"
|
|
|
55
45
|
|
|
56
46
|
## Usage
|
|
57
47
|
|
|
58
|
-
By default nothing has to be done outside the [installation](#installation) of
|
|
59
|
-
the gem.
|
|
48
|
+
By default nothing has to be done outside the [installation](#installation) of the gem.
|
|
60
49
|
|
|
61
50
|
It's possible to query your sessions.
|
|
62
51
|
|
|
@@ -68,77 +57,47 @@ MongoidStore::Session.where(:updated_at.gt => 2.days.ago)
|
|
|
68
57
|
MongoStore::Session.where("updated_at" => { "$gt" => 2.days.ago })
|
|
69
58
|
```
|
|
70
59
|
|
|
71
|
-
|
|
60
|
+
### Serializable Session Values
|
|
72
61
|
|
|
73
|
-
|
|
62
|
+
Both adapters serialize session data with Ruby's `Marshal`. Store serializable values such as strings, numbers, arrays, and hashes, not requests, input streams, or uploaded files. Serialization errors are raised rather than silently discarding data.
|
|
74
63
|
|
|
75
|
-
|
|
64
|
+
Do not store `ActionController::Parameters` objects directly in the session. On Rails 7 and newer, their logging context can retain the request and its input stream, causing `TypeError: can't dump IO` (or a similar error for `StringIO`). A nested `params[:search]` object can retain that context too. Explicitly permit the values your application needs and convert them to a hash before saving:
|
|
76
65
|
|
|
66
|
+
```ruby
|
|
67
|
+
session[:search] = params.require(:search).permit(:query, :sort).to_h
|
|
77
68
|
```
|
|
78
|
-
script/testenv
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Testing
|
|
82
69
|
|
|
83
|
-
|
|
84
|
-
the environment.
|
|
70
|
+
This stores the permitted values without the request context. It does not make uploaded files or other non-serializable values serializable; store a durable identifier for those instead.
|
|
85
71
|
|
|
86
|
-
|
|
72
|
+
### Deleting Stale Sessions
|
|
87
73
|
|
|
88
|
-
|
|
89
|
-
bundle exec rake
|
|
90
|
-
```
|
|
74
|
+
Sessions are not automatically expired or deleted. To opt in to cleanup, call the store's `delete_stale_sessions` method with an explicit `Time` cutoff:
|
|
91
75
|
|
|
92
|
-
|
|
76
|
+
```ruby
|
|
77
|
+
# Mongoid
|
|
78
|
+
MongoidStore.delete_stale_sessions(:before => 1.week.ago)
|
|
93
79
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
BUNDLE_GEMFILE=gemfiles/rails-5.0-mongoid.gemfile bundle exec rake
|
|
97
|
-
BUNDLE_GEMFILE=gemfiles/rails-5.1-mongo.gemfile bundle exec rake
|
|
98
|
-
BUNDLE_GEMFILE=gemfiles/rails-5.1-mongoid.gemfile bundle exec rake
|
|
99
|
-
BUNDLE_GEMFILE=gemfiles/rails-5.2-mongo.gemfile bundle exec rake
|
|
100
|
-
BUNDLE_GEMFILE=gemfiles/rails-5.2-mongoid.gemfile bundle exec rake
|
|
101
|
-
BUNDLE_GEMFILE=gemfiles/rails-6.0-mongo.gemfile bundle exec rake
|
|
102
|
-
BUNDLE_GEMFILE=gemfiles/rails-6.0-mongoid.gemfile bundle exec rake
|
|
80
|
+
# MongoDB Ruby Driver
|
|
81
|
+
MongoStore.delete_stale_sessions(:before => 1.week.ago)
|
|
103
82
|
```
|
|
104
83
|
|
|
105
|
-
|
|
84
|
+
The method returns the number deleted and uses the configured session collection. It performs a bulk database deletion without loading session data or running model callbacks. Only records whose `updated_at` is strictly earlier than the cutoff are deleted; records at the cutoff or without a timestamp are retained. Invalid cutoffs raise `ArgumentError`, and database errors propagate to the caller.
|
|
106
85
|
|
|
107
|
-
|
|
86
|
+
Run cleanup explicitly from a scheduled job or a Rails runner command, choosing a retention policy appropriate for your application:
|
|
108
87
|
|
|
109
88
|
```sh
|
|
110
|
-
|
|
89
|
+
bin/rails runner 'MongoidStore.delete_stale_sessions(before: 1.week.ago)'
|
|
111
90
|
```
|
|
112
91
|
|
|
113
|
-
|
|
92
|
+
Deleting a session signs that session out on its next request. Cleanup is not cookie expiration or a guarantee of inactivity-based logout: `updated_at` tracks session saves, and a request that does not save the session may not refresh it. No default maximum age, background job, or TTL index is installed. For large collections, consider creating an ordinary index on `updated_at` as part of your database setup.
|
|
114
93
|
|
|
115
|
-
|
|
116
|
-
RUBY_VERSION=2.7 BUNDLE_GEMFILE=gemfiles/rails-6.0-mongo.gemfile script/test
|
|
117
|
-
```
|
|
94
|
+
## Contributing
|
|
118
95
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
The repository includes a performance benchmark. It runs against all available
|
|
122
|
-
included stores and outputs the results.
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
bundle exec ruby perf/benchmark.rb
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### Releases
|
|
129
|
-
|
|
130
|
-
To create a new release checkout the `master` branch and make sure it's in the
|
|
131
|
-
right state to release. Run the `release` Rake task and follow the
|
|
132
|
-
instructions.
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
bundle exec rake release
|
|
136
|
-
```
|
|
96
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), [CHANGELOG.md](CHANGELOG.md), and [RELEASING.md](RELEASING.md).
|
|
137
97
|
|
|
138
98
|
## Contributors
|
|
139
99
|
|
|
140
|
-
MongoSessionStore started as a fork of the DataMapper session store, modified
|
|
141
|
-
to work with MongoMapper, Mongoid and the Mongo Ruby Driver.
|
|
100
|
+
MongoSessionStore started as a fork of the DataMapper session store, modified to work with MongoMapper, Mongoid and the Mongo Ruby Driver.
|
|
142
101
|
|
|
143
102
|
Much thanks to all contributors:
|
|
144
103
|
|
|
@@ -157,10 +116,7 @@ Released under the MIT license. See the [LICENSE](LICENSE) file.
|
|
|
157
116
|
|
|
158
117
|
[mongodb]: https://www.mongodb.com/
|
|
159
118
|
[mongo]: https://github.com/mongodb/mongo-ruby-driver
|
|
160
|
-
[mongoid]:
|
|
161
|
-
[rails]:
|
|
119
|
+
[mongoid]: https://www.mongodb.com/docs/mongoid/current/
|
|
120
|
+
[rails]: https://rubyonrails.org/
|
|
162
121
|
|
|
163
122
|
[issue-rails3]: https://github.com/mongoid/mongo_session_store/issues/17
|
|
164
|
-
## CI compatibility
|
|
165
|
-
|
|
166
|
-
CI retains the Rails 5.0–6.0 dependency files and exercises both Mongo and Mongoid session stores with Rails 8.1, Mongoid 9, Ruby 3.4/4.0 and MongoDB 8.0; use `BUNDLE_GEMFILE=gemfiles/rails-8.1-mongoid.gemfile bundle exec rake test` for the modern Mongoid suite, which shares the minimal Rails 6 integration app.
|
data/RELEASING.md
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
# Releasing
|
|
1
|
+
# Releasing MongoSessionStore
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Releases use [ruby-gem-release](https://github.com/dblock/ruby-gem-release) 0.9.0 through a manually dispatched [Release workflow](.github/workflows/release.yml). Keep the `ruby-gem-release` gem in [Gemfile](Gemfile) and the reusable workflow in `release.yml` pinned to the same version. The workflow publishes through RubyGems Trusted Publishing, so no RubyGems API key or one-time password is needed. It only runs from `main` in `mongoid/mongo_session_store`. The local Bundler `rake release`, `release:rubygem_push`, and `release:source_control_push` tasks are disabled.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## One-Time Setup
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
2. Choose the next semantic version, update `lib/mongo_session_store/version.rb`, and replace the unreleased changelog heading with the version and release date. Remove the contribution placeholder.
|
|
9
|
-
3. With MongoDB running, install dependencies and run `bundle exec rake test` using each supported adapter's `BUNDLE_GEMFILE`, for example `gemfiles/rails-6.0-mongo.gemfile` and `gemfiles/rails-6.0-mongoid.gemfile`. Run `bundle exec rubocop` with the default Gemfile.
|
|
10
|
-
4. Commit the preparation, push `main`, and wait for the complete GitHub Actions matrix to pass for that commit.
|
|
7
|
+
Before the first automated release, a maintainer must:
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
1. Create the GitHub environment `release` in `mongoid/mongo_session_store`, for example with `gh api --method PUT repos/mongoid/mongo_session_store/environments/release`, and restrict its deployment branches to `main`. Add required reviewers to require maintainer approval before publication.
|
|
10
|
+
2. At [mongo_session_store's trusted publishers](https://rubygems.org/gems/mongo_session_store/trusted_publishers), add a GitHub Actions publisher with repository owner `mongoid`, repository `mongo_session_store`, workflow filename `release.yml`, environment `release`, and the separate workflow repository owner `dblock` and repository `ruby-gem-release`.
|
|
11
|
+
3. Allow GitHub Actions to push release commits and `v*` tags to `main`. See the upstream [setup and permissions guidance](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/RELEASING.md#one-time-setup).
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
Verify the setup without publishing with a [dry run](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#dry-run), which never edits files, builds, pushes, or publishes:
|
|
15
14
|
|
|
16
15
|
```sh
|
|
17
|
-
|
|
18
|
-
gem build mongo_session_store.gemspec
|
|
19
|
-
git tag "v$version"
|
|
20
|
-
git push origin "v$version"
|
|
21
|
-
gem push "mongo_session_store-$version.gem"
|
|
16
|
+
gh workflow run release.yml --repo mongoid/mongo_session_store --ref main -f dry-run=true
|
|
22
17
|
```
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
## Prepare
|
|
20
|
+
|
|
21
|
+
Start with a clean, up-to-date `main` and verify that the latest [CI checks](https://github.com/mongoid/mongo_session_store/actions) pass. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes. Check `VERSION` in [lib/mongo_session_store/version.rb](lib/mongo_session_store/version.rb) and the matching `(Next)` heading in [CHANGELOG.md](CHANGELOG.md), and change both in a pull request if needed, or pass a `version` override when dispatching. The workflow dates the `(Next)` heading using `YYYY/MM/DD` and removes the `* Your contribution here.` placeholder; a section without notes cannot be released.
|
|
22
|
+
|
|
23
|
+
Release automation requires MRI Ruby 3.3 or newer; the release dependency and tasks are skipped on older Ruby versions and JRuby. Release specs in [spec/release](spec/release) run the actual release tasks against a local fixture with the [ruby-gem-release RSpec helpers](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/testing.md), without contacting RubyGems or GitHub.
|
|
24
|
+
|
|
25
|
+
## Publish
|
|
25
26
|
|
|
26
27
|
```sh
|
|
27
|
-
gh
|
|
28
|
-
--verify-tag --title "$version" --notes-file /path/to/release-notes.md --latest
|
|
28
|
+
gh workflow run release.yml --repo mongoid/mongo_session_store --ref main
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
Verify the
|
|
32
|
-
|
|
33
|
-
If publication is interrupted, check the remote tag, RubyGems version, and GitHub release first. Resume only the missing step; never move a published tag or rebuild an already published version. If the gem push needs a new code, retry that command with `--otp CODE`.
|
|
31
|
+
Pass `-f version=x.y.z` to release a different version. Dispatching starts a real release; do not merge into `main` while it runs. The workflow prepares the release commit, starts MongoDB 8.0, runs lint and specs on Ruby 3.3, builds the gem, preserves recovery artifacts, publishes to RubyGems, pushes the release commit and `v` tag, and creates a GitHub Release with the changelog notes and the gem attached. It then increments the patch version, adds a new `(Next)` section, and pushes the next development commit. Verify the published version on [RubyGems](https://rubygems.org/gems/mongo_session_store), the tag, the [GitHub Release](https://github.com/mongoid/mongo_session_store/releases), and the next development commit.
|
|
34
32
|
|
|
35
|
-
##
|
|
33
|
+
## Recover a Partial Release
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
Inspect the failed run, RubyGems, remote commits and tags, and the GitHub Release before retrying. Publication may have succeeded even if a later step failed. Never move a published tag or republish a version with different contents. Use the run's retained recovery artifacts and the upstream [recovery instructions](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#recovery-artifacts).
|
data/Rakefile
CHANGED
|
@@ -23,68 +23,29 @@ end
|
|
|
23
23
|
desc "Run the mongo_session_store gem test suite."
|
|
24
24
|
RSpec::Core::RakeTask.new :test => :mongo_prepare
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
task :release do
|
|
28
|
-
GEMSPEC_NAME = "mongo_session_store"
|
|
29
|
-
GEM_NAME = "mongo_session_store"
|
|
30
|
-
VERSION_FILE = "lib/mongo_session_store/version.rb"
|
|
26
|
+
require "bundler/gem_tasks"
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
load File.expand_path(VERSION_FILE)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
raise "$EDITOR should be set" unless ENV["EDITOR"]
|
|
40
|
-
|
|
41
|
-
def build_and_push_gem
|
|
42
|
-
puts "# Building gem"
|
|
43
|
-
system "gem build #{GEMSPEC_NAME}.gemspec"
|
|
44
|
-
puts "# Publishing Gem"
|
|
45
|
-
system "gem push #{GEM_NAME}-#{gem_version}.gem"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def update_repo
|
|
49
|
-
puts `git commit -am "Bump to #{version} [ci skip]"`
|
|
50
|
-
begin
|
|
51
|
-
puts `git tag #{version}`
|
|
52
|
-
puts `git push origin #{version}`
|
|
53
|
-
puts `git push origin master`
|
|
54
|
-
rescue
|
|
55
|
-
raise %(Tag: "#{version}" already exists)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
28
|
+
if RUBY_ENGINE == "ruby" && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3") &&
|
|
29
|
+
Gem.loaded_specs.key?("ruby-gem-release")
|
|
30
|
+
require_relative "script/release"
|
|
31
|
+
MongoSessionStoreRelease.workflow.install_tasks
|
|
58
32
|
|
|
59
|
-
|
|
60
|
-
|
|
33
|
+
%w[release release:rubygem_push release:source_control_push].each do |name|
|
|
34
|
+
Rake::Task[name].clear
|
|
35
|
+
desc "Disabled; releases run through GitHub Actions, see RELEASING.md"
|
|
36
|
+
task(name) { abort "#{name} is disabled; releases run through GitHub Actions, see RELEASING.md" }
|
|
61
37
|
end
|
|
38
|
+
end
|
|
62
39
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
@version ||= "v" << gem_version
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def git_status_to_array(changes)
|
|
72
|
-
changes.split("\n").map { |change| change.gsub(/^.. /, "") }
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
raise "Branch should hold no uncommitted file change)" unless changes.empty?
|
|
76
|
-
|
|
77
|
-
reload_version
|
|
40
|
+
lint = RUBY_ENGINE == "ruby" && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3") &&
|
|
41
|
+
Gem.loaded_specs.key?("rubocop")
|
|
42
|
+
if lint
|
|
43
|
+
require "rubocop/rake_task"
|
|
44
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
78
45
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
reload_version
|
|
82
|
-
build_and_push_gem
|
|
83
|
-
update_repo
|
|
84
|
-
else
|
|
85
|
-
raise "Actually change the version in: #{VERSION_FILE}"
|
|
86
|
-
end
|
|
46
|
+
desc "Lint Ruby, Markdown, YAML, and spelling"
|
|
47
|
+
task :lint => :rubocop
|
|
87
48
|
end
|
|
88
49
|
|
|
89
|
-
desc "Default task for Rake. Runs test suite."
|
|
90
|
-
task :default => :test
|
|
50
|
+
desc "Default task for Rake. Runs lint, where available, and the test suite."
|
|
51
|
+
task :default => (lint ? [:rubocop, :test] : [:test])
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gem "rails", ENV.fetch("RAILS_VERSION", "~> 7.2.0")
|
|
4
|
+
gem "mongo", "~> 2.0"
|
|
5
|
+
gem "devise", "~> 4.9"
|
|
6
|
+
gem "sqlite3", ENV.fetch("SQLITE_VERSION", "~> 1.4")
|
|
7
|
+
gem "logger"
|
|
8
|
+
gem "bigdecimal"
|
|
9
|
+
gem "mutex_m"
|
|
10
|
+
gem "drb"
|
|
11
|
+
gem "base64"
|
|
12
|
+
gem "benchmark"
|
|
13
|
+
gem "ostruct"
|
|
14
|
+
gem "simplecov", "~> 0.22", :require => false if ENV["COVERAGE"] == "true"
|
|
15
|
+
|
|
16
|
+
if RUBY_ENGINE == "ruby" && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3")
|
|
17
|
+
gem "commonmarker", "~> 2.10", :require => false
|
|
18
|
+
gem "ruby-gem-release", "0.9.0", :require => false
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
gemspec :path => "../"
|
|
@@ -16,6 +16,12 @@ module ActionDispatch
|
|
|
16
16
|
self::Session
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
def self.delete_stale_sessions(before:)
|
|
20
|
+
raise ArgumentError, "before must be a Time" unless before.is_a?(Time)
|
|
21
|
+
|
|
22
|
+
session_class.collection.find("updated_at" => { "$lt" => before.getutc }).delete_many.deleted_count
|
|
23
|
+
end
|
|
24
|
+
|
|
19
25
|
private
|
|
20
26
|
|
|
21
27
|
def session_class
|