mongoid-locker 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dc56290fe20687a98a9a031da8334d833f76b64ce44ae28efb1a8facf5db9eb
4
- data.tar.gz: a8c1dccc297c272bc46182e9adc5409c9d9d8add0fd66492bad3344811a896f3
3
+ metadata.gz: 81cc5f3f7114bc807ad56afade38745fb74d2d4ed45eb007a12b0e61a0237450
4
+ data.tar.gz: 81ba6e72064c31a302ffcbfd0a6df6c555051057d2b8890b696ef3b62d033baa
5
5
  SHA512:
6
- metadata.gz: b73d8474bbdc7f106ff2d562614937c9cfeb1c925a3d6dd01f7d50cc57ffca2e742ff34c6c192f6cde7e86a9766939b4aa96b10e280a4e5a6109180aa981e793
7
- data.tar.gz: 8d31f7452bd7d83bf2c54373c309698135f066a32bf006b608fc70fb1caf0bfed15fc6c38b1cc08b7e804ed0cbf1c27bc691b32997331c2e035a3408b383d57a
6
+ metadata.gz: 75b674da45761991d07da697139454f53864327d9b3f0a73b20e5d5a278f1faabce95430c3cfc7e06ff2597a5be4acccb4c714b66d2ec17b0b93ef270c934a5e
7
+ data.tar.gz: 402ab3c14985c52c65b4440c7b763d8b59ccf1f9e33cd97b7324f237353443edd96e9134031ee15735213ed1d19cf8865151f05a0e32dd12d8ce43f3c3e4f04e
@@ -0,0 +1,71 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ entry:
12
+ - { ruby: '2.6.6', mongo: 'mongo:4.4', mongoid: '5' }
13
+ - { ruby: 'jruby-9.1.17.0', mongo: 'mongo:4.4', mongoid: '5' }
14
+ - { ruby: 'jruby-9.2.11.1', mongo: 'mongo:4.4', mongoid: '5' }
15
+ - { ruby: '2.6.6', mongo: 'mongo:4.4', mongoid: '6' }
16
+ - { ruby: '2.7.1', mongo: 'mongo:4.4', mongoid: '6' }
17
+ - { ruby: '3.0.5', mongo: 'mongo:4.4', mongoid: '6' }
18
+ - { ruby: '3.1.3', mongo: 'mongo:4.4', mongoid: '6' }
19
+ - { ruby: 'jruby-9.2.11.1', mongo: 'mongo:4.4', mongoid: '6' }
20
+ - { ruby: '2.6.6', mongo: 'mongo:4.4', mongoid: '7', coverage: 'true' }
21
+ - { ruby: '2.7.1', mongo: 'mongo:4.4', mongoid: '7' }
22
+ - { ruby: '3.0.5', mongo: 'mongo:4.4', mongoid: '7' }
23
+ - { ruby: '3.1.3', mongo: 'mongo:4.4', mongoid: '7' }
24
+ - { ruby: 'jruby-9.2.11.1', mongo: 'mongo:4.4', mongoid: '7' }
25
+ - { ruby: '2.6.6', mongo: 'mongo:4.4', mongoid: '8' }
26
+ - { ruby: '2.7.1', mongo: 'mongo:4.4', mongoid: '8' }
27
+ - { ruby: '3.0.5', mongo: 'mongo:4.4', mongoid: '8' }
28
+ - { ruby: '3.1.3', mongo: 'mongo:4.4', mongoid: '8' }
29
+ experimental: [false]
30
+
31
+ name: test (ruby=${{ matrix.entry.ruby }}, mongo=${{ matrix.entry.mongo }}, mongoid=${{ matrix.entry.mongoid }})
32
+ runs-on: ubuntu-latest
33
+
34
+ continue-on-error: ${{ matrix.experimental }}
35
+
36
+ services:
37
+ mongo:
38
+ image: ${{ matrix.entry.mongo }}
39
+ ports: ["27017:27017"]
40
+
41
+ env:
42
+ MONGOID_VERSION: ${{ matrix.entry.mongoid }}
43
+ COVERAGE: ${{ matrix.entry.coverage }}
44
+
45
+ steps:
46
+ - uses: actions/checkout@v2
47
+
48
+ - name: Set up Ruby
49
+ uses: ruby/setup-ruby@v1
50
+ with:
51
+ ruby-version: ${{ matrix.entry.ruby }}
52
+ bundler-cache: true
53
+
54
+ - name: Checks
55
+ if: ${{ matrix.entry.coverage == 'true' }}
56
+ run: |
57
+ bundle exec rubocop
58
+ # Disabled until mongoid-danger is updated to support Github Actions
59
+ # bundle exec danger
60
+
61
+ - name: Run tests
62
+ run: bundle exec rspec
63
+
64
+ - name: Code Climate
65
+ if: ${{ env.CC_TEST_REPORTER_ID != '' && success() && matrix.entry.coverage == 'true' }}
66
+ run: |
67
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter;
68
+ chmod +x ./cc-test-reporter;
69
+ ./cc-test-reporter before-build;
70
+ ./cc-test-reporter format-coverage -t simplecov -o coverage/codeclimate.json coverage/.resultset.json;
71
+ ./cc-test-reporter upload-coverage;
data/.rubocop.yml CHANGED
@@ -1,2 +1,24 @@
1
+ Lint/RaiseException:
2
+ Enabled: true
3
+
4
+ Lint/StructNewOverride:
5
+ Enabled: true
6
+
7
+ Style/HashEachMethods:
8
+ Enabled: true
9
+
10
+ Style/HashTransformKeys:
11
+ Enabled: true
12
+
13
+ Style/HashTransformValues:
14
+ Enabled: true
15
+
16
+ RSpec/MultipleExpectations:
17
+ Enabled: false
18
+
19
+ RSpec/LeakyConstantDeclaration:
20
+ Enabled: false
21
+
1
22
  inherit_from: .rubocop_todo.yml
