mongoid-auto_increment 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +9 -10
- data/lib/mongoid-auto_increment.rb +1 -2
- data/lib/mongoid/auto_increment.rb +18 -19
- data/lib/mongoid/auto_increment/version.rb +1 -2
- data/test/consistency_test.rb +5 -6
- data/test/models/first_auto_incremented_model.rb +0 -1
- data/test/models/second_auto_incremented_model.rb +1 -2
- data/test/models/subclass_model.rb +0 -1
- data/test/subclass_test.rb +5 -6
- data/test/test_helper.rb +12 -11
- data/test/uniqueness_test.rb +3 -4
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 876e9c2048aae1ca83bdc4b3c1a403f0ea1e74403dcdd6b8ae6efa8d417f9dd2
|
4
|
+
data.tar.gz: 14120f367d8c585b892835914f77413b694c73875406d0bb2ae443283baa68a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc7feb182e438f52ff399296fd1f61a2dbedad995a8b10c0c2a4f595892f32fcfb70d51c5e00700a1b4276f534b43022c35113b327b214609460fa86af133719
|
7
|
+
data.tar.gz: 101401b9fc451c7151c36132596c016624dfcfcff41c5cfb4a18ca0b04a9e80eed8450c67bac75cf4338147469419bfcdd8097ef1ac722d0accd0f7b60ab3d19
|
data/Rakefile
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rake/testtask"
|
4
4
|
|
5
|
-
desc
|
6
|
-
task :
|
5
|
+
desc "Default: run unit tests"
|
6
|
+
task default: :test
|
7
7
|
|
8
|
-
desc
|
8
|
+
desc "Run tests"
|
9
9
|
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs <<
|
11
|
-
t.libs <<
|
12
|
-
t.pattern =
|
13
|
-
t.
|
10
|
+
t.libs << "lib"
|
11
|
+
t.libs << "test"
|
12
|
+
t.pattern = "test/**/*_test.rb"
|
13
|
+
t.warning = false
|
14
14
|
end
|
15
|
-
|
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require "mongoid/auto_increment"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/concern"
|
2
2
|
|
3
3
|
module Mongoid
|
4
4
|
module AutoIncrement
|
@@ -12,33 +12,33 @@ module Mongoid
|
|
12
12
|
class_attribute :auto_increment_collection
|
13
13
|
class_attribute :auto_increment_class_prefix
|
14
14
|
|
15
|
-
self.auto_increment_value_field
|
16
|
-
self.auto_increment_class
|
17
|
-
self.auto_incremented_fields
|
18
|
-
self.auto_increment_classes
|
19
|
-
self.auto_increment_collection
|
20
|
-
self.auto_increment_class_prefix
|
15
|
+
self.auto_increment_value_field = "value"
|
16
|
+
self.auto_increment_class = self
|
17
|
+
self.auto_incremented_fields = []
|
18
|
+
self.auto_increment_classes = []
|
19
|
+
self.auto_increment_collection = "__auto_increments"
|
20
|
+
self.auto_increment_class_prefix = collection_name
|
21
21
|
|
22
22
|
set_callback :create, :before, :auto_increment!, unless: :persisted?
|
23
23
|
|
24
|
-
|
24
|
+
ancestors.each do |klass|
|
25
25
|
if klass.respond_to?(:auto_incremented_fields)
|
26
|
-
|
26
|
+
auto_increment_classes << klass
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
module ClassMethods
|
32
32
|
def auto_incremented(name, opts = {})
|
33
|
-
if
|
34
|
-
self.auto_increment_classes =
|
35
|
-
self.auto_incremented_fields =
|
36
|
-
if
|
37
|
-
self.auto_increment_class_prefix =
|
33
|
+
if auto_increment_class != self
|
34
|
+
self.auto_increment_classes = auto_increment_classes + [self]
|
35
|
+
self.auto_incremented_fields = auto_incremented_fields.dup
|
36
|
+
if auto_increment_class.auto_increment_class_prefix == auto_increment_class_prefix
|
37
|
+
self.auto_increment_class_prefix = collection_name
|
38
38
|
end
|
39
39
|
self.auto_increment_class = self
|
40
40
|
end
|
41
|
-
|
41
|
+
auto_incremented_fields << name
|
42
42
|
field name, opts.merge({type: Integer})
|
43
43
|
end
|
44
44
|
end
|
@@ -47,15 +47,15 @@ module Mongoid
|
|
47
47
|
client = self.class.mongo_client
|
48
48
|
self.class.auto_increment_classes.each do |klass|
|
49
49
|
klass.auto_incremented_fields.each do |name|
|
50
|
-
|
50
|
+
unless self[name]
|
51
51
|
result = client.command({
|
52
52
|
findAndModify: self.class.auto_increment_collection,
|
53
53
|
query: {_id: "#{klass.auto_increment_class_prefix}_#{name}"},
|
54
|
-
update: {
|
54
|
+
update: {"$inc" => {klass.auto_increment_value_field => 1}},
|
55
55
|
upsert: true,
|
56
56
|
new: true,
|
57
57
|
})
|
58
|
-
self[name] = result.first[
|
58
|
+
self[name] = result.first["value"][klass.auto_increment_value_field]
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -72,4 +72,3 @@ module Mongoid
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
data/test/consistency_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class ConsistencyTest < BaseTest
|
4
|
-
test
|
4
|
+
test "single auto increment consistency" do
|
5
5
|
n = 200
|
6
6
|
|
7
7
|
n.times do
|
@@ -11,7 +11,7 @@ class ConsistencyTest < BaseTest
|
|
11
11
|
assert_equal (1..n).to_a, FirstAutoIncrementedModel.only(:identifier).map(&:identifier).sort
|
12
12
|
end
|
13
13
|
|
14
|
-
test
|
14
|
+
test "pre incrementing should not be overriden" do
|
15
15
|
n = 200
|
16
16
|
|
17
17
|
n.times do
|
@@ -23,7 +23,7 @@ class ConsistencyTest < BaseTest
|
|
23
23
|
assert_equal (1..n).to_a, FirstAutoIncrementedModel.only(:identifier).map(&:identifier).sort
|
24
24
|
end
|
25
25
|
|
26
|
-
test
|
26
|
+
test "dup should create new identifier" do
|
27
27
|
n = 100
|
28
28
|
|
29
29
|
n.times do
|
@@ -34,7 +34,7 @@ class ConsistencyTest < BaseTest
|
|
34
34
|
assert_equal (1..(n * 2)).to_a, FirstAutoIncrementedModel.only(:identifier).map(&:identifier).sort
|
35
35
|
end
|
36
36
|
|
37
|
-
test
|
37
|
+
test "double auto increment consistency" do
|
38
38
|
n = 100
|
39
39
|
|
40
40
|
n.times do
|
@@ -46,4 +46,3 @@ class ConsistencyTest < BaseTest
|
|
46
46
|
assert_equal (1..n).to_a, SecondAutoIncrementedModel.only(:identifier).map(&:identifier).sort
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
data/test/subclass_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class SubclassTest < BaseTest
|
4
|
-
test
|
4
|
+
test "subclass auto increment" do
|
5
5
|
n = 200
|
6
6
|
|
7
7
|
n.times do
|
@@ -12,7 +12,7 @@ class SubclassTest < BaseTest
|
|
12
12
|
assert_equal (1..n).to_a, SubclassModel.only(:count).map(&:count).sort
|
13
13
|
end
|
14
14
|
|
15
|
-
test
|
15
|
+
test "subclass auto increment works with base" do
|
16
16
|
n = 100
|
17
17
|
|
18
18
|
n.times do |i|
|
@@ -25,7 +25,7 @@ class SubclassTest < BaseTest
|
|
25
25
|
assert_equal (1..n).to_a, SubclassModel.only(:count).map(&:count).sort
|
26
26
|
end
|
27
27
|
|
28
|
-
test
|
28
|
+
test "mixed auto increment uniqueness" do
|
29
29
|
n = 100
|
30
30
|
|
31
31
|
n.times do
|
@@ -36,7 +36,7 @@ class SubclassTest < BaseTest
|
|
36
36
|
assert_equal n * 2, FirstAutoIncrementedModel.all.uniq.size
|
37
37
|
end
|
38
38
|
|
39
|
-
test
|
39
|
+
test "mixed auto increment consistency" do
|
40
40
|
n = 100
|
41
41
|
|
42
42
|
n.times do
|
@@ -47,4 +47,3 @@ class SubclassTest < BaseTest
|
|
47
47
|
assert_equal (1..(n * 2)).to_a, FirstAutoIncrementedModel.only(:identifier).map(&:identifier).sort
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
data/test/test_helper.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "bundler/setup"
|
2
|
+
require "simplecov"
|
3
3
|
SimpleCov.configure do
|
4
|
-
add_filter
|
4
|
+
add_filter "/test/"
|
5
5
|
end
|
6
|
-
SimpleCov.start if ENV[
|
6
|
+
SimpleCov.start if ENV["COVERAGE"]
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require "minitest/autorun"
|
9
|
+
require "mongoid"
|
10
10
|
|
11
|
-
Mongo::Logger.logger = Logger.new(File.open(File.expand_path(
|
11
|
+
Mongo::Logger.logger = Logger.new(File.open(File.expand_path("../../log/test.log", __FILE__), "a+"))
|
12
12
|
|
13
13
|
require File.expand_path("../../lib/mongoid-auto_increment", __FILE__)
|
14
14
|
|
15
15
|
Mongoid.load!("#{File.dirname(__FILE__)}/mongoid.yml", "test")
|
16
16
|
|
17
|
-
require_relative
|
18
|
-
require_relative
|
19
|
-
require_relative
|
17
|
+
require_relative "models/first_auto_incremented_model"
|
18
|
+
require_relative "models/second_auto_incremented_model"
|
19
|
+
require_relative "models/subclass_model"
|
20
20
|
|
21
21
|
ActiveSupport::TestCase.test_order = :random
|
22
22
|
|
23
23
|
class BaseTest < ActiveSupport::TestCase
|
24
24
|
def teardown
|
25
|
-
Mongoid.default_client.use(
|
25
|
+
Mongoid.default_client.use("mongoid_auto_increment_test").database.drop
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
puts "Testing against mongoid: #{Mongoid::VERSION}"
|
data/test/uniqueness_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class UniquenessTest < BaseTest
|
4
|
-
test
|
4
|
+
test "single auto increment uniqueness" do
|
5
5
|
n = 200
|
6
6
|
|
7
7
|
n.times do
|
@@ -11,7 +11,7 @@ class UniquenessTest < BaseTest
|
|
11
11
|
assert_equal n, FirstAutoIncrementedModel.all.uniq.size
|
12
12
|
end
|
13
13
|
|
14
|
-
test
|
14
|
+
test "double auto increment uniqueness" do
|
15
15
|
n = 100
|
16
16
|
|
17
17
|
n.times do
|
@@ -23,4 +23,3 @@ class UniquenessTest < BaseTest
|
|
23
23
|
assert_equal n, SecondAutoIncrementedModel.all.uniq.size
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-auto_increment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoffroy Planquart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-26 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.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 7.1.0
|
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.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 7.1.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,17 +90,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
|
-
|
94
|
-
rubygems_version: 2.6.13
|
93
|
+
rubygems_version: 3.0.6
|
95
94
|
signing_key:
|
96
95
|
specification_version: 4
|
97
96
|
summary: Auto-incremented field for Mongoid
|
98
97
|
test_files:
|
99
|
-
- test/
|
100
|
-
- test/
|
98
|
+
- test/mongoid.yml
|
99
|
+
- test/consistency_test.rb
|
101
100
|
- test/models/subclass_model.rb
|
102
101
|
- test/models/first_auto_incremented_model.rb
|
103
|
-
- test/
|
104
|
-
- test/test_helper.rb
|
102
|
+
- test/models/second_auto_incremented_model.rb
|
105
103
|
- test/uniqueness_test.rb
|
106
|
-
- test/
|
104
|
+
- test/test_helper.rb
|
105
|
+
- test/subclass_test.rb
|