mongo_mapper_acts_as_versioned 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +64 -24
- data/lib/acts_as_versioned.rb +68 -32
- data/spec/acts_as_versioned_spec.rb +67 -67
- data/spec/spec_helper.rb +10 -9
- 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: c112d7390018bff2595ef3b03c4d8bda1b99232d
|
4
|
+
data.tar.gz: cce2fb0907beb7d3d30dae48bdcdba47a877d653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9305d32fe1697cc8e0bd26bd4cfa3f1cb5e5f44534c8a270ec2f07e65031eb6f95478f294a08c768c12d2c06236f6c4048170bae81023a6a06d6defa2a0299cb
|
7
|
+
data.tar.gz: d661de01a41d287253ffa18f6f6d8a5013b6a31b84c8488537f35fffeb03595be423cbc11668e387cf1247b3404a03f59f8cb0973715bc27a2acc844584e50a5
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -8,32 +8,34 @@ Stores changed attributes in a single collection using a general Hash key.
|
|
8
8
|
|
9
9
|
### Basic Example
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
```ruby
|
12
|
+
class Page
|
13
|
+
include MongoMapper::Document
|
13
14
|
|
14
|
-
|
15
|
+
plugin MongoMapper::Acts::Versioned
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
key :title, String
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
page = Page.create(:title => 'title')
|
21
|
+
page.version # => 1
|
22
|
+
page.versions.size # => 1
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
page.title = 'new title'
|
25
|
+
page.save
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
page = page.reload
|
28
|
+
page.version # => 2
|
29
|
+
page.versions.size # => 2
|
30
|
+
page.title # => 'new title'
|
30
31
|
|
31
|
-
|
32
|
+
page.revert_to!(1)
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
page = page.reload
|
35
|
+
page.version # => 1
|
36
|
+
page.versions.size # => 2
|
37
|
+
page.title # => 'title'
|
38
|
+
```
|
37
39
|
|
38
40
|
### Keys that do not trigger new versions
|
39
41
|
|
@@ -53,11 +55,6 @@ Default ignored keys are:
|
|
53
55
|
|
54
56
|
Simply add `do_not_version 'new_skipped_key', 'another_skipped_key'` somewhere in your model.
|
55
57
|
|
56
|
-
## Tested with
|
57
|
-
|
58
|
-
* MongoMapper 0.11.1, 0.13.1, 0.14.0
|
59
|
-
* Ruby 1.9.2 up to 2.4.0
|
60
|
-
|
61
58
|
## Older MongoMapper versions
|
62
59
|
|
63
60
|
* For MongoMapper <= 0.8.6, see the master branch of this repository.
|
@@ -66,10 +63,53 @@ Simply add `do_not_version 'new_skipped_key', 'another_skipped_key'` somewhere i
|
|
66
63
|
|
67
64
|
* See the next branch of this repository.
|
68
65
|
|
66
|
+
### Upgrading from older embedded document versions
|
67
|
+
|
68
|
+
Since 0.3.0, versions have moved into standalone documents rather than embedded documents,
|
69
|
+
mostly for performance reasons.
|
70
|
+
In hindsight, it didn't really make much sense to load all of a document's versions in every query
|
71
|
+
(unless a query specified `.fields` without `:versions`), on top of the actual document itself.
|
72
|
+
Versions are now only loaded when specifically requested. Existing versions in your system
|
73
|
+
will however not be automatically updated.
|
74
|
+
|
75
|
+
Here's an example script that can do it for you.
|
76
|
+
Assuming models called Page and Template, you can convert its old versions through a script
|
77
|
+
like such:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
models = [Page, Template]
|
81
|
+
|
82
|
+
models.each do |model|
|
83
|
+
model.const_set(:Version, Class.new {
|
84
|
+
include MongoMapper::EmbeddedDocument
|
85
|
+
key :modified
|
86
|
+
key :version
|
87
|
+
})
|
88
|
+
|
89
|
+
model.many :versions, class_name: "#{model.name}::Version"
|
90
|
+
|
91
|
+
model.all.each do |document|
|
92
|
+
document.versions.each do |old_version|
|
93
|
+
MongoMapper::Acts::Versioned::DocumentVersion.create(
|
94
|
+
entity_type: model.name,
|
95
|
+
entity_id: document.id,
|
96
|
+
modified: old_version.modified,
|
97
|
+
version: old_version.version
|
98
|
+
) || warn("Didnt create new version for #{old_version.inspect}")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
69
104
|
## Bundler note
|
70
105
|
|
71
106
|
Make sure to specify `:require => 'acts_as_versioned'` in your Gemfile.
|
72
107
|
|
108
|
+
## Tested with
|
109
|
+
|
110
|
+
* MongoMapper 0.11.1, 0.13.1, 0.14.0
|
111
|
+
* Ruby 1.9.2 up to 2.4.0
|
112
|
+
|
73
113
|
## Copyright
|
74
114
|
|
75
115
|
See LICENSE.
|
data/lib/acts_as_versioned.rb
CHANGED
@@ -2,6 +2,7 @@ require "active_support"
|
|
2
2
|
require "active_support/concern"
|
3
3
|
if ActiveSupport.version >= Gem::Version.new("5.0.0")
|
4
4
|
begin
|
5
|
+
# MongoMapper doesn't work without this since it was extracted from Rails in 5.0+
|
5
6
|
require "activemodel-serializers-xml"
|
6
7
|
rescue LoadError
|
7
8
|
warn "Couldn't load AM serializers. Things might break."
|
@@ -13,9 +14,15 @@ require "active_model"
|
|
13
14
|
module MongoMapper
|
14
15
|
module Acts
|
15
16
|
module Versioned
|
17
|
+
VERSION = "0.3.3"
|
18
|
+
|
19
|
+
# This model stores all version information.
|
16
20
|
class DocumentVersion
|
17
21
|
include MongoMapper::Document
|
18
|
-
|
22
|
+
# Manually set the collection name to
|
23
|
+
# "document_versions"
|
24
|
+
# instead of the default
|
25
|
+
# "mongo_mapper.acts.versioned.document_versions"
|
19
26
|
set_collection_name "document_versions"
|
20
27
|
|
21
28
|
key :modified, Hash
|
@@ -27,39 +34,49 @@ module MongoMapper
|
|
27
34
|
belongs_to :entity, polymorphic: true
|
28
35
|
end
|
29
36
|
|
37
|
+
# Required in order to act as a MM plugin.
|
30
38
|
extend ActiveSupport::Concern
|
31
39
|
|
32
|
-
|
40
|
+
# Callbacks that should be silenced when saving without revision.
|
33
41
|
CALLBACKS = [:save_version, :clear_old_versions]
|
34
42
|
|
43
|
+
# Set defaults when plugin is included into model.
|
35
44
|
included do
|
36
45
|
class_attribute :non_versioned_keys, :max_version_limit
|
37
46
|
|
38
|
-
self.max_version_limit
|
39
|
-
self.non_versioned_keys
|
47
|
+
self.max_version_limit = 0
|
48
|
+
self.non_versioned_keys = %w(
|
40
49
|
_id _type created_at updated_at
|
41
50
|
creator_id updater_id version
|
42
51
|
)
|
43
52
|
|
53
|
+
# The document's current version.
|
44
54
|
key :version, Integer
|
55
|
+
|
45
56
|
before_save :save_version
|
46
57
|
before_save :clear_old_versions
|
47
58
|
end
|
48
59
|
|
60
|
+
# All DocumentVersion documents belonging to this document.
|
61
|
+
# Returns +Plucky::Query+.
|
49
62
|
def versions
|
50
63
|
MongoMapper::Acts::Versioned::DocumentVersion.where(
|
51
64
|
entity_type: self.class.name, entity_id: self.id
|
52
65
|
)
|
53
66
|
end
|
54
67
|
|
68
|
+
# Grab a specific DocumentVersion document by +given_version+ number.
|
55
69
|
def document_version(given_version)
|
56
70
|
versions.where(version: given_version).first
|
57
71
|
end
|
58
72
|
|
73
|
+
# Grab the DocumentVersion document corresponding with this document's
|
74
|
+
# current +version+.
|
59
75
|
def current_document_version
|
60
76
|
document_version(version)
|
61
77
|
end
|
62
78
|
|
79
|
+
# Save a new version for this document.
|
63
80
|
def save_version
|
64
81
|
if new_record? || save_version?
|
65
82
|
self.version = next_version
|
@@ -75,43 +92,58 @@ module MongoMapper
|
|
75
92
|
end
|
76
93
|
end
|
77
94
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
if excess_bagage > 0
|
83
|
-
versions.select { |v| v.version.to_i <= excess_bagage }.map(&:delete)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def revert_to(rev)
|
88
|
-
if rev.is_a?(MongoMapper::Acts::Versioned::DocumentVersion)
|
89
|
-
return false if rev.new_record?
|
95
|
+
# Change the current document's attributes to those of a given +revision+.
|
96
|
+
def revert_to(revision)
|
97
|
+
if revision.is_a?(MongoMapper::Acts::Versioned::DocumentVersion)
|
98
|
+
return false if revision.new_record?
|
90
99
|
else
|
91
|
-
return false unless
|
100
|
+
return false unless revision = document_version(revision)
|
92
101
|
end
|
93
102
|
|
94
|
-
clone_attributes(
|
95
|
-
self.version =
|
103
|
+
clone_attributes(revision, self)
|
104
|
+
self.version = revision.version
|
96
105
|
|
97
106
|
true
|
98
107
|
end
|
99
108
|
|
100
|
-
|
101
|
-
|
109
|
+
# Change the current document's attributes to those of a given +revision+,
|
110
|
+
# and save the document.
|
111
|
+
def revert_to!(revision)
|
112
|
+
revert_to(revision) and save_without_revision or false
|
102
113
|
end
|
103
114
|
|
115
|
+
# Save this document without creating a new version.
|
104
116
|
def save_without_revision
|
105
|
-
|
106
|
-
true
|
107
|
-
rescue
|
108
|
-
false
|
117
|
+
without_revision { save }
|
109
118
|
end
|
110
119
|
|
120
|
+
# Save this document without creating a new version. Raises on save
|
121
|
+
# failure.
|
111
122
|
def save_without_revision!
|
112
123
|
without_revision { save! }
|
113
124
|
end
|
114
125
|
|
126
|
+
# Forwards to +self.class.without_revision+.
|
127
|
+
def without_revision(&block)
|
128
|
+
self.class.without_revision(&block)
|
129
|
+
end
|
130
|
+
|
131
|
+
protected
|
132
|
+
|
133
|
+
# Clear old versions based on +self.class.max_version_limit+.
|
134
|
+
# If this limit is 0, no versions are removed.
|
135
|
+
def clear_old_versions
|
136
|
+
return if self.class.max_version_limit == 0
|
137
|
+
excess_bagage = version.to_i - self.class.max_version_limit
|
138
|
+
|
139
|
+
if excess_bagage > 0
|
140
|
+
versions.select { |v| v.version.to_i <= excess_bagage }.map(&:delete)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Copy the attributes specified in +self.class.versioned_keys+ from either
|
145
|
+
# a +DocumentVersion+ into this document, or from this document into a
|
146
|
+
# +DocumentVersion+.
|
115
147
|
def clone_attributes(orig_model, new_model)
|
116
148
|
if orig_model.is_a?(MongoMapper::Acts::Versioned::DocumentVersion)
|
117
149
|
orig_model = orig_model.modified
|
@@ -124,37 +156,41 @@ module MongoMapper
|
|
124
156
|
end
|
125
157
|
end
|
126
158
|
|
159
|
+
# Should a new version be saved?
|
127
160
|
def save_version?
|
128
161
|
(self.class.versioned_keys & changed).any?
|
129
162
|
end
|
130
163
|
|
131
|
-
|
132
|
-
self.class.without_revision(&block)
|
133
|
-
end
|
134
|
-
|
164
|
+
# Do nothing.
|
135
165
|
def empty_callback
|
136
166
|
end
|
137
167
|
|
138
|
-
|
139
|
-
|
168
|
+
# Next version number, based on current version.
|
140
169
|
def next_version
|
141
170
|
new_record? || versions.count == 0 ?
|
142
171
|
1 : versions.fields(:version).map(&:version).max.next
|
143
172
|
end
|
144
173
|
|
145
174
|
module ClassMethods
|
175
|
+
# Keys/attributes that should be saved in versions.
|
176
|
+
#
|
177
|
+
# Returns all available keys minus those found in the
|
178
|
+
# +non_versioned_keys+ list.
|
146
179
|
def versioned_keys
|
147
|
-
keys.keys - non_versioned_keys
|
180
|
+
keys.keys - non_versioned_keys.map(&:to_s)
|
148
181
|
end
|
149
182
|
|
183
|
+
# Add given +args+ to the +non_versioned_keys+ list.
|
150
184
|
def do_not_version(*args)
|
151
185
|
self.non_versioned_keys |= args
|
152
186
|
end
|
153
187
|
|
188
|
+
# Set +max_version_limit+ as +amount+.
|
154
189
|
def max_versions(amount)
|
155
190
|
self.max_version_limit = amount
|
156
191
|
end
|
157
192
|
|
193
|
+
# Versioning-related are silenced within given +&block+.
|
158
194
|
def without_revision
|
159
195
|
class_eval do
|
160
196
|
CALLBACKS.each do |attr_name|
|
@@ -7,7 +7,7 @@ describe MongoMapper::Acts::Versioned do
|
|
7
7
|
include MongoMapper::Document
|
8
8
|
|
9
9
|
plugin MongoMapper::Acts::Versioned
|
10
|
-
do_not_version
|
10
|
+
do_not_version :depth
|
11
11
|
|
12
12
|
key :title, String
|
13
13
|
key :depth, Integer
|
@@ -21,10 +21,10 @@ describe MongoMapper::Acts::Versioned do
|
|
21
21
|
|
22
22
|
it 'should save a versioned copy' do
|
23
23
|
l = Landmark.create(:title => 'title')
|
24
|
-
l.new_record
|
25
|
-
l.versions.size.
|
26
|
-
l.version.
|
27
|
-
l.versions.first.
|
24
|
+
expect(l.new_record?).to be_falsy
|
25
|
+
expect(l.versions.size).to eq 1
|
26
|
+
expect(l.version).to eq 1
|
27
|
+
expect(l.versions.first).to be_a(MongoMapper::Acts::Versioned::DocumentVersion)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should clear old versions when a limit is set' do
|
@@ -37,20 +37,20 @@ describe MongoMapper::Acts::Versioned do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
l = l.reload
|
40
|
-
l.versions.size.
|
41
|
-
l.versions.first.version.
|
42
|
-
l.versions.last.version.
|
40
|
+
expect(l.versions.size).to eq 3
|
41
|
+
expect(l.versions.first.version).to eq 8
|
42
|
+
expect(l.versions.last.version).to eq 10
|
43
43
|
|
44
44
|
Landmark.max_version_limit = 0
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should save without revision' do
|
48
48
|
l = Landmark.create(:title => 'title')
|
49
|
-
l.version.
|
49
|
+
expect(l.version).to eq 1
|
50
50
|
|
51
51
|
l.update_attributes(:title => 'changed')
|
52
52
|
l = l.reload
|
53
|
-
l.version.
|
53
|
+
expect(l.version).to eq 2
|
54
54
|
|
55
55
|
old_versions = l.versions.size
|
56
56
|
|
@@ -60,7 +60,7 @@ describe MongoMapper::Acts::Versioned do
|
|
60
60
|
l.update_attributes :title => 'changed again'
|
61
61
|
end
|
62
62
|
|
63
|
-
l.reload.versions.size.
|
63
|
+
expect(l.reload.versions.size).to eq old_versions
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should rollback with version number' do
|
@@ -71,15 +71,15 @@ describe MongoMapper::Acts::Versioned do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
l = l.reload
|
74
|
-
l.version.
|
75
|
-
l.versions.size.
|
76
|
-
l.title.
|
74
|
+
expect(l.version).to eq 10
|
75
|
+
expect(l.versions.size).to eq 10
|
76
|
+
expect(l.title).to eq 'title10'
|
77
77
|
|
78
|
-
l.revert_to!(7).
|
78
|
+
expect(l.revert_to!(7)).to be_truthy
|
79
79
|
l = l.reload
|
80
|
-
l.version.
|
81
|
-
l.versions.size.
|
82
|
-
l.title.
|
80
|
+
expect(l.version).to eq 7
|
81
|
+
expect(l.versions.size).to eq 10
|
82
|
+
expect(l.title).to eq 'title7'
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'should rollback with version class' do
|
@@ -90,15 +90,15 @@ describe MongoMapper::Acts::Versioned do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
l = l.reload
|
93
|
-
l.version.
|
94
|
-
l.versions.size.
|
95
|
-
l.title.
|
93
|
+
expect(l.version).to eq 10
|
94
|
+
expect(l.versions.size).to eq 10
|
95
|
+
expect(l.title).to eq 'title10'
|
96
96
|
|
97
|
-
l.revert_to!(l.document_version(7)).
|
97
|
+
expect(l.revert_to!(l.document_version(7))).to be_truthy
|
98
98
|
l = l.reload
|
99
|
-
l.version.
|
100
|
-
l.versions.size.
|
101
|
-
l.title.
|
99
|
+
expect(l.version).to eq 7
|
100
|
+
expect(l.versions.size).to eq 10
|
101
|
+
expect(l.title).to eq 'title7'
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should have versioned records belong to its parent' do
|
@@ -109,68 +109,68 @@ describe MongoMapper::Acts::Versioned do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
l_version = l.reload.versions.last
|
112
|
-
l_version.entity.
|
112
|
+
expect(l_version.entity).to eq l.reload
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'should not create new versions for skipped keys' do
|
116
116
|
l = Landmark.create(:title => 'title')
|
117
117
|
l.update_attributes(:depth => 1)
|
118
118
|
l = l.reload
|
119
|
-
l.version.
|
120
|
-
l.versions.size.
|
119
|
+
expect(l.version).to eq 1
|
120
|
+
expect(l.versions.size).to eq 1
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should create a new version even if a skipped key is added' do
|
124
124
|
l = Landmark.create(:title => 'title')
|
125
125
|
l.update_attributes(:title => 'new title', :depth => 1)
|
126
126
|
l = l.reload
|
127
|
-
l.version.
|
128
|
-
l.versions.size.
|
127
|
+
expect(l.version).to eq 2
|
128
|
+
expect(l.versions.size).to eq 2
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'should remember skipped keys through versions' do
|
132
132
|
l = Landmark.create(:title => 'title')
|
133
133
|
l.update_attributes(:title => 'new title')
|
134
134
|
l = l.reload
|
135
|
-
l.version.
|
136
|
-
l.versions.size.
|
135
|
+
expect(l.version).to eq 2
|
136
|
+
expect(l.versions.size).to eq 2
|
137
137
|
|
138
138
|
l.update_attributes(:depth => 1)
|
139
139
|
l = l.reload
|
140
|
-
l.version.
|
141
|
-
l.versions.size.
|
142
|
-
l.depth.
|
143
|
-
l.title.
|
140
|
+
expect(l.version).to eq 2
|
141
|
+
expect(l.versions.size).to eq 2
|
142
|
+
expect(l.depth).to eq 1
|
143
|
+
expect(l.title).to eq 'new title'
|
144
144
|
|
145
145
|
l.revert_to!(1)
|
146
146
|
l = l.reload
|
147
|
-
l.version.
|
148
|
-
l.versions.size.
|
149
|
-
l.depth.
|
150
|
-
l.title.
|
147
|
+
expect(l.version).to eq 1
|
148
|
+
expect(l.versions.size).to eq 2
|
149
|
+
expect(l.depth).to eq 1
|
150
|
+
expect(l.title).to eq 'title'
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'should store changes in a hash' do
|
154
154
|
l = Landmark.create(:title => 'title')
|
155
|
-
l.document_version(1).modified.
|
155
|
+
expect(l.document_version(1).modified).to eq({'title' => 'title'})
|
156
156
|
|
157
157
|
l.update_attributes(:title => 'changed title', :depth => 1)
|
158
|
-
l.reload.document_version(2).modified.
|
158
|
+
expect(l.reload.document_version(2).modified).to eq({'title' => 'changed title'})
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'should save when a version was created' do
|
162
162
|
l = Landmark.create(:title => 'title')
|
163
|
-
l.document_version(1).created_at.
|
163
|
+
expect(l.document_version(1).created_at).to be_instance_of(Time)
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'should save a versioned class with sci' do
|
167
167
|
s = Sublandmark.create!(:title => 'first title')
|
168
|
-
s.new_record
|
169
|
-
s.version.
|
168
|
+
expect(s.new_record?).to be_falsy
|
169
|
+
expect(s.version).to eq 1
|
170
170
|
|
171
|
-
s.versions.size.
|
172
|
-
s.versions.first.
|
173
|
-
s.versions.first.entity_type.
|
171
|
+
expect(s.versions.size).to eq 1
|
172
|
+
expect(s.versions.first).to be_a(MongoMapper::Acts::Versioned::DocumentVersion)
|
173
|
+
expect(s.versions.first.entity_type).to eq "Sublandmark"
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'should rollback with sci' do
|
@@ -181,14 +181,14 @@ describe MongoMapper::Acts::Versioned do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
l = l.reload
|
184
|
-
l.version.
|
185
|
-
l.versions.size.
|
186
|
-
l.title.
|
187
|
-
l.revert_to!(3).
|
184
|
+
expect(l.version).to eq 5
|
185
|
+
expect(l.versions.size).to eq 5
|
186
|
+
expect(l.title).to eq 'other title5'
|
187
|
+
expect(l.revert_to!(3)).to be_truthy
|
188
188
|
l = l.reload
|
189
|
-
l.version.
|
190
|
-
l.versions.size.
|
191
|
-
l.title.
|
189
|
+
expect(l.version).to eq 3
|
190
|
+
expect(l.versions.size).to eq 5
|
191
|
+
expect(l.title).to eq 'other title3'
|
192
192
|
|
193
193
|
s = Sublandmark.create(:title => 'title')
|
194
194
|
(2..5).each do |i|
|
@@ -197,15 +197,15 @@ describe MongoMapper::Acts::Versioned do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
s = s.reload
|
200
|
-
s.versions.
|
201
|
-
s.version.
|
202
|
-
s.versions.size.
|
203
|
-
s.title.
|
204
|
-
s.revert_to!(3).
|
200
|
+
expect(s.versions).not_to eq l.versions
|
201
|
+
expect(s.version).to eq 5
|
202
|
+
expect(s.versions.size).to eq 5
|
203
|
+
expect(s.title).to eq 'title5'
|
204
|
+
expect(s.revert_to!(3)).to be_truthy
|
205
205
|
s = s.reload
|
206
|
-
s.version.
|
207
|
-
s.versions.size.
|
208
|
-
s.title.
|
206
|
+
expect(s.version).to eq 3
|
207
|
+
expect(s.versions.size).to eq 5
|
208
|
+
expect(s.title).to eq 'title3'
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
@@ -229,10 +229,10 @@ describe MongoMapper::Acts::Versioned do
|
|
229
229
|
it 'should version only the subclass' do
|
230
230
|
page = Page.create(:title => 'page title')
|
231
231
|
post = Post.create(:title => 'post title')
|
232
|
-
page.version.
|
233
|
-
page.versions.size.
|
234
|
-
post.version.
|
235
|
-
post.versions.size.
|
232
|
+
expect(page.version).to eq 1
|
233
|
+
expect(page.versions.size).to eq 1
|
234
|
+
expect(post.version).to eq 1
|
235
|
+
expect(post.versions.size).to eq 1
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
require 'mongo_mapper'
|
2
|
-
require 'mongo_mapper/version'
|
3
|
-
puts MongoMapper::Version
|
4
2
|
require 'rspec'
|
5
3
|
require File.expand_path('../../lib/acts_as_versioned', __FILE__)
|
6
4
|
|
7
5
|
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
|
8
6
|
MongoMapper.database = 'test'
|
9
|
-
MongoMapper.database.collections.each
|
7
|
+
MongoMapper.database.collections.each(&:drop_indexes)
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
collection.drop_indexes
|
16
|
-
end
|
9
|
+
def remove_collections
|
10
|
+
MongoMapper.database.collections.each do |collection|
|
11
|
+
collection.remove unless collection.name =~ /(.*\.)?system\..*/
|
12
|
+
collection.drop_indexes
|
17
13
|
end
|
18
14
|
end
|
15
|
+
remove_collections
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.after(:each) { remove_collections }
|
19
|
+
end
|
metadata
CHANGED