mongo_mapper_versioned 0.1.2 → 0.1.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.
@@ -36,10 +36,14 @@ module MongoMapper
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def last_version?
|
40
40
|
return true if versions.empty?
|
41
41
|
self.version_number == versions.last.version_number
|
42
42
|
end
|
43
|
+
|
44
|
+
def previous_version
|
45
|
+
Version.where(:versioned_id => self.id, :version_number => self.version_number-1).first
|
46
|
+
end
|
43
47
|
|
44
48
|
def current_version
|
45
49
|
Version.new(:data => self.attributes.slice!(*ignored_keys), :versioned_id => self.id, :version_number => self.version_number)
|
@@ -29,8 +29,11 @@ class VersionedTest < ActiveSupport::TestCase
|
|
29
29
|
should "have 0 versions" do
|
30
30
|
assert_equal 0, @doc.versions.count
|
31
31
|
end
|
32
|
-
should "be
|
33
|
-
assert @doc.
|
32
|
+
should "be last version" do
|
33
|
+
assert @doc.last_version?
|
34
|
+
end
|
35
|
+
should "have no previous version" do
|
36
|
+
assert_nil @doc.previous_version
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
@@ -44,8 +47,11 @@ class VersionedTest < ActiveSupport::TestCase
|
|
44
47
|
should "have 1 (initial) version" do
|
45
48
|
assert_equal 1, @doc.versions.count
|
46
49
|
end
|
47
|
-
should "be
|
48
|
-
assert @doc.
|
50
|
+
should "be last version" do
|
51
|
+
assert @doc.last_version?
|
52
|
+
end
|
53
|
+
should "have no previous version" do
|
54
|
+
assert_nil @doc.previous_version
|
49
55
|
end
|
50
56
|
|
51
57
|
context "when saved with no changes" do
|
@@ -60,8 +66,11 @@ class VersionedTest < ActiveSupport::TestCase
|
|
60
66
|
should "not create new version" do
|
61
67
|
assert_equal @version_count, @doc.versions.count
|
62
68
|
end
|
63
|
-
should "be
|
64
|
-
assert @doc.
|
69
|
+
should "be last version" do
|
70
|
+
assert @doc.last_version?
|
71
|
+
end
|
72
|
+
should "have no previous version" do
|
73
|
+
assert_nil @doc.previous_version
|
65
74
|
end
|
66
75
|
end
|
67
76
|
|
@@ -78,8 +87,11 @@ class VersionedTest < ActiveSupport::TestCase
|
|
78
87
|
should "increase version number" do
|
79
88
|
assert_equal @version_number+1, @doc.version_number
|
80
89
|
end
|
81
|
-
should "be
|
82
|
-
assert @doc.
|
90
|
+
should "be last version" do
|
91
|
+
assert @doc.last_version?
|
92
|
+
end
|
93
|
+
should "have previous version" do
|
94
|
+
assert_equal @doc.previous_version.version_number, @doc.version_number-1
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
@@ -110,8 +122,8 @@ class VersionedTest < ActiveSupport::TestCase
|
|
110
122
|
should "not create new version" do
|
111
123
|
assert_equal 5, @doc.versions.count
|
112
124
|
end
|
113
|
-
should "not be
|
114
|
-
assert !@doc.
|
125
|
+
should "not be last version" do
|
126
|
+
assert !@doc.last_version?
|
115
127
|
end
|
116
128
|
end
|
117
129
|
|
@@ -131,8 +143,8 @@ class VersionedTest < ActiveSupport::TestCase
|
|
131
143
|
should "not create new version" do
|
132
144
|
assert_equal 5, @doc.versions.count
|
133
145
|
end
|
134
|
-
should "not be
|
135
|
-
assert !@doc.
|
146
|
+
should "not be last version" do
|
147
|
+
assert !@doc.last_version?
|
136
148
|
end
|
137
149
|
context "after save" do
|
138
150
|
setup do
|
@@ -144,8 +156,8 @@ class VersionedTest < ActiveSupport::TestCase
|
|
144
156
|
should "have 6 versions" do
|
145
157
|
assert_equal 6, @doc.versions.count
|
146
158
|
end
|
147
|
-
should "be
|
148
|
-
assert @doc.
|
159
|
+
should "be last version" do
|
160
|
+
assert @doc.last_version?
|
149
161
|
end
|
150
162
|
end
|
151
163
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper_versioned
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tomas Celizna
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-26 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|