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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 335f426351947efbcd8dde32386982a9afadfd5c
4
- data.tar.gz: 39f3168fe68034772d2326c38027f0d8f3535116
3
+ metadata.gz: af5fa3f065e4ca5819b480619d7b385f2c537554
4
+ data.tar.gz: 5b05db16d3d5c2a10599f2bf9053b57e01c568cc
5
5
  SHA512:
6
- metadata.gz: 1402591cba459621cbd352dd35c4391edaccc490552f90bf49eeb5954641806123866a15425f56489443085b049f22754ebd9b69001dbe49f39f1bb1414caad9
7
- data.tar.gz: 0418a28b9439bd5d9c42b1dcf185fc3679b06cfde94ef71c7c1ff6d4fe9c5c11a6a91d5314477b08c6a0509763997981c675444651167db013728bbe509611b2
6
+ metadata.gz: 7ee6ad5d4bae63b40faa4325e7c9b538e9b972143950842f0fedf7e92225a8704a5e26651a9ec4a0da92fb3366be290713cfed34d0552fc73b51f0283ea9e165
7
+ data.tar.gz: 933f8e4ded7b13f3e8be2f990244e9a8d29b26edb2b4c9eaf4bf9f152ac1c43695724c2eaaecaa3e274d35aec3ebbe30d586ea523aa7cead71203fa234bf562a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid_versioning (0.1.0)
4
+ mongoid_versioning (0.1.1)
5
5
  mongoid (~> 5.0.0)
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module MongoidVersioning
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
 
@@ -40,6 +40,6 @@ end
40
40
  DatabaseCleaner.orm = :mongoid
41
41
  DatabaseCleaner.strategy = :truncation
42
42
 
43
- # class MiniTest::Spec
44
- # before(:each) { DatabaseCleaner.clean }
45
- # end
43
+ class MiniTest::Spec
44
+ before(:each) { DatabaseCleaner.clean }
45
+ end
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.0
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-22 00:00:00.000000000 Z
11
+ date: 2015-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid