mongoid-collection-snapshot 1.3.1 → 1.3.3

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: a83bba2b3b5308ff4015fb6b1160946e9ce76acc
4
- data.tar.gz: 74c2c24fcee8b86d53cd090cddcb3dd9b59ce117
2
+ SHA256:
3
+ metadata.gz: 9456efe5e5e89a7ca629647b61ce24b9dda9973750e80f7b6cca89e6a5521351
4
+ data.tar.gz: 0643b4f5269d3ffc8ac3847bb01cb0fa8d45315c8aaebd7a97970d2c5fddc775
5
5
  SHA512:
6
- metadata.gz: b4d4d635979850c86c773192dea47a00497a48a5d1220fce28e80cae6e002960ffa3a9f7db48ac5be62c6c22043120dbf4bb117971705561f831fb617b033ad3
7
- data.tar.gz: ac843dacc50abd245f56487ddaa49542d2aed4cc70d4a82ab9e84d359b0bc2306217471db489db6a70ff7798babd7736c6fdd042ab230958204507be1e3853fa
6
+ metadata.gz: 659f053c0fe149ad0c3f752559da9e5d592ae8949ac9d505209afe49030dc765278b281b4fcee360510a1d611438755a79b984d62bb01c6e59dcd0caa475cedf
7
+ data.tar.gz: b2e1d5175e0e8687381305550600e958b4afbb80f3b2e42a97ef439db27bac037e84efe6906c6330c27254885fdee6df995c4164a40308aa3c3cb41ff2aaaa05
@@ -0,0 +1,52 @@
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' }
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' }
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 }
26
+ env:
27
+ MONGOID_VERSION: ${{ matrix.mongoid }}
28
+ COVERAGE: ${{ matrix.ruby == '4.0' && 'true' || 'false' }}
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.ruby == '4.0'
46
+ uses: coverallsapp/github-action@v2
47
+ with:
48
+ github-token: ${{ secrets.GITHUB_TOKEN }}
49
+ file: coverage/.resultset.json
50
+ format: simplecov
51
+ - if: matrix.mongoid == '6'
52
+ run: bundle exec rake rubocop
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-01-20 15:27:40 -0500 using RuboCop version 0.47.1.
3
+ # on 2017-06-03 12:33:20 -0400 using RuboCop version 0.47.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -26,18 +26,18 @@ Lint/UselessAccessModifier:
26
26
 
27
27
  # Offense count: 3
28
28
  Metrics/AbcSize:
29
- Max: 34
29
+ Max: 38
30
30
 
31
31
  # Offense count: 5
32
32
  # Configuration parameters: CountComments, ExcludedMethods.
33
33
  Metrics/BlockLength:
34
- Max: 145
34
+ Max: 151
35
35
 
36
36
  # Offense count: 1
37
37
  Metrics/CyclomaticComplexity:
38
38
  Max: 8
39
39
 
40
- # Offense count: 43
40
+ # Offense count: 46
41
41
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
42
42
  # URISchemes: http, https
43
43
  Metrics/LineLength:
@@ -51,7 +51,7 @@ Metrics/MethodLength:
51
51
  # Offense count: 1
52
52
  # Configuration parameters: CountComments.
53
53
  Metrics/ModuleLength:
54
- Max: 147
54
+ Max: 153
55
55
 
56
56
  # Offense count: 1
57
57
  Metrics/PerceivedComplexity:
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
- ### 1.3.2 (Next)
1
+ ### 1.3.3 (2026/10/14)
2
2
 
3
- * Your contribution here.
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.
5
+
6
+ ### 1.3.2 (6/4/2017)
7
+
8
+ * [#13](https://github.com/mongoid/mongoid-collection-snapshot/issues/13): Fix: use correct database on all threads - [@dblock](https://github.com/dblock).
9
+ * [#7](https://github.com/mongoid/mongoid-collection-snapshot/issues/7): Fix: `max_collection_snapshot_instances` broken - [@dblock](https://github.com/dblock).
4
10
 
5
11
  ### 1.3.1 (5/22/2017)
6
12
 
data/Gemfile CHANGED
@@ -1,24 +1,17 @@
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
11
  gem 'mongoid-danger', '~> 0.1.1'
20
12
  gem 'rake'
21
13
  gem 'rspec', '~> 3.1'
22
14
  gem 'rubocop', '0.47.1'
15
+ gem 'simplecov', '~> 0.22' if ENV['COVERAGE'] == 'true'
23
16
  gem 'timecop'
24
17
  end
data/README.md CHANGED
@@ -1,12 +1,17 @@
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.
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.
10
15
 
11
16
  ### Example
12
17
 
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.1'.freeze
3
+ VERSION = '1.3.3'.freeze
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require 'mongoid-collection-snapshot/version'
2
2
 
3
3
  module Mongoid
4
4
  module CollectionSnapshot
5
- extend ActiveSupport::Concern
5
+ extend ::ActiveSupport::Concern
6
6
 
7
7
  DEFAULT_COLLECTION_KEY_NAME = '*'.freeze
8
8
 
@@ -16,10 +16,10 @@ module Mongoid
16
16
  field :workspace_basename, default: 'snapshot'
17
17
  slug :workspace_basename
18
18
 
19
- field :max_collection_snapshot_instances, default: 2
19
+ class_attribute :max_collection_snapshot_instances
20
20
 
21
21
  before_create :build
22
- after_create :ensure_at_most_two_instances_exist
22
+ after_create :ensure_at_most_max_instances_exist
23
23
  before_destroy :drop_snapshot_collections
24
24
 
25
25
  class_attribute :document_blocks
@@ -41,14 +41,18 @@ module Mongoid
41
41
  cattr_accessor :mongo_session
42
42
  end
43
43
  instance_eval(&document_block) if document_block
44
- store_in collection: collection_name
45
44
  end
46
- if Mongoid::Compatibility::Version.mongoid6?
47
- ctx = PersistenceContext.set(klass, {})
48
- ctx.instance_variable_set(:@client, snapshot_session)
45
+ if Mongoid::VERSION.to_i >= 6
46
+ # assign a name to the snapshot session
47
+ session_id = snapshot_session.object_id.to_s
48
+ Mongoid::Clients.set session_id, snapshot_session
49
+ # tell the class to use the client by name
50
+ klass.store_in client: session_id, collection: collection_name
49
51
  elsif Mongoid::Compatibility::Version.mongoid5?
52
+ klass.store_in collection: collection_name
50
53
  klass.mongo_client = snapshot_session
51
54
  else
55
+ klass.store_in collection: collection_name
52
56
  klass.mongo_session = snapshot_session
53
57
  end
54
58
  Object.const_set(class_name, klass)
@@ -77,7 +81,7 @@ module Mongoid
77
81
  end
78
82
 
79
83
  def drop_snapshot_collections
80
- collections = Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? snapshot_session.database.collections : snapshot_session.collections
84
+ collections = Mongoid::VERSION.to_i >= 5 ? snapshot_session.database.collections : snapshot_session.collections
81
85
  collections.each do |collection|
82
86
  collection.drop if collection.name =~ /^#{self.collection.name}\.([^\.]+\.)?#{slug}$/
83
87
  end
@@ -87,15 +91,16 @@ module Mongoid
87
91
  # called after each save - making sure only at most two instances exists should be
88
92
  # sufficient to ensure that this data can be rebuilt live without corrupting any
89
93
  # existing computations that might have a handle to the previous "latest" instance.
90
- def ensure_at_most_two_instances_exist
94
+ def ensure_at_most_max_instances_exist
91
95
  all_instances = self.class.order_by([[:created_at, :desc]]).to_a
96
+ max_collection_snapshot_instances = self.class.max_collection_snapshot_instances || 2
92
97
  return unless all_instances.length > max_collection_snapshot_instances
93
98
  all_instances[max_collection_snapshot_instances..-1].each(&:destroy)
94
99
  end
95
100
 
96
101
  # Override to supply custom database connection for snapshots
97
102
  def snapshot_session
98
- Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6? ? Mongoid.default_client : Mongoid.default_session
103
+ Mongoid::VERSION.to_i >= 5 ? Mongoid.default_client : Mongoid.default_session
99
104
  end
100
105
  end
101
106
  end
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test
5
+ imports:
6
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test-imports
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test
5
+ imports:
6
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test-imports
@@ -0,0 +1,6 @@
1
+ test:
2
+ clients:
3
+ default:
4
+ uri: mongodb://localhost:27017/mongoid-collection-snapshot_test
5
+ imports:
6
+ uri: mongodb://localhost:27017/mongoid-collection-snapshot_test-imports
@@ -0,0 +1,6 @@
1
+ test:
2
+ clients:
3
+ default:
4
+ uri: mongodb://<%= ENV.fetch('MONGODB_HOST', 'localhost:27017') %>/mongoid-collection-snapshot_test
5
+ 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)
@@ -55,6 +55,15 @@ module Mongoid
55
55
  end
56
56
  end
57
57
 
58
+ it 'maintains at most max_collection_snapshot_instances of the latest snapshots to support its calculations' do
59
+ AverageArtistPrice.max_collection_snapshot_instances = 5
60
+ AverageArtistPrice.create
61
+ 10.times do
62
+ AverageArtistPrice.create
63
+ end
64
+ expect(AverageArtistPrice.count).to eq(5)
65
+ end
66
+
58
67
  context '#documents' do
59
68
  it 'provides access to a Mongoid collection' do
60
69
  snapshot = AverageArtistPrice.create
@@ -95,7 +104,7 @@ module Mongoid
95
104
 
96
105
  it 'safely cleans up all collections used by the snapshot' do
97
106
  # Create some collections with names close to the snapshots we'll create
98
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
107
+ if Mongoid::VERSION.to_i >= 5
99
108
  Mongoid.default_client["#{MultiCollectionSnapshot.collection.name}.do.not_delete"].insert_one('a' => 1)
100
109
  Mongoid.default_client["#{MultiCollectionSnapshot.collection.name}.snapshorty"].insert_one('a' => 1)
101
110
  Mongoid.default_client["#{MultiCollectionSnapshot.collection.name}.hello.1"].insert_one('a' => 1)
@@ -106,19 +115,19 @@ module Mongoid
106
115
  end
107
116
 
108
117
  MultiCollectionSnapshot.create
109
- 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
110
119
  before_create = collections.map(&:name)
111
120
  expect(before_create.length).to be > 0
112
121
 
113
122
  Timecop.travel(1.second.from_now)
114
123
  MultiCollectionSnapshot.create
115
- 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
116
125
  after_create = collections.map(&:name)
117
126
  collections_created = (after_create - before_create).sort
118
127
  expect(collections_created.length).to eq(3)
119
128
 
120
129
  MultiCollectionSnapshot.latest.destroy
121
- 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
122
131
  after_destroy = collections.map(&:name)
123
132
  collections_destroyed = (after_create - after_destroy).sort
124
133
  expect(collections_created).to eq(collections_destroyed)
@@ -127,13 +136,13 @@ module Mongoid
127
136
 
128
137
  context 'with a custom snapshot connection' do
129
138
  around(:each) do |example|
130
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
139
+ if Mongoid::VERSION.to_i >= 5
131
140
  CustomConnectionSnapshot.snapshot_session.database.drop
132
141
  else
133
142
  CustomConnectionSnapshot.snapshot_session.drop
134
143
  end
135
144
  example.run
136
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
145
+ if Mongoid::VERSION.to_i >= 5
137
146
  CustomConnectionSnapshot.snapshot_session.database.drop
138
147
  else
139
148
  CustomConnectionSnapshot.snapshot_session.drop
@@ -146,7 +155,7 @@ module Mongoid
146
155
  "#{CustomConnectionSnapshot.collection.name}.foo.#{snapshot.slug}",
147
156
  "#{CustomConnectionSnapshot.collection.name}.#{snapshot.slug}"
148
157
  ].each do |collection_name|