23
+
2
24
  require: rubocop-rspec
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-04-05 22:21:29 +0300 using RuboCop version 0.81.0.
3
+ # on 2020-04-07 15:05:45 -0400 using RuboCop version 0.81.0.
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
@@ -13,11 +13,6 @@ Bundler/DuplicatedGem:
13
13
  Exclude:
14
14
  - 'Gemfile'
15
15
 
16
- # Offense count: 2
17
- Lint/AmbiguousBlockAssociation:
18
- Exclude:
19
- - 'spec/test_examples_spec.rb'
20
-
21
16
  # Offense count: 4
22
17
  # Configuration parameters: IgnoredMethods.
23
18
  Metrics/AbcSize:
@@ -66,15 +61,6 @@ RSpec/BeforeAfterAll:
66
61
  - 'spec/support/**/*.rb'
67
62
  - 'spec/test_examples_spec.rb'
68
63
 
69
- # Offense count: 12
70
- # Configuration parameters: Prefixes.
71
- # Prefixes: when, with, without
72
- RSpec/ContextWording:
73
- Exclude:
74
- - 'spec/support/configurations_shared_context.rb'
75
- - 'spec/support/populate_database_shared_context.rb'
76
- - 'spec/support/reset_shared_context.rb'
77
-
78
64
  # Offense count: 1
79
65
  RSpec/DescribeClass:
80
66
  Exclude:
@@ -93,23 +79,12 @@ RSpec/FilePath:
93
79
  Exclude:
94
80
  - 'spec/mongoid-locker_spec.rb'
95
81
 
96
- # Offense count: 7
97
- RSpec/LeakyConstantDeclaration:
98
- Exclude:
99
- - 'spec/support/configurations_shared_context.rb'
100
- - 'spec/test_examples_spec.rb'
101
-
102
82
  # Offense count: 12
103
83
  # Configuration parameters: .
104
84
  # SupportedStyles: have_received, receive
105
85
  RSpec/MessageSpies:
106
86
  EnforcedStyle: receive
107
87
 
108
- # Offense count: 10
109
- # Configuration parameters: AggregateFailuresByDefault.
110
- RSpec/MultipleExpectations:
111
- Max: 3
112
-
113
88
  # Offense count: 1
114
89
  RSpec/SubjectStub:
115
90
  Exclude:
data/.travis.yml CHANGED
@@ -1,54 +1,16 @@
1
- services:
2
- - mongodb
3
-
4
1
  language: ruby
5
2
 
6
3
  cache: bundler
7
4
 
8
- script:
9
- - bundle exec rspec
10
-
11
5
  rvm:
12
- - 2.3.8
13
- - 2.4.7
14
- - 2.5.7
15
6
  - 2.6.6
16
- - 2.7.1
17
- - jruby-9.1.17.0
18
- - jruby-9.2.11.1
19
7
 
20
8
  env:
21
- - MONGOID_VERSION=5
22
- - MONGOID_VERSION=6
23
9
  - MONGOID_VERSION=7
24
10
 
25
- matrix:
26
- include:
27
- - rvm: 2.6.6
28
- env:
29
- - MONGOID_VERSION=7
30
- - COVERAGE=true
31
- before_script:
32
- - bundle exec rubocop
33
- - bundle exec danger
34
- after_script:
35
- - if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then
36
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter;
37
- chmod +x ./cc-test-reporter;
38
- ./cc-test-reporter before-build;
39
- ./cc-test-reporter format-coverage -t simplecov -o coverage/codeclimate.json coverage/.resultset.json;
40
- ./cc-test-reporter upload-coverage;
41
- fi
42
- - rvm: ruby-head
43
- env: MONGOID_VERSION=7
44
- - rvm: jruby-head
45
- env: MONGOID_VERSION=7
46
- exclude:
47
- - rvm: 2.7.1
48
- env: MONGOID_VERSION=5
49
- fast_finish: true
50
- allow_failures:
51
- - rvm: ruby-head
52
- - rvm: jruby-head
11
+ before_script:
12
+ - bundle exec danger
13
+
14
+ script:
15
+ - echo SKIP
53
16
 
54
- bundler_args: --without development
data/CHANGELOG.md CHANGED
@@ -1,28 +1,35 @@
1
1
  ## Changelog
2
2
 
