mongoid-collection-snapshot 1.3.2 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 413b563ac9f33351ab543a7e72f56e7c5402802c
4
- data.tar.gz: 803caae2c222ab14a8cbdcef6b1390a941cfed87
2
+ SHA256:
3
+ metadata.gz: 50e1fc889a97e8dc1f4957f182b440141ca48643eddc78c43e6449a08c289f9a
4
+ data.tar.gz: 4f9e9397dfca958344f59478de0ca0985ed6a5cfadb5591f2b7bf05693bab8ca
5
5
  SHA512:
6
- metadata.gz: 8f27da72bb8c0308a12d0f79b7a06afd5c9317407036231bdda9995b9eec05f845641116d44fc28c042c758e2ce278c7cb31ed685d9ced8c5ea67e072f171ef9
7
- data.tar.gz: f48f7d1e8414a9dbd7ba41f541d86b57382490ed7ea51a1aa2e93b4bb522f2d960ac9f22daea95ffb14c0965e1d577a94da20c1f258706cc88d04a3b5490ee7e
6
+ metadata.gz: 5e93438cc0c1e69c936e0bbb632c1c1306b8ef636d927f7cbed708e31e2ff42d95fc33ac0db69ff0460bbf9550e049dddd41975d601c60df51fd729c01e94f72
7
+ data.tar.gz: 21ec0317e6433d12d45fd915f229e454b6d9536e5d19b55271d423e17b934a387c6e9c40abed0f693457fe572b2934a5a5a2639a286c5c27786022e3c2869cfc
@@ -0,0 +1,11 @@
1
+ name: Danger Comment
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows: [Danger]
6
+ types: [completed]
7
+
8
+ jobs:
9
+ comment:
10
+ uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@v0.1.0
11
+ secrets: inherit
@@ -0,0 +1,13 @@
1
+ name: Danger
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened, edited, synchronize]
6
+
7
+ jobs:
8
+ danger:
9
+ uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.1.0
10
+ secrets: inherit
11
+ with:
12
+ ruby-version: '3.3'
13
+ bundler-cache: true
@@ -0,0 +1,64 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ permissions:
6
+ contents: read
7
+
8
+ jobs:
9
+ test:
10
+ name: Ruby ${{ matrix.ruby }} / Mongoid ${{ matrix.mongoid }} / MongoDB ${{ matrix.mongodb }}
11
+ runs-on: ubuntu-22.04
12
+ timeout-minutes: 15
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ include:
17
+ - { ruby: '2.1.9', mongoid: '3', mongodb: '2.6', bundler: '1.17.3', coverage: true }
18
+ - { ruby: '2.3.8', mongoid: '4', mongodb: '2.6', bundler: '2.3.26' }
19
+ - { ruby: '2.3.8', mongoid: '5', mongodb: '4.0', bundler: '2.3.26', coverage: true }
20
+ - { ruby: '2.5.9', mongoid: '6', mongodb: '4.0', bundler: '2.3.26' }
21
+ - { ruby: '2.7.8', mongoid: '7', mongodb: '4.4', bundler: '2.4.22' }
22
+ - { ruby: '3.2', mongoid: '8', mongodb: '6.0', bundler: default }
23
+ - { ruby: '3.3', mongoid: '9', mongodb: '7.0', bundler: default }
24
+ - { ruby: '3.4', mongoid: '9', mongodb: '8.0', bundler: default }
25
+ - { ruby: '4.0', mongoid: '9', mongodb: '8.0', bundler: default, coverage: true }
26
+ env:
27
+ MONGOID_VERSION: ${{ matrix.mongoid }}
28
+ COVERAGE: ${{ matrix.coverage }}
29
+ services:
30
+ mongodb:
31
+ image: mongo:${{ matrix.mongodb }}
32
+ ports: ['27017:27017']
33
+ options: >-
34
+ --health-cmd "bash -c 'echo > /dev/tcp/127.0.0.1/27017'"
35
+ --health-interval 5s --health-timeout 5s --health-retries 20
36
+ steps:
37
+ - uses: actions/checkout@v6
38
+ - uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: ${{ matrix.ruby }}
41
+ bundler: ${{ matrix.bundler }}
42
+ bundler-cache: true
43
+ - run: bundle exec rake spec
44
+ - name: Report coverage to Coveralls
45
+ if: matrix.coverage
46
+ uses: coverallsapp/github-action@v2
47
+ with:
48
+ github-token: ${{ secrets.GITHUB_TOKEN }}
49
+ file: coverage/.resultset.json
50
+ format: simplecov
51
+ parallel: true
52
+ flag-name: mongoid-${{ matrix.mongoid }}
53
+ - if: matrix.mongoid == '6'
54
+ run: bundle exec rake rubocop
55
+
56
+ coverage:
57
+ needs: test
58
+ if: ${{ always() && needs.test.result == 'success' }}
59
+ runs-on: ubuntu-latest
60
+ steps:
61
+ - uses: coverallsapp/github-action@v2
62
+ with:
63
+ github-token: ${{ secrets.GITHUB_TOKEN }}
64
+ parallel-finished: true
data/.rubocop_todo.yml CHANGED
@@ -26,7 +26,7 @@ Lint/UselessAccessModifier:
26
26
 
27
27
  # Offense count: 3
28
28
  Metrics/AbcSize:
29
- Max: 37
29
+ Max: 38
30
30
 
31
31
  # Offense count: 5
32
32
  # Configuration parameters: CountComments, ExcludedMethods.
data/CHANGELOG.md CHANGED
@@ -1,14 +1,25 @@
1
- ### 1.3.2 (6/4/2017)
1
+ ### 1.4.0 (2026/10/18)
2
+
3
+ * [#20](https://github.com/mongoid/mongoid-collection-snapshot/pull/20): Combine coverage from real legacy and modern Mongoid integration tests - [@dblock](https://github.com/dblock).
4
+ * [#18](https://github.com/mongoid/mongoid-collection-snapshot/pull/18): Migrate Danger to use danger-pr-comment workflows, retaining legacy Ruby compatibility - [@dblock](https://github.com/dblock).
5
+ * [#19](https://github.com/mongoid/mongoid-collection-snapshot/pull/19): Add `snapshot.collections` discovery from the configured snapshot database, independent of dynamically generated document classes; use the same exact-name matching for cleanup - [@dblock](https://github.com/dblock).
6
+
7
+ ### 1.3.3 (2026/10/14)
8
+
9
+ * [#17](https://github.com/mongoid/mongoid-collection-snapshot/pull/17): Generate real SimpleCov coverage in one modern CI job and report to Coveralls; scope CI and coverage badges to upstream master - [@dblock](https://github.com/dblock).
10
+ * [#17](https://github.com/mongoid/mongoid-collection-snapshot/pull/17): Modernize CI with GitHub Actions through Ruby 4.0, Mongoid 9, and MongoDB Server 8.0; use current Mongoid client and public snapshot storage APIs while retaining legacy coverage - [@dblock](https://github.com/dblock).
11
+
12
+ ### 1.3.2 (2017/06/04)
2
13
 
3
14
  * [#13](https://github.com/mongoid/mongoid-collection-snapshot/issues/13): Fix: use correct database on all threads - [@dblock](https://github.com/dblock).
4
15
  * [#7](https://github.com/mongoid/mongoid-collection-snapshot/issues/7): Fix: `max_collection_snapshot_instances` broken - [@dblock](https://github.com/dblock).
5
16
 
6
- ### 1.3.1 (5/22/2017)
17
+ ### 1.3.1 (2017/05/22)
7
18
 
8
19
  * [#11](https://github.com/mongoid/mongoid-collection-snapshot/pull/11): Fix: incorrect connection used with Mongoid 6 - [@dblock](https://github.com/dblock).
9
20
  * [#8](https://github.com/mongoid/mongoid-collection-snapshot/pull/8): Lock mongoid-compatibility at 0.4.0 or newer - [@dblock](https://github.com/dblock).
10
21
 
11
- ### 1.3.0 (1/20/2017)
22
+ ### 1.3.0 (2017/01/20)
12
23
 
13
24
  * [#2](https://github.com/mongoid/mongoid-collection-snapshot/pull/2): Support for Mongoid 6 - [@dblock](https://github.com/dblock).
14
25
  * [#1](https://github.com/mongoid/mongoid-collection-snapshot/pull/1): Gem renamed to mongoid-collection-snapshot and forked to the [mongoid org](https://github.com/mongoid) - [@dblock](https://github.com/dblock).
data/Dangerfile CHANGED
@@ -1 +1,5 @@
1
- danger.import_dangerfile(gem: "mongoid-danger")
1
+ # frozen_string_literal: true
2
+
3
+ danger.import_dangerfile(gem: 'danger-pr-comment')
4
+
5
+ changelog.check!
data/Gemfile CHANGED
@@ -1,24 +1,21 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- case version = ENV['MONGOID_VERSION'] || '6.0'
6
- when /^6/
7
- gem 'mongoid', '~> 6.0'
8
- when /^5/
9
- gem 'mongoid', '~> 5.0'
10
- when /^4/
11
- gem 'mongoid', '~> 4.0'
12
- when /^3/
13
- gem 'mongoid', '~> 3.1'
14
- else
15
- gem 'mongoid', version
16
- end
5
+ version = ENV['MONGOID_VERSION'] || '9'
6
+ gem 'bigdecimal' if RUBY_VERSION >= '3.4'
7
+ gem 'logger' if RUBY_VERSION >= '3.4'
8
+ gem 'mongoid', version =~ /\A\d+\z/ ? "~> #{version}.0" : version
17
9
 
18
10
  group :development, :test do
19
- gem 'mongoid-danger', '~> 0.1.1'
11
+ if RUBY_VERSION >= '2.7'
12
+ gem 'danger'
13
+ gem 'danger-changelog', require: false
14
+ gem 'danger-pr-comment', require: false
15
+ end
20
16
  gem 'rake'
21
17
  gem 'rspec', '~> 3.1'
22
18
  gem 'rubocop', '0.47.1'
19
+ gem 'simplecov', RUBY_VERSION < '2.5' ? '~> 0.16.0' : '~> 0.22' if ENV['COVERAGE'] == 'true'
23
20
  gem 'timecop'
24
21
  end
data/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  Mongoid Collection Snapshot
2
2
  ===========================
3
3
 
4
- Easy maintenance of collections of processed data in MongoDB with Mongoid 3, 4, 5 and 6.
4
+ Easy maintenance of collections of processed data in MongoDB with Mongoid.
5
5
 
6
6
  This is a forked, renamed, maintained and supported version of [mongoid_collection_snapshot](https://github.com/aaw/mongoid_collection_snapshot).
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/mongoid-collection-snapshot.svg)](https://badge.fury.io/rb/mongoid-collection-snapshot)
9
- [![Build Status](https://travis-ci.org/mongoid/mongoid-collection-snapshot.svg)](https://travis-ci.org/mongoid/mongoid-collection-snapshot)
9
+ [![Test](https://github.com/mongoid/mongoid-collection-snapshot/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mongoid/mongoid-collection-snapshot/actions/workflows/test.yml?query=branch%3Amaster)
10
+ [![Coverage Status](https://coveralls.io/repos/github/mongoid/mongoid-collection-snapshot/badge.svg?branch=master)](https://coveralls.io/github/mongoid/mongoid-collection-snapshot?branch=master)
11
+
12
+ The Ruby 4.0 CI job measures library line coverage with SimpleCov and submits `coverage/.resultset.json` to Coveralls using GitHub's automatic token. Other matrix jobs do not submit duplicate reports. Run `COVERAGE=true bundle install` followed by `COVERAGE=true bundle exec rake spec` for a local report. The default-branch badge requires Coveralls to accept an upstream `master` build; configuring this workflow does not activate the external service.
10
13
 
11
14
  ### Example
12
15
 
@@ -68,6 +71,20 @@ andy_warhol_price = ArtistArtworkPrice.latest.collection_snapshot.where(artist_i
68
71
  average_price = andy_warhol_price['sum'] / andy_warhol_price['count']
69
72
  ```
70
73
 
74
+ ### Discover Snapshot Collections
75
+
76
+ Use `snapshot.collections` to discover existing collections belonging to a snapshot, including its unnamed collection and named subcollections. Discovery queries the snapshot database, not the lazily populated `document_classes` cache, so it works before calling `documents` and includes collections without a `document` declaration.
77
+
78
+ ```ruby
79
+ snapshot = ArtistArtworkPrice.latest
80
+ snapshot.collections.each do |collection|
81
+ puts collection.name
82
+ collection.find.each { |document| puts document.inspect }
83
+ end if snapshot
84
+ ```
85
+
86
+ The result is an Array of driver collection objects in the snapshot's configured `snapshot_session`, not Mongoid model classes. Their names are full database collection names; `snapshot.documents('average')` still takes the logical subcollection name, not a full collection name. Only existing collections for this snapshot are returned; discovery neither creates collections nor includes older snapshots. Collection order is unspecified.
87
+
71
88
  ### Snapshot Cleanup
72
89
 
73
90
  By default, mongoid-collection-snapshot maintains the most recent two snapshots computed any given time. Set `max_collection_snapshot_instances` to change this.
data/RELEASING.md CHANGED
@@ -1,68 +1,50 @@
1
- Releasing Mongoid::CollectionSnapshot
2
- =====================================
1
+ # Releasing Mongoid Collection Snapshot
3
2
 
4
- There're no particular rules about when to release mongoid-collection-snapshot. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
3
+ ## Prepare
5
4
 
6
- ### Release
5
+ Use the upstream checkout on clean `master`, verify `origin` points to `mongoid/mongoid-collection-snapshot`, and run `git pull --ff-only`. Check supported platforms in [GitHub Actions](https://github.com/mongoid/mongoid-collection-snapshot/actions). Choose a patch version for fixes, minor for backward-compatible features, or major for breaking changes.
7
6
 
8
- Run tests, check that all tests succeed locally.
7
+ Set `lib/mongoid-collection-snapshot/version.rb` to the release version. Date the matching changelog section using `YYYY/MM/DD` and remove its contribution placeholder.
9
8
 
10
- ```
9
+ ```sh
11
10
  bundle install
12
- rake
13
- ```
14
-
15
- Check that the last build succeeded in [Travis CI](https://travis-ci.org/mongoid/mongoid-collection-snapshot) for all supported platforms.
16
-
17
- Increment the version, modify [lib/mongoid/collection-snapshot/version.rb](lib/mongoid/collection-snapshot/version.rb).
18
-
19
- * Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`).
20
- * Increment the second number if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.4.0`).
21
-
22
- Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
23
-
24
- ```
25
- ### 0.4.0 (2014-01-27)
26
- ```
27
-
28
- Remove the line with "Your contribution here.", since there will be no more contributions to this release.
29
-
30
- Commit your changes.
31
-
32
- ```
33
- git add CHANGELOG.md lib/mongoid-collection-snapshot/version.rb
34
- git commit -m "Preparing for release, 0.4.0."
11
+ bundle exec rake
12
+ git add CHANGELOG.md lib/mongoid-collection-snapshot/version.rb RELEASING.md
13
+ git commit -m "Preparing for release, 1.3.3."
35
14
  git push origin master
36
15
  ```
37
16
 
38
- Release.
17
+ Wait for the preparation commit's CI checks to pass.
39
18
 
40
- ```
41
- $ rake release
19
+ ## Publish RubyGems and GitHub
42
20
 
43
- mongoid-collection-snapshot 0.4.0 built to pkg/mongoid-collection-snapshot-0.4.0.gem.
44
- Tagged v0.4.0.
45
- Pushed git commits and tags.
46
- Pushed mongoid-collection-snapshot 0.4.0 to rubygems.org.
21
+ ```sh
22
+ bundle exec rake release
47
23
  ```
48
24
 
49
- ### Prepare for the Next Version
25
+ Complete RubyGems MFA when prompted. This builds the package, pushes the tag, and publishes to RubyGems. If interrupted, inspect existing tags and the RubyGems version before retrying. Never move published tags; if only publication is missing, use `gem push pkg/mongoid-collection-snapshot-1.3.3.gem`.
50
26
 
51
- Add the next release to [CHANGELOG.md](CHANGELOG.md).
27
+ A tag alone does not create a GitHub release. Once RubyGems publication is verified, publish a matching GitHub release with changelog notes:
52
28
 
29
+ ```sh
30
+ version=1.3.3
31
+ notes="$(mktemp)"
32
+ awk -v version="$version" '
33
+ /^### / {
34
+ if (found) exit
35
+ if ($2 == version) found = 1
36
+ next
37
+ }
38
+ found { print }
39
+ ' CHANGELOG.md > "$notes"
40
+ gh release create "v$version" --repo mongoid/mongoid-collection-snapshot --verify-tag --title "$version" --notes-file "$notes" --latest
41
+ rm "$notes"
42
+ curl --fail --silent --show-error "https://rubygems.org/api/v2/rubygems/mongoid-collection-snapshot/versions/$version.json"
43
+ gh release view "v$version" --repo mongoid/mongoid-collection-snapshot
53
44
  ```
54
- Next Release
55
- ============
56
45
 
57
- * Your contribution here.
58
- ```
46
+ Verify both the published gem and non-draft GitHub release.
59
47
 
60
- Increment the minor version, modify [lib/mongoid-collection-snapshot/version.rb](lib/mongoid-collection-snapshot/version.rb).
48
+ ## Prepare the Next Version
61
49
 
62
- Commit your changes.
63
-
64
- ```
65
- git add CHANGELOG.md lib/mongoid-collection-snapshot/version.rb
66
- git commit -m "Preparing for next release, 0.4.1."
67
- git push origin master
68
- ```
50
+ Increment the development patch version in `lib/mongoid-collection-snapshot/version.rb` (for example, `1.3.4`). Add `### 1.3.4 (Next)` with a contribution placeholder above the released changelog section. Commit and push those changes to `master` without changing the release tag.
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module CollectionSnapshot
3
- VERSION = '1.3.2'.freeze
3
+ VERSION = '1.4.0'.freeze
4
4
  end
5
5
  end
@@ -42,12 +42,12 @@ module Mongoid
42
42
  end
43
43
  instance_eval(&document_block) if document_block
44
44
  end
45
- if Mongoid::Compatibility::Version.mongoid6?
45
+ if Mongoid::VERSION.to_i >= 6
46
46
  # assign a name to the snapshot session
47
47
  session_id = snapshot_session.object_id.to_s
48
48
  Mongoid::Clients.set session_id, snapshot_session
49
49
  # tell the class to use the client by name
50
- klass.class_variable_set :@@storage_options, client: session_id, collection: collection_name
50
+ klass.store_in client: session_id, collection: collection_name
51
51
  elsif Mongoid::Compatibility::Version.mongoid5?
52
52
  klass.store_in collection: collection_name
53
53
  klass.mongo_client = snapshot_session
@@ -80,13 +80,18 @@ module Mongoid
80
80
  end
81
81
  end
82
82
 
83
- def drop_snapshot_collections
84
- collections = Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? snapshot_session.database.collections : snapshot_session.collections
85
- collections.each do |collection|
86
- collection.drop if collection.name =~ /^#{self.collection.name}\.([^\.]+\.)?#{slug}$/
83
+ def collections
84
+ available = Mongoid::VERSION.to_i >= 5 ? snapshot_session.database.collections : snapshot_session.collections
85
+ pattern = /\A#{Regexp.escape(collection.name)}\.(?:[^.]+\.)?#{Regexp.escape(slug.to_s)}\z/
86
+ available.select do |snapshot_collection|
87
+ snapshot_collection.name =~ pattern
87
88
  end
88
89
  end
89
90
 
91
+ def drop_snapshot_collections
92
+ collections.each(&:drop)
93
+ end
94
+
90
95
  # Since we should always be using the latest instance of this class, this method is
91
96
  # called after each save - making sure only at most two instances exists should be
92
97
  # sufficient to ensure that this data can be rebuilt live without corrupting any
@@ -100,7 +105,7 @@ module Mongoid
100
105
 
101
106
  # Override to supply custom database connection for snapshots
102
107
  def snapshot_session
103
- Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? Mongoid.default_client : Mongoid.default_session
108
+ Mongoid::VERSION.to_i >= 5 ? Mongoid.default_client : Mongoid.default_session
104
109
  end
105
110
  end
106
111
  end
@@ -1,6 +1,6 @@
1
1
  test:
2
2
  sessions:
3
3
  default:
4
- uri: mongodb://localhost:27017/mongoid-collection-snapshot_test
4
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test
5
5
  imports:
6
- uri: mongodb://localhost:27017/mongoid-collection-snapshot_test-imports
6
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test-imports
@@ -1,6 +1,6 @@
1
1
  test:
2
2
  sessions:
3
3
  default:
4
- uri: mongodb://localhost:27017/mongoid-collection-snapshot_test
4
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test
5
5
  imports:
6
- uri: mongodb://localhost:27017/mongoid-collection-snapshot_test-imports
6
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test-imports
@@ -1,6 +1,6 @@
1
1
  test:
2
2
  clients:
3
3
  default:
4
- uri: mongodb://localhost:27017/mongoid-collection-snapshot_test
4
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test
5
5
  imports:
6
- uri: mongodb://localhost:27017/mongoid-collection-snapshot_test-imports
6
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test-imports
@@ -29,7 +29,7 @@ class AverageArtistPrice < AveragePrice
29
29
  EOS
30
30
 
31
31
  Artwork.map_reduce(map, reduce).out(inline: 1).each do |doc|
32
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
32
+ if Mongoid::VERSION.to_i >= 5
33
33
  collection_snapshot.insert_one(
34
34
  artist_id: doc['_id']['artist_id'],
35
35
  count: doc['value']['count'],
@@ -81,7 +81,7 @@ class AveragePartnerPrice < AveragePrice
81
81
  EOS
82
82
 
83
83
  Artwork.map_reduce(map, reduce).out(inline: 1).each do |doc|
84
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
84
+ if Mongoid::VERSION.to_i >= 5
85
85
  collection_snapshot.insert_one(
86
86
  partner_id: doc['_id']['partner_id'],
87
87
  count: doc['value']['count'],
@@ -10,7 +10,7 @@ class CustomConnectionSnapshot
10
10
  end
11
11
 
12
12
  def build
13
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
13
+ if Mongoid::VERSION.to_i >= 5
14
14
  collection_snapshot.insert_one('name' => 'foo')
15
15
  collection_snapshot('foo').insert_one('name' => 'bar')
16
16
  else
@@ -22,10 +22,10 @@ class CustomConnectionSnapshot
22
22
  private
23
23
 
24
24
  def self.new_snapshot_session
25
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
26
- Mongo::Client.new('mongodb://localhost:27017/snapshot_test')
25
+ if Mongoid::VERSION.to_i >= 5
26
+ Mongo::Client.new("mongodb://#{ENV.fetch('MONGODB_HOST', 'localhost:27017')}/snapshot_test")
27
27
  else
28
- Moped::Session.new(['127.0.0.1:27017']).tap do |session|
28
+ Moped::Session.new([ENV.fetch('MONGODB_HOST', '127.0.0.1:27017')]).tap do |session|
29
29
  session.use :snapshot_test
30
30
  end
31
31
  end
@@ -17,7 +17,7 @@ class MultiCollectionSnapshot
17
17
  end
18
18
 
19
19
  def build
20
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
20
+ if Mongoid::VERSION.to_i >= 5
21
21
  collection_snapshot('foo').insert_one('name' => 'foo!', count: 1)
22
22
  collection_snapshot('bar').insert_one('name' => 'bar!', number: 2)
23
23
  collection_snapshot('baz').insert_one('name' => 'baz!', digit: 3)
@@ -104,7 +104,7 @@ module Mongoid
104
104
 
105
105
  it 'safely cleans up all collections used by the snapshot' do
106
106
  # Create some collections with names close to the snapshots we'll create
107
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
107
+ if Mongoid::VERSION.to_i >= 5
108
108
  Mongoid.default_client["#{MultiCollectionSnapshot.collection.name}.do.not_delete"].insert_one('a' => 1)
109
109
  Mongoid.default_client["#{MultiCollectionSnapshot.collection.name}.snapshorty"].insert_one('a' => 1)
110
110
  Mongoid.default_client["#{MultiCollectionSnapshot.collection.name}.hello.1"].insert_one('a' => 1)
@@ -115,19 +115,19 @@ module Mongoid
115
115
  end
116
116
 
117
117
  MultiCollectionSnapshot.create
118
- collections = Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? Mongoid.default_client.database.collections : Mongoid.default_session.collections
118
+ collections = Mongoid::VERSION.to_i >= 5 ? Mongoid.default_client.database.collections : Mongoid.default_session.collections
119
119
  before_create = collections.map(&:name)
120
120
  expect(before_create.length).to be > 0
121
121
 
122
122
  Timecop.travel(1.second.from_now)
123
123
  MultiCollectionSnapshot.create
124
- collections = Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? Mongoid.default_client.database.collections : Mongoid.default_session.collections
124
+ collections = Mongoid::VERSION.to_i >= 5 ? Mongoid.default_client.database.collections : Mongoid.default_session.collections
125
125
  after_create = collections.map(&:name)
126
126
  collections_created = (after_create - before_create).sort
127
127
  expect(collections_created.length).to eq(3)
128
128
 
129
129
  MultiCollectionSnapshot.latest.destroy
130
- collections = Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? Mongoid.default_client.database.collections : Mongoid.default_session.collections
130
+ collections = Mongoid::VERSION.to_i >= 5 ? Mongoid.default_client.database.collections : Mongoid.default_session.collections
131
131
  after_destroy = collections.map(&:name)
132
132
  collections_destroyed = (after_create - after_destroy).sort
133
133
  expect(collections_created).to eq(collections_destroyed)
@@ -136,13 +136,13 @@ module Mongoid
136
136
 
137
137
  context 'with a custom snapshot connection' do
138
138
  around(:each) do |example|
139
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
139
+ if Mongoid::VERSION.to_i >= 5
140
140
  CustomConnectionSnapshot.snapshot_session.database.drop
141
141
  else
142
142
  CustomConnectionSnapshot.snapshot_session.drop
143
143
  end
144
144
  example.run
145
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
145
+ if Mongoid::VERSION.to_i >= 5
146
146
  CustomConnectionSnapshot.snapshot_session.database.drop
147
147
  else
148
148
  CustomConnectionSnapshot.snapshot_session.drop
@@ -155,7 +155,7 @@ module Mongoid
155
155
  "#{CustomConnectionSnapshot.collection.name}.foo.#{snapshot.slug}",
156
156
  "#{CustomConnectionSnapshot.collection.name}.#{snapshot.slug}"
157
157
  ].each do |collection_name|
158
- session = Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? Mongoid.default_client : Mongoid.default_session
158
+ session = Mongoid::VERSION.to_i >= 5 ? Mongoid.default_client : Mongoid.default_session
159
159
  expect(session[collection_name].find.count).to eq(0)
160
160
  expect(CustomConnectionSnapshot.snapshot_session[collection_name].find.count).to eq(1)
161
161
  end
@@ -163,7 +163,7 @@ module Mongoid
163
163
 
164
164
  context '#documents' do
165
165
  it 'uses the custom session' do
166
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
166
+ if Mongoid::VERSION.to_i >= 5
167
167
  expect(CustomConnectionSnapshot.new.documents.mongo_client).to eq CustomConnectionSnapshot.snapshot_session
168
168
  else
169
169
  expect(CustomConnectionSnapshot.new.documents.mongo_session).to eq CustomConnectionSnapshot.snapshot_session
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Snapshot collection discovery' do
4
+ def insert(collection)
5
+ if Mongoid::VERSION.to_i >= 5
6
+ collection.insert_one('value' => 1)
7
+ else
8
+ collection.insert('value' => 1)
9
+ end
10
+ end
11
+
12
+ it 'discovers named collections without generating document classes' do
13
+ snapshot = MultiCollectionSnapshot.create!
14
+ expect(snapshot).not_to receive(:documents)
15
+ expected = %w(foo bar baz).map { |name| snapshot.collection_snapshot(name).name }
16
+ expect(snapshot.collections.map(&:name)).to match_array(expected)
17
+ expect(snapshot.collections.map { |collection| collection.find.first['name'] }).to match_array(%w(foo! bar! baz!))
18
+ end
19
+
20
+ it 'excludes other snapshots, unrelated collections and absent collections' do
21
+ previous = MultiCollectionSnapshot.create!
22
+ snapshot = MultiCollectionSnapshot.create!
23
+ insert(snapshot.snapshot_session["#{snapshot.collection.name}.foo.#{snapshot.slug}.extra"])
24
+ expect(snapshot.collections.map(&:name)).not_to include(previous.collection_snapshot('foo').name)
25
+ expect(snapshot.collections.map(&:name)).not_to include(snapshot.collection_snapshot.name)
26
+ expect(snapshot.collections.size).to eq(3)
27
+ end
28
+
29
+ it 'returns no collections before any data has been written' do
30
+ expect(MultiCollectionSnapshot.new.collections).to be_empty
31
+ end
32
+
33
+ it 'matches literal collection names and slugs during discovery and cleanup' do
34
+ snapshot = MultiCollectionSnapshot.new
35
+ allow(snapshot.collection).to receive(:name).and_return('literal.snapshots')
36
+ allow(snapshot).to receive(:slug).and_return('snapshot-1+')
37
+ owned = snapshot.collection_snapshot('foo')
38
+ unrelated = snapshot.snapshot_session['literalXsnapshots.foo.snapshot-11']
39
+ insert(owned)
40
+ insert(unrelated)
41
+ expect(snapshot.collections.map(&:name)).to eq([owned.name])
42
+ snapshot.drop_snapshot_collections
43
+ expect(unrelated.find.count).to eq(1)
44
+ expect(snapshot.collections).to be_empty
45
+ end
46
+
47
+ it 'discovers both unnamed and named collections in a custom database' do
48
+ snapshot = CustomConnectionSnapshot.create!
49
+ begin
50
+ expected = [snapshot.collection_snapshot.name, snapshot.collection_snapshot('foo').name]
51
+ expect(snapshot.collections.map(&:name)).to match_array(expected)
52
+ expect(snapshot.collections.map { |collection| collection.find.first['name'] }).to match_array(%w(foo bar))
53
+ snapshot.drop_snapshot_collections
54
+ expect(snapshot.collections).to be_empty
55
+ ensure
56
+ snapshot.drop_snapshot_collections
57
+ end
58
+ end
59
+ end
@@ -20,7 +20,7 @@ class WidgetsAndGadgets
20
20
  collection_snapshot.drop
21
21
  Widget.all.each do |widget|
22
22
  Gadget.all.each do |gadget|
23
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
23
+ if Mongoid::VERSION.to_i >= 5
24
24
  collection_snapshot.insert_one(widget_id: widget.id, gadget_id: gadget.id)
25
25
  else
26
26
  collection_snapshot.insert(widget_id: widget.id, gadget_id: gadget.id)
@@ -30,7 +30,7 @@ class WidgetsAndGadgets
30
30
  end
31
31
 
32
32
  def snapshot_session
33
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
33
+ if Mongoid::VERSION.to_i >= 5
34
34
  Mongoid.client('imports')
35
35
  else
36
36
  Mongoid.session('imports')
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,11 @@
1
+ if ENV['COVERAGE'] == 'true'
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ track_files 'lib/**/*.rb'
5
+ add_filter '/spec/'
6
+ end
7
+ end
8
+
1
9
  require 'rubygems'
2
10
  require 'bundler/setup'
3
11
  require 'rspec'
@@ -5,7 +13,8 @@ require 'rspec'
5
13
  require 'mongoid'
6
14
  require 'timecop'
7
15
 
8
- Mongoid.load!("#{File.dirname(__FILE__)}/config/mongoid#{ENV['MONGOID_VERSION'] || 6}.yml", :test)
16
+ config_version = [Mongoid::VERSION.to_i, 6].min
17
+ Mongoid.load!("#{File.dirname(__FILE__)}/config/mongoid#{config_version}.yml", :test)
9
18
 
10
19
  require File.expand_path('../../lib/mongoid-collection-snapshot', __FILE__)
11
20
  Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each { |f| require f }
@@ -15,13 +24,13 @@ require 'mongoid-compatibility'
15
24
  RSpec.configure do |c|
16
25
  c.before(:all) do
17
26
  Mongoid.logger.level = Logger::INFO
18
- Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
27
+ Mongo::Logger.logger.level = Logger::INFO if Mongoid::VERSION.to_i >= 5
19
28
  end
20
29
  c.before(:each) do
21
30
  Mongoid.purge!
22
31
  end
23
32
  c.after(:all) do
24
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
33
+ if Mongoid::VERSION.to_i >= 5
25
34
  Mongoid.default_client.database.drop
26
35
  else
27
36
  Mongoid.default_session.drop
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::CollectionSnapshot do
4
+ it 'defines a frozen semantic version' do
5
+ expect(described_class::VERSION).to match(/\A\d+\.\d+\.\d+\z/)
6
+ expect(described_class::VERSION).to be_frozen
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-collection-snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Windsor
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-04 00:00:00.000000000 Z
11
+ date: 2026-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -52,17 +52,19 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description:
55
+ description:
56
56
  email: aaron.windsor@gmail.com
57
57
  executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
+ - ".github/workflows/danger-comment.yml"
62
+ - ".github/workflows/danger.yml"
63
+ - ".github/workflows/test.yml"
61
64
  - ".gitignore"
62
65
  - ".rspec"
63
66
  - ".rubocop.yml"
64
67
  - ".rubocop_todo.yml"
65
- - ".travis.yml"
66
68
  - CHANGELOG.md
67
69
  - Dangerfile
68
70
  - Gemfile
@@ -91,13 +93,15 @@ files:
91
93
  - spec/models/multi_collection_snapshot.rb
92
94
  - spec/models/partner.rb
93
95
  - spec/mongoid/collection_snapshot_spec.rb
96
+ - spec/mongoid/collections_spec.rb
94
97
  - spec/mongoid/multiple_databases_spec.rb
95
98
  - spec/spec_helper.rb
99
+ - spec/version_spec.rb
96
100
  homepage: http://github.com/mongoid/mongoid-collection-snapshot
97
101
  licenses:
98
102
  - MIT
99
103
  metadata: {}
100
- post_install_message:
104
+ post_install_message:
101
105
  rdoc_options: []
102
106
  require_paths:
103
107
  - lib
@@ -112,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
116
  - !ruby/object:Gem::Version
113
117
  version: 1.3.6
114
118
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.12
117
- signing_key:
119
+ rubygems_version: 3.5.16
120
+ signing_key:
118
121
  specification_version: 4
119
122
  summary: Easy maintenence of collections of processed data in MongoDB with the Mongoid
120
123
  ODM.
data/.travis.yml DELETED
@@ -1,27 +0,0 @@
1
- sudo: false
2
-
3
- matrix:
4
- include:
5
- - rvm: 2.3.1
6
- env:
7
- - MONGOID_VERSION=6
8
- before_script:
9
- - bundle exec danger
10
- - rvm: 2.3.1
11
- env:
12
- - MONGOID_VERSION=5
13
- - rvm: 2.2
14
- env:
15
- - MONGOID_VERSION=4
16
- - rvm: 2.1
17
- env:
18
- - MONGOID_VERSION=3
19
-
20
- services: mongodb
21
-
22
- addons:
23
- apt:
24
- sources:
25
- - mongodb-3.2-precise
26
- packages:
27
- - mongodb-org-server