mongoid_versioning 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/mongoid_versioning/version.rb +1 -1
- data/lib/mongoid_versioning/versioned.rb +12 -0
- data/test/mongoid_versioning/versioned_test.rb +16 -0
- data/test/test_helper.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af5fa3f065e4ca5819b480619d7b385f2c537554
|
4
|
+
data.tar.gz: 5b05db16d3d5c2a10599f2bf9053b57e01c568cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ee6ad5d4bae63b40faa4325e7c9b538e9b972143950842f0fedf7e92225a8704a5e26651a9ec4a0da92fb3366be290713cfed34d0552fc73b51f0283ea9e165
|
7
|
+
data.tar.gz: 933f8e4ded7b13f3e8be2f990244e9a8d29b26edb2b4c9eaf4bf9f152ac1c43695724c2eaaecaa3e274d35aec3ebbe30d586ea523aa7cead71203fa234bf562a
|
data/Gemfile.lock
CHANGED
@@ -13,6 +13,8 @@ module MongoidVersioning
|
|
13
13
|
{ _orig_id: 1, _version: 1 }, { unique: true }
|
14
14
|
)
|
15
15
|
|
16
|
+
class_attribute :version_max
|
17
|
+
|
16
18
|
before_create :set_initial_version
|
17
19
|
after_initialize :revert_id
|
18
20
|
end
|
@@ -28,6 +30,10 @@ module MongoidVersioning
|
|
28
30
|
def versions_collection
|
29
31
|
collection.database[versions_collection_name]
|
30
32
|
end
|
33
|
+
|
34
|
+
def max_versions(number)
|
35
|
+
self.version_max = number.to_i
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
# =====================================================================
|
@@ -107,9 +113,15 @@ module MongoidVersioning
|
|
107
113
|
|
108
114
|
res2 = self.class.collection.find(_id: id, _version: current_version).update_one(self.as_document)
|
109
115
|
|
116
|
+
|
117
|
+
|
110
118
|
# replay flow if someone else updated the document before us
|
111
119
|
break unless res2.n != 1
|
112
120
|
end
|
121
|
+
|
122
|
+
if version_max.present? && versions.length > version_max
|
123
|
+
self.class.versions_collection.find(_orig_id: self.id, _version: versions.min_by(&:_version)._version).delete_many
|
124
|
+
end
|
113
125
|
end
|
114
126
|
|
115
127
|
end
|
@@ -8,6 +8,8 @@ class TestDocument
|
|
8
8
|
|
9
9
|
field :name, type: String
|
10
10
|
|
11
|
+
max_versions 5
|
12
|
+
|
11
13
|
validates :name, presence: true
|
12
14
|
|
13
15
|
before_revise -> i { i.callbacks = i.callbacks << 'before_revise' }
|
@@ -81,6 +83,20 @@ module MongoidVersioning
|
|
81
83
|
new_document._based_on_version.must_be_nil
|
82
84
|
end
|
83
85
|
|
86
|
+
it 'version_max' do
|
87
|
+
new_document.revise
|
88
|
+
new_document.versions.count.must_equal 2
|
89
|
+
new_document.revise
|
90
|
+
new_document.versions.count.must_equal 3
|
91
|
+
new_document.revise
|
92
|
+
new_document.versions.count.must_equal 4
|
93
|
+
new_document.revise
|
94
|
+
new_document.versions.count.must_equal 5
|
95
|
+
new_document.revise
|
96
|
+
new_document.versions.count.must_equal 5
|
97
|
+
|
98
|
+
end
|
99
|
+
|
84
100
|
describe 'when invalid' do
|
85
101
|
before { new_document.name = nil }
|
86
102
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_versioning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|