mongoid_versioning 0.0.3 → 0.1.0

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: 3da640238adffc66b1ef2b4aa7c1214e96f76e84
4
- data.tar.gz: bbf75f611e013b11dd7819a46c58c7a739102de5
3
+ metadata.gz: 335f426351947efbcd8dde32386982a9afadfd5c
4
+ data.tar.gz: 39f3168fe68034772d2326c38027f0d8f3535116
5
5
  SHA512:
6
- metadata.gz: fa55a2afa36a3aede3250003ed3225424c8a8215c0a0ead848f2d9a0ee6ba0bc2f16449f5872e0c8252f7b422b97291ecf78418191ad9bffe42ccd4ca5a48098
7
- data.tar.gz: 41bd4e6e8f24f25c3f80e062b4993d7814bd7c18bb0dee72162a7cd6bd828156bd5af0e7d823793680bd086ca72b2fb9d65c1dcb185bb127c9761541bd9eb461
6
+ metadata.gz: 1402591cba459621cbd352dd35c4391edaccc490552f90bf49eeb5954641806123866a15425f56489443085b049f22754ebd9b69001dbe49f39f1bb1414caad9
7
+ data.tar.gz: 0418a28b9439bd5d9c42b1dcf185fc3679b06cfde94ef71c7c1ff6d4fe9c5c11a6a91d5314477b08c6a0509763997981c675444651167db013728bbe509611b2
data/Gemfile.lock CHANGED
@@ -1,96 +1,105 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid_versioning (0.0.3)
5
- mongoid (~> 4.0)
4
+ mongoid_versioning (0.1.0)
5
+ mongoid (~> 5.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (4.2.0)
11
- activesupport (= 4.2.0)
10
+ activemodel (4.2.4)
11
+ activesupport (= 4.2.4)
12
12
  builder (~> 3.1)
13
- activesupport (4.2.0)
13
+ activesupport (4.2.4)
14
14
  i18n (~> 0.7)
15
15
  json (~> 1.7, >= 1.7.7)
16
16
  minitest (~> 5.1)
17
17
  thread_safe (~> 0.3, >= 0.3.4)
18
18
  tzinfo (~> 1.1)
19
- bson (2.3.0)
19
+ bson (3.2.6)
20
20
  builder (3.2.2)
21
- celluloid (0.16.0)
22
- timers (~> 4.0.0)
23
21
  coderay (1.1.0)
24
- connection_pool (2.1.0)
25
- coveralls (0.7.1)
26
- multi_json (~> 1.3)
27
- rest-client
28
- simplecov (>= 0.7)
29
- term-ansicolor
30
- thor
31
- database_cleaner (1.3.0)
22
+ coveralls (0.8.3)
23
+ json (~> 1.8)
24
+ rest-client (>= 1.6.8, < 2)
25
+ simplecov (~> 0.10.0)
26
+ term-ansicolor (~> 1.3)
27
+ thor (~> 0.19.1)
28
+ database_cleaner (1.5.1)
32
29
  docile (1.1.5)
33
- ffi (1.9.5)
30
+ domain_name (0.5.25)
31
+ unf (>= 0.0.5, < 1.0.0)
32
+ ffi (1.9.10)
34
33
  formatador (0.2.5)
35
- guard (2.6.1)
34
+ guard (2.13.0)
36
35
  formatador (>= 0.2.4)
37
- listen (~> 2.7)
36
+ listen (>= 2.7, <= 4.0)
38
37
  lumberjack (~> 1.0)
38
+ nenv (~> 0.1)
39
+ notiffany (~> 0.0)
39
40
  pry (>= 0.9.12)
41
+ shellany (~> 0.0)
40
42
  thor (>= 0.18.1)
41
- guard-minitest (2.3.2)
42
- guard (~> 2.0)
43
+ guard-compat (1.2.1)
44
+ guard-minitest (2.4.4)
45
+ guard-compat (~> 1.2)
43
46
  minitest (>= 3.0)
44
- hitimes (1.2.2)
47
+ http-cookie (1.0.2)
48
+ domain_name (~> 0.5)
45
49
  i18n (0.7.0)
46
- json (1.8.1)
47
- listen (2.7.11)
48
- celluloid (>= 0.15.2)
50
+ json (1.8.3)
51
+ listen (3.0.3)
49
52
  rb-fsevent (>= 0.9.3)
50
53
  rb-inotify (>= 0.9)
51
54
  lumberjack (1.0.9)
52
55
  method_source (0.8.2)
53
- mime-types (2.4.1)
54
- minitest (5.4.2)
55
- mongoid (4.0.0)
56
+ mime-types (2.6.2)
57
+ minitest (5.8.1)
58
+ mongo (2.1.2)
59
+ bson (~> 3.0)
60
+ mongoid (5.0.0)
56
61
  activemodel (~> 4.0)
57
- moped (~> 2.0.0)
62
+ mongo (~> 2.1)
58
63
  origin (~> 2.1)
59
64
  tzinfo (>= 0.3.37)
60
- moped (2.0.2)
61
- bson (~> 2.2)
62
- connection_pool (~> 2.0)
63
- optionable (~> 0.2.0)
64
- multi_json (1.10.1)
65
- netrc (0.7.7)
66
- optionable (0.2.0)
65
+ nenv (0.2.0)
66
+ netrc (0.10.3)
67
+ notiffany (0.0.8)
68
+ nenv (~> 0.1)
69
+ shellany (~> 0.0)
67
70
  origin (2.1.1)
68
- pry (0.10.1)
71
+ pry (0.10.3)
69
72
  coderay (~> 1.1.0)
70
73
  method_source (~> 0.8.1)
71
74
  slop (~> 3.4)
72
- rake (10.3.2)
73
- rb-fsevent (0.9.4)
75
+ rake (10.4.2)
76
+ rb-fsevent (0.9.6)
74
77
  rb-inotify (0.9.5)
75
78
  ffi (>= 0.5.0)
76
- rest-client (1.7.2)
79
+ rest-client (1.8.0)
80
+ http-cookie (>= 1.0.2, < 2.0)
77
81
  mime-types (>= 1.16, < 3.0)
78
82
  netrc (~> 0.7)
79
- simplecov (0.9.1)
83
+ rspec-core (3.3.2)
84
+ rspec-support (~> 3.3.0)
85
+ rspec-support (3.3.0)
86
+ shellany (0.0.1)
87
+ simplecov (0.10.0)
80
88
  docile (~> 1.1.0)
81
- multi_json (~> 1.0)
82
- simplecov-html (~> 0.8.0)
83
- simplecov-html (0.8.0)
89
+ json (~> 1.8)
90
+ simplecov-html (~> 0.10.0)
91
+ simplecov-html (0.10.0)
84
92
  slop (3.6.0)
85
- term-ansicolor (1.3.0)
93
+ term-ansicolor (1.3.2)
86
94
  tins (~> 1.0)
87
95
  thor (0.19.1)
88
- thread_safe (0.3.4)
89
- timers (4.0.1)
90
- hitimes
91
- tins (1.3.3)
96
+ thread_safe (0.3.5)
97
+ tins (1.6.0)
92
98
  tzinfo (1.2.2)
93
99
  thread_safe (~> 0.1)
100
+ unf (0.1.4)
101
+ unf_ext
102
+ unf_ext (0.0.7.1)
94
103
 
95
104
  PLATFORMS
96
105
  ruby
@@ -104,3 +113,4 @@ DEPENDENCIES
104
113
  minitest
105
114
  mongoid_versioning!
106
115
  rake
116
+ rspec-core
data/README.md CHANGED
@@ -87,6 +87,16 @@ To retrieve specific version:
87
87
  doc.version(2) # => MyVersionedDocument
88
88
  ```
89
89
 
90
+ ### Removing versions
91
+
92
+ By default, past versions are never removed. This way it is possible to implement some sort of recovery mechanism of deleted documents.
93
+
94
+ It should be however trivial to implement removal of versions on destroy. For example:
95
+
96
+ ```ruby
97
+ after_destroy -> doc { doc.previous_versions.destroy_all }
98
+ ```
99
+
90
100
  ## Further Reading
91
101
 
92
102
  See [Further Thoughts on How to Track Versions with MongoDB](http://askasya.com/post/revisitversions).
@@ -1,3 +1,3 @@
1
1
  module MongoidVersioning
2
- VERSION = "0.0.3"
3
- end
2
+ VERSION = "0.1.0"
3
+ end
@@ -9,7 +9,7 @@ module MongoidVersioning
9
9
  field :_version, type: Integer
10
10
  field :_based_on_version, type: Integer
11
11
 
12
- versions_collection.indexes.create(
12
+ versions_collection.indexes.create_one(
13
13
  { _orig_id: 1, _version: 1 }, { unique: true }
14
14
  )
15
15
 
@@ -81,7 +81,7 @@ module MongoidVersioning
81
81
  private # =============================================================
82
82
 
83
83
  def set_initial_version
84
- self._version ||= 1
84
+ self[:_version] ||= 1
85
85
  end
86
86
 
87
87
  def revert_id
@@ -98,15 +98,17 @@ module MongoidVersioning
98
98
 
99
99
  current_version = previous_doc._version
100
100
 
101
- res1 = self.class.versions_collection.where(_orig_id: previous_doc['_orig_id'], _version: previous_doc._version).upsert(previous_doc.as_document)
101
+ res1 = self.class.versions_collection.find(_orig_id: previous_doc['_orig_id'], _version: previous_doc._version)
102
+ previous_doc[:_version] = current_version if previous_doc[:_version].nil?
103
+ self.class.versions_collection.insert_one(previous_doc.as_document) if res1.count == 0
102
104
 
103
105
  self._based_on_version = _version || current_version
104
106
  self._version = current_version+1
105
107
 
106
- res2 = self.class.collection.where(_id: id, _version: current_version).update(self.as_document)
108
+ res2 = self.class.collection.find(_id: id, _version: current_version).update_one(self.as_document)
107
109
 
108
110
  # replay flow if someone else updated the document before us
109
- break unless res2['n'] != 1
111
+ break unless res2.n != 1
110
112
  end
111
113
  end
112
114
 
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "mongoid", "~> 4.0"
21
+ spec.add_dependency "mongoid", "~> 5.0.0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rspec-core"
24
25
  spec.add_development_dependency "coveralls"
25
26
  spec.add_development_dependency "database_cleaner"
26
27
  spec.add_development_dependency "guard"
@@ -70,8 +70,8 @@ module MongoidVersioning
70
70
  new_document.name = 'Foo'
71
71
  new_document.revise
72
72
 
73
- @versions = TestDocument.versions_collection.where(_orig_id: new_document.id).sort(_version: -1)
74
- @current = TestDocument.collection.where(_id: new_document.id).first
73
+ @versions = TestDocument.versions_collection.find(_orig_id: new_document.id).sort(_version: -1)
74
+ @current = TestDocument.collection.find(_id: new_document.id).first
75
75
  end
76
76
 
77
77
  it 'sets _version' do
@@ -121,8 +121,8 @@ module MongoidVersioning
121
121
  existing_document.name = 'Foo'
122
122
  existing_document.revise
123
123
 
124
- @versions = TestDocument.versions_collection.where(_orig_id: existing_document.id).sort(_version: -1)
125
- @current = TestDocument.collection.where(_id: existing_document.id).first
124
+ @versions = TestDocument.versions_collection.find(_orig_id: existing_document.id).sort(_version: -1)
125
+ @current = TestDocument.collection.find(_id: existing_document.id).first
126
126
  end
127
127
 
128
128
  it 'sets _version' do
@@ -169,8 +169,8 @@ module MongoidVersioning
169
169
  existing_document.name = 'Bar'
170
170
  existing_document.revise
171
171
 
172
- @versions = TestDocument.versions_collection.where(_orig_id: existing_document.id).sort(_version: -1)
173
- @current = TestDocument.collection.where(_id: existing_document.id).first
172
+ @versions = TestDocument.versions_collection.find(_orig_id: existing_document.id).sort(_version: -1)
173
+ @current = TestDocument.collection.find(_id: existing_document.id).first
174
174
  end
175
175
 
176
176
  it 'sets _version' do
@@ -217,8 +217,8 @@ module MongoidVersioning
217
217
  @user1.revise
218
218
 
219
219
  @result = TestDocument.where(_id: @doc.id).first
220
- @versions = TestDocument.versions_collection.where(_orig_id: @doc.id).sort(_version: -1)
221
- @current = TestDocument.collection.where(_id: @doc.id).first
220
+ @versions = TestDocument.versions_collection.find(_orig_id: @doc.id).sort(_version: -1)
221
+ @current = TestDocument.collection.find(_id: @doc.id).first
222
222
  end
223
223
 
224
224
  it 'will correctly set values' do
data/test/test_helper.rb CHANGED
@@ -25,7 +25,7 @@ def database_id
25
25
  end
26
26
 
27
27
  CONFIG = {
28
- sessions: {
28
+ clients: {
29
29
  default: {
30
30
  database: database_id,
31
31
  hosts: [ "#{HOST}:#{PORT}" ]
@@ -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.0.3
4
+ version: 0.1.0
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-01-01 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: 5.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: 5.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-core
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: coveralls
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
178
  version: '0'
165
179
  requirements: []
166
180
  rubyforge_project:
167
- rubygems_version: 2.2.2
181
+ rubygems_version: 2.4.8
168
182
  signing_key:
169
183
  specification_version: 4
170
184
  summary: Versioning Mongoid documents by means of separate collection.