3
+ ### 2.0.2 (2023-01-24)
4
+
5
+ * [#92](https://github.com/mongoid/mongoid-locker/pull/92): Removed TTL and updated unique index definitions - [@cesarizu](https://github.com/cesarizu).
6
+ * [#96](https://github.com/mongoid/mongoid-locker/pull/96): `new Date()` replaced by `Time.now.utc` - [@rsosag](https://github.com/rsosag).
7
+ * [#96](https://github.com/mongoid/mongoid-locker/pull/96): Update the use of the `change` method in tests - [@rsosag](https://github.com/rsosag).
8
+ * [#97](https://github.com/mongoid/mongoid-locker/pull/97): Added support for mongoid 8.0.x versions - [@randikabanura](https://github.com/randikabanura).
9
+
3
10
  ### 2.0.1 (2020-06-17)
4
11
 
5
12
  * [#86](https://github.com/mongoid/mongoid-locker/pull/86): Upgraded to RuboCop 0.81.0 - [@dks17](https://github.com/dks17).
6
13
  * [#86](https://github.com/mongoid/mongoid-locker/pull/86): Fixed issue with `ruby` `delegate` method - [@dks17](https://github.com/dks17).
7
- * [#86](https://github.com/mongoid/mongoid-locker/pull/86): Update Ruby and JRUby versions for Travis config - [@dks17](https://github.com/dks17).
8
- * [#88](https://github.com/mongoid/mongoid-locker/pull/88): Add RSpec test examples - [@dks17](https://github.com/dks17).
14
+ * [#86](https://github.com/mongoid/mongoid-locker/pull/86): Updated Ruby and JRUby versions for Travis config - [@dks17](https://github.com/dks17).
15
+ * [#88](https://github.com/mongoid/mongoid-locker/pull/88): Added RSpec test examples - [@dks17](https://github.com/dks17).
9
16
 
10
17
  ### 2.0.0 (2019-10-23)
11
18
 
12
- * [#79](https://github.com/mongoid/mongoid-locker/pull/79): Update find_and_lock and find_and_unlock methods - [@dks17](https://github.com/dks17).
13
- * [#78](https://github.com/mongoid/mongoid-locker/pull/78): Upgrade to v2.0 - [@dks17](https://github.com/dks17).
19
+ * [#79](https://github.com/mongoid/mongoid-locker/pull/79): Updated find_and_lock and find_and_unlock methods - [@dks17](https://github.com/dks17).
20
+ * [#78](https://github.com/mongoid/mongoid-locker/pull/78): Upgraded to v2.0 - [@dks17](https://github.com/dks17).
14
21
  * [#83](https://github.com/mongoid/mongoid-locker/pull/83): Upgraded to RuboCop 0.75.1 - [@dblock](https://github.com/dblock).
15
22
 
16
23
  ### 1.0.1 (2019-03-23)
17
24
 
18
- * [#74](https://github.com/mongoid/mongoid-locker/pull/74): Add JRuby tests - [@dks17](https://github.com/dks17).
25
+ * [#74](https://github.com/mongoid/mongoid-locker/pull/74): Added JRuby tests - [@dks17](https://github.com/dks17).
19
26
  * [#68](https://github.com/mongoid/mongoid-locker/pull/68): Fix Rubocop offenses, refactoring, update `ruby` versions, add `COVERAGE` test env, update `.travis.yml` matrix - [@dks17](https://github.com/dks17).
20
- * [#67](https://github.com/mongoid/mongoid-locker/pull/67): Deprecate `:wait` in favor of `:retries` option, which can attempt to grab a lock multiple times - [@afeld](https://github.com/afeld), [@dks17](https://github.com/dks17).
27
+ * [#67](https://github.com/mongoid/mongoid-locker/pull/67): Deprecated `:wait` in favor of `:retries` option, which can attempt to grab a lock multiple times - [@afeld](https://github.com/afeld), [@dks17](https://github.com/dks17).
21
28
  * [#66](https://github.com/mongoid/mongoid-locker/pull/66): Fix Mongoid::Locker::LockError for not persisted document - [@dks17](https://github.com/dks17).
22
- * [#65](https://github.com/mongoid/mongoid-locker/pull/65): Drop `mongoid-compatibility` gem dependency - [@dks17](https://github.com/dks17).
29
+ * [#65](https://github.com/mongoid/mongoid-locker/pull/65): Dropped `mongoid-compatibility` gem dependency - [@dks17](https://github.com/dks17).
23
30
  * [#64](https://github.com/mongoid/mongoid-locker/pull/64): Exclude demo files from the gem - [@dks17](https://github.com/dks17).
24
- * [#60](https://github.com/mongoid/mongoid-locker/pull/60): Drop support for `mongoid` version `2` and `3` - [@dks17](https://github.com/dks17).
25
- * [#60](https://github.com/mongoid/mongoid-locker/pull/60): Add SimpleCov - [@dks17](https://github.com/dks17).
31
+ * [#60](https://github.com/mongoid/mongoid-locker/pull/60): Dropped support for `mongoid` version `2` and `3` - [@dks17](https://github.com/dks17).
32
+ * [#60](https://github.com/mongoid/mongoid-locker/pull/60): Added SimpleCov - [@dks17](https://github.com/dks17).
26
33
 
27
34
  ### 1.0.0 (2018-09-02)
28
35
 
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  case ENV['MONGOID_VERSION']
7
+ when /^8/
8
+ gem 'mongoid', '~> 8.0'
7
9
  when /^7/
8
10
  gem 'mongoid', '~> 7.0'
9
11
  when /^6/
@@ -23,6 +25,7 @@ end
23
25
  group :development, :test do
24
26
  gem 'pry-byebug', platforms: :mri
25
27
 
28
+ gem 'mongoid-compatibility'
26
29
  gem 'mongoid-danger', '~> 0.1.1'
27
30
  gem 'rspec', '~> 3.9'
28
31
  gem 'rubocop', '0.81.0'
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Mongoid-Locker
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/mongoid-locker.svg)](https://badge.fury.io/rb/mongoid-locker)
4
+ [![Test Status](https://github.com/mongoid/mongoid-locker/workflows/Test/badge.svg)](https://github.com/mongoid/mongoid-locker/actions)
4
5
  [![Build Status](https://travis-ci.org/mongoid/mongoid-locker.svg?branch=master)](https://travis-ci.org/mongoid/mongoid-locker)
5
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/04ee4ee75ff54659300a/maintainability)](https://codeclimate.com/github/mongoid/mongoid-locker/maintainability)
6
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/04ee4ee75ff54659300a/test_coverage)](https://codeclimate.com/github/mongoid/mongoid-locker/test_coverage)
@@ -11,12 +12,12 @@ Document-level optimistic locking for MongoDB via Mongoid. Mongoid-Locker is an
11
12
 
12
13
  **NOTE:** Please refer to [1-x-stable](https://github.com/mongoid/mongoid-locker/tree/1-x-stable) branch for `1.x.x` documentation. See the [UPGRADING](UPGRADING.md) guide and [CHANGELOG](CHANGELOG.md) for an overview of the changes.
13
14
 
14
- [Tested](https://travis-ci.org/mongoid/mongoid-locker) against:
15
- - MRI: `2.3.8`, `2.4.7`, `2.5.7`, `2.6.6`, `2.7.1`
15
+ [Tested](https://github.com/mongoid/mongoid-locker/actions) against:
16
+ - MRI: `2.3.8`, `2.4.7`, `2.5.7`, `2.6.6`, `2.7.1`, `3.0.5`, `3.1.3`
16
17
  - JRuby `9.1.17.0`, `9.2.11.1`
17
- - Mongoid: `5`, `6`, `7`
18
+ - Mongoid: `5`, `6`, `7`, `8`
18
19
 
19
- See [.travis.yml](.travis.yml) for the latest test matrix.
20
+ See [.github/workflows/test.yml](.github/workflows/test.yml) for the latest test matrix.
20
21
 
21
22
  ## Usage
22
23
 
@@ -37,8 +38,6 @@ class User
37
38
  field :locked_at, type: Time
38
39
 
39
40
  field :age, type: Integer
40
-
41
- index({ _id: 1, locking_name: 1 }, name: 'mongoid_locker_index', sparse: true, unique: true, expire_after_seconds: lock_timeout)
42
41
  end
43
42
  ```
44
43
 
data/RELEASING.md CHANGED
@@ -12,7 +12,7 @@ bundle install
12
12
  bundle exec rake
13
13
  ```
14
14
 
15
- Check that the last build succeeded in [Travis CI](https://travis-ci.org/mongoid/mongoid-locker) for all supported platforms.
15
+ Check that the last build succeeded in [GitHub Actions](https://github.com/mongoid/mongoid-locker/actions) for all supported platforms.
16
16
 
17
17
  Check the version, if needed modify [lib/mongoid/locker/version.rb](lib/mongoid/locker/version.rb).
18
18
 
@@ -8,7 +8,7 @@ module Mongoid
8
8
  BASE_KEY = 'mongoid.locker.errors.messages'
9
9
 
10
10
  def initialize(key, **params)
11
- message = I18n.translate("#{BASE_KEY}.#{key}.message", params)
11
+ message = I18n.translate("#{BASE_KEY}.#{key}.message", **params)
12
12
 
13
13
  super("\nmessage:\n #{message}")
14
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Locker
5
- VERSION = '2.0.1'
5
+ VERSION = '2.0.2'
6
6
  end
7
7
  end
@@ -138,8 +138,7 @@ module Mongoid
138
138
  where(
139
139
  '$and': [
140
140
  { locking_name_field => { '$exists': true, '$ne': nil } },
141
- { locked_at_field => { '$exists': true, '$ne': nil } },
142
- { '$where': "new Date() - this.#{locked_at_field} < #{lock_timeout * 1000}" }
141
+ { locked_at_field => { '$gte': Time.now.utc - (lock_timeout * 1000) } }
143
142
  ]
144
143
  )
145
144
  end
@@ -168,9 +167,7 @@ module Mongoid
168
167
  { locked_at_field => { '$eq': nil } }
169
168
  ]
170
169
  },
171
- {
172
- '$where': "new Date() - this.#{locked_at_field} >= #{lock_timeout * 1000}"
173
- }
170
+ { locked_at_field => { '$lt': Time.now.utc - (lock_timeout * 1000) } }
174
171
  ]
175
172
  )
176
173
  end
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_dependency 'mongoid', '>= 5.0', '< 8'
21
+ s.add_dependency 'mongoid', '>= 5.0', '< 9'
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-locker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aidan Feldman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2023-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8'
22
+ version: '9'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8'
32
+ version: '9'
33
33
  description: Allows multiple processes to operate on individual documents in MongoDB
34
34
  while ensuring that only one can act at a time.
35
35
  email:
@@ -38,6 +38,7 @@ executables: []
38
38
  extensions: []
39
39
  extra_rdoc_files: []
40
40
  files:
41
+ - ".github/workflows/test.yml"
41
42
  - ".gitignore"
42
43
  - ".rspec"
43
44
  - ".rubocop.yml"
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubygems_version: 3.1.3
83
+ rubygems_version: 3.0.9
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: Document-level optimistic locking for MongoDB via Mongoid.