149
- 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
150
159
  expect(session[collection_name].find.count).to eq(0)
151
160
  expect(CustomConnectionSnapshot.snapshot_session[collection_name].find.count).to eq(1)
152
161
  end
@@ -154,7 +163,7 @@ module Mongoid
154
163
 
155
164
  context '#documents' do
156
165
  it 'uses the custom session' do
157
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
166
+ if Mongoid::VERSION.to_i >= 5
158
167
  expect(CustomConnectionSnapshot.new.documents.mongo_client).to eq CustomConnectionSnapshot.snapshot_session
159
168
  else
160
169
  expect(CustomConnectionSnapshot.new.documents.mongo_session).to eq CustomConnectionSnapshot.snapshot_session
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ class Widget
4
+ include Mongoid::Document
5
+ end
6
+
7
+ class Gadget
8
+ include Mongoid::Document
9
+ end
10
+
11
+ class WidgetsAndGadgets
12
+ include Mongoid::CollectionSnapshot
13
+
14
+ document do
15
+ belongs_to :widget, inverse_of: nil
16
+ belongs_to :gadget, inverse_of: nil
17
+ end
18
+
19
+ def build
20
+ collection_snapshot.drop
21
+ Widget.all.each do |widget|
22
+ Gadget.all.each do |gadget|
23
+ if Mongoid::VERSION.to_i >= 5
24
+ collection_snapshot.insert_one(widget_id: widget.id, gadget_id: gadget.id)
25
+ else
26
+ collection_snapshot.insert(widget_id: widget.id, gadget_id: gadget.id)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def snapshot_session
33
+ if Mongoid::VERSION.to_i >= 5
34
+ Mongoid.client('imports')
35
+ else
36
+ Mongoid.session('imports')
37
+ end
38
+ end
39
+ end
40
+
41
+ module Mongoid
42
+ describe CollectionSnapshot do
43
+ before do
44
+ Widget.delete_all
45
+ Gadget.delete_all
46
+ Widget.create!
47
+ Gadget.create!
48
+ WidgetsAndGadgets.each.map(&:collection_snapshot).each(&:drop)
49
+ WidgetsAndGadgets.create!
50
+ end
51
+ it 'uses the correct database on a separate thread' do
52
+ expect(WidgetsAndGadgets.latest.documents.count).to eq 1
53
+ require 'thread'
54
+ Thread.new do
55
+ expect(WidgetsAndGadgets.latest.documents.count).to eq 1
56
+ WidgetsAndGadgets.latest.documents.each do |pair|
57
+ expect(pair.widget).to_not be nil
58
+ expect(pair.gadget).to_not be nil
59
+ end
60
+ end.join
61
+ end
62
+ end
63
+ end
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,9 +13,8 @@ require 'rspec'
5
13
  require 'mongoid'
6
14
  require 'timecop'
7
15
 
8
- Mongoid.configure do |config|
9
- config.connect_to('mongoid-collection-snapshot_test')
10
- end
16
+ config_version = [Mongoid::VERSION.to_i, 6].min
17
+ Mongoid.load!("#{File.dirname(__FILE__)}/config/mongoid#{config_version}.yml", :test)
11
18
 
12
19
  require File.expand_path('../../lib/mongoid-collection-snapshot', __FILE__)
13
20
  Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each { |f| require f }
@@ -17,13 +24,13 @@ require 'mongoid-compatibility'
17
24
  RSpec.configure do |c|
18
25
  c.before(:all) do
19
26
  Mongoid.logger.level = Logger::INFO
20
- 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
21
28
  end
22
29
  c.before(:each) do
23
30
  Mongoid.purge!
24
31
  end
25
32
  c.after(:all) do
26
- if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
33
+ if Mongoid::VERSION.to_i >= 5
27
34
  Mongoid.default_client.database.drop
28
35
  else
29
36
  Mongoid.default_session.drop
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.1
4
+ version: 1.3.3
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-05-22 00:00:00.000000000 Z
11
+ date: 2026-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -52,17 +52,17 @@ 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/test.yml"
61
62
  - ".gitignore"
62
63
  - ".rspec"
63
64
  - ".rubocop.yml"
64
65
  - ".rubocop_todo.yml"
65
- - ".travis.yml"
66
66
  - CHANGELOG.md
67
67
  - Dangerfile
68
68
  - Gemfile
@@ -80,6 +80,10 @@ files:
80
80
  - lib/mongoid-collection-snapshot.rb
81
81
  - lib/mongoid-collection-snapshot/version.rb
82
82
  - mongoid-collection-snapshot.gemspec
83
+ - spec/config/mongoid3.yml
84
+ - spec/config/mongoid4.yml
85
+ - spec/config/mongoid5.yml
86
+ - spec/config/mongoid6.yml
83
87
  - spec/models/artist.rb
84
88
  - spec/models/artwork.rb
85
89
  - spec/models/average_price.rb
@@ -87,12 +91,13 @@ files:
87
91
  - spec/models/multi_collection_snapshot.rb
88
92
  - spec/models/partner.rb
89
93
  - spec/mongoid/collection_snapshot_spec.rb
94
+ - spec/mongoid/multiple_databases_spec.rb
90
95
  - spec/spec_helper.rb
91
96
  homepage: http://github.com/mongoid/mongoid-collection-snapshot
92
97
  licenses:
93
98
  - MIT
94
99
  metadata: {}
95
- post_install_message:
100
+ post_install_message:
96
101
  rdoc_options: []
97
102
  require_paths:
98
103
  - lib
@@ -107,9 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
112
  - !ruby/object:Gem::Version
108
113
  version: 1.3.6
109
114
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.6.11
112
- signing_key:
115
+ rubygems_version: 3.5.16
116
+ signing_key:
113
117
  specification_version: 4
114
118
  summary: Easy maintenence of collections of processed data in MongoDB with the Mongoid
115
119
  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