mongoid-collection-snapshot 1.3.3 → 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
2
  SHA256:
3
- metadata.gz: 9456efe5e5e89a7ca629647b61ce24b9dda9973750e80f7b6cca89e6a5521351
4
- data.tar.gz: 0643b4f5269d3ffc8ac3847bb01cb0fa8d45315c8aaebd7a97970d2c5fddc775
3
+ metadata.gz: 50e1fc889a97e8dc1f4957f182b440141ca48643eddc78c43e6449a08c289f9a
4
+ data.tar.gz: 4f9e9397dfca958344f59478de0ca0985ed6a5cfadb5591f2b7bf05693bab8ca
5
5
  SHA512:
6
- metadata.gz: 659f053c0fe149ad0c3f752559da9e5d592ae8949ac9d505209afe49030dc765278b281b4fcee360510a1d611438755a79b984d62bb01c6e59dcd0caa475cedf
7
- data.tar.gz: b2e1d5175e0e8687381305550600e958b4afbb80f3b2e42a97ef439db27bac037e84efe6906c6330c27254885fdee6df995c4164a40308aa3c3cb41ff2aaaa05
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
@@ -14,18 +14,18 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  include:
17
- - { ruby: '2.1.9', mongoid: '3', mongodb: '2.6', bundler: '1.17.3' }
17
+ - { ruby: '2.1.9', mongoid: '3', mongodb: '2.6', bundler: '1.17.3', coverage: true }
18
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' }
19
+ - { ruby: '2.3.8', mongoid: '5', mongodb: '4.0', bundler: '2.3.26', coverage: true }
20
20
  - { ruby: '2.5.9', mongoid: '6', mongodb: '4.0', bundler: '2.3.26' }
21
21
  - { ruby: '2.7.8', mongoid: '7', mongodb: '4.4', bundler: '2.4.22' }
22
22
  - { ruby: '3.2', mongoid: '8', mongodb: '6.0', bundler: default }
23
23
  - { ruby: '3.3', mongoid: '9', mongodb: '7.0', bundler: default }
24
24
  - { ruby: '3.4', mongoid: '9', mongodb: '8.0', bundler: default }
25
- - { ruby: '4.0', mongoid: '9', mongodb: '8.0', bundler: default }
25
+ - { ruby: '4.0', mongoid: '9', mongodb: '8.0', bundler: default, coverage: true }
26
26
  env:
27
27
  MONGOID_VERSION: ${{ matrix.mongoid }}
28
- COVERAGE: ${{ matrix.ruby == '4.0' && 'true' || 'false' }}
28
+ COVERAGE: ${{ matrix.coverage }}
29
29
  services:
30
30
  mongodb:
31
31
  image: mongo:${{ matrix.mongodb }}
@@ -42,11 +42,23 @@ jobs:
42
42
  bundler-cache: true
43
43
  - run: bundle exec rake spec
44
44
  - name: Report coverage to Coveralls
45
- if: matrix.ruby == '4.0'
45
+ if: matrix.coverage
46
46
  uses: coverallsapp/github-action@v2
47
47
  with:
48
48
  github-token: ${{ secrets.GITHUB_TOKEN }}
49
49
  file: coverage/.resultset.json
50
50
  format: simplecov
51
+ parallel: true
52
+ flag-name: mongoid-${{ matrix.mongoid }}
51
53
  - if: matrix.mongoid == '6'
52
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/CHANGELOG.md CHANGED
@@ -1,19 +1,25 @@
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
+
1
7
  ### 1.3.3 (2026/10/14)
2
8
 
3
- * [#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.
4
- * [#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.
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).
5
11
 
6
- ### 1.3.2 (6/4/2017)
12
+ ### 1.3.2 (2017/06/04)
7
13
 
8
14
  * [#13](https://github.com/mongoid/mongoid-collection-snapshot/issues/13): Fix: use correct database on all threads - [@dblock](https://github.com/dblock).
9
15
  * [#7](https://github.com/mongoid/mongoid-collection-snapshot/issues/7): Fix: `max_collection_snapshot_instances` broken - [@dblock](https://github.com/dblock).
10
16
 
11
- ### 1.3.1 (5/22/2017)
17
+ ### 1.3.1 (2017/05/22)
12
18
 
13
19
  * [#11](https://github.com/mongoid/mongoid-collection-snapshot/pull/11): Fix: incorrect connection used with Mongoid 6 - [@dblock](https://github.com/dblock).
14
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).
15
21
 
16
- ### 1.3.0 (1/20/2017)
22
+ ### 1.3.0 (2017/01/20)
17
23
 
18
24
  * [#2](https://github.com/mongoid/mongoid-collection-snapshot/pull/2): Support for Mongoid 6 - [@dblock](https://github.com/dblock).
19
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
@@ -8,10 +8,14 @@ gem 'logger' if RUBY_VERSION >= '3.4'
8
8
  gem 'mongoid', version =~ /\A\d+\z/ ? "~> #{version}.0" : version
9
9
 
10
10
  group :development, :test do
11
- 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
12
16
  gem 'rake'
13
17
  gem 'rspec', '~> 3.1'
14
18
  gem 'rubocop', '0.47.1'
15
- gem 'simplecov', '~> 0.22' if ENV['COVERAGE'] == 'true'
19
+ gem 'simplecov', RUBY_VERSION < '2.5' ? '~> 0.16.0' : '~> 0.22' if ENV['COVERAGE'] == 'true'
16
20
  gem 'timecop'
17
21
  end
data/README.md CHANGED
@@ -11,8 +11,6 @@ This is a forked, renamed, maintained and supported version of [mongoid_collecti
11
11
 
12
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.
13
13
 
14
- CI tests representative compatible combinations of Mongoid 3 through 9, Ruby 2.1 through 4.0, and MongoDB Server 2.6 through 8.0, including Ruby 4.0 / Mongoid 9 / MongoDB 8.0. See [the test matrix](.github/workflows/test.yml); this is not a Cartesian product of supported versions. Mongoid 3–4 use MongoDB 2.6 because their Moped driver enumerates collections via the removed `system.namespaces` collection. Set `MONGOID_VERSION` to select a Mongoid major version and `MONGODB_HOST` to override the default `localhost:27017` when running tests.
15
-
16
14
  ### Example
17
15
 
18
16
  Suppose that you have a Mongoid model called `Artwork`, stored in a MongoDB collection called `artworks` and the underlying documents look something like:
@@ -73,6 +71,20 @@ andy_warhol_price = ArtistArtworkPrice.latest.collection_snapshot.where(artist_i
73
71
  average_price = andy_warhol_price['sum'] / andy_warhol_price['count']
74
72
  ```
75
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
+
76
88
  ### Snapshot Cleanup
77
89
 
78
90
  By default, mongoid-collection-snapshot maintains the most recent two snapshots computed any given time. Set `max_collection_snapshot_instances` to change this.
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module CollectionSnapshot
3
- VERSION = '1.3.3'.freeze
3
+ VERSION = '1.4.0'.freeze
4
4
  end
5
5
  end
@@ -80,13 +80,18 @@ module Mongoid
80
80
  end
81
81
  end
82
82
 
83
- def drop_snapshot_collections
84
- collections = Mongoid::VERSION.to_i >= 5 ? 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
@@ -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
@@ -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.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Windsor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-15 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
@@ -58,6 +58,8 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
+ - ".github/workflows/danger-comment.yml"
62
+ - ".github/workflows/danger.yml"
61
63
  - ".github/workflows/test.yml"
62
64
  - ".gitignore"
63
65
  - ".rspec"
@@ -91,8 +93,10 @@ 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