mongo_mapper_versioned 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
  module MongoMapper
3
3
  module Plugins
4
4
  module Versioned
5
- Version = '0.1'
5
+ Version = '0.1.1'
6
6
  end
7
7
  end
8
8
  end
@@ -24,7 +24,7 @@ module MongoMapper
24
24
  module InstanceMethods
25
25
 
26
26
  def create_version
27
- self.version_number = version_count + 1 if (version_count > 0)
27
+ self.version_number = versions.last.version_number+1 if versions.count > 0
28
28
  self.versions << current_version
29
29
  end
30
30
 
@@ -34,9 +34,10 @@ module MongoMapper
34
34
  self.version_number = target_version.version_number
35
35
  end
36
36
  end
37
-
38
- def version_count
39
- self.versions.count
37
+
38
+ def latest_version?
39
+ return true if versions.empty?
40
+ self.version_number == versions.last.version_number
40
41
  end
41
42
 
42
43
  def current_version
@@ -27,7 +27,10 @@ class VersionedTest < ActiveSupport::TestCase
27
27
  assert_equal 1, @doc.version_number
28
28
  end
29
29
  should "have 0 versions" do
30
- assert_equal 0, @doc.version_count
30
+ assert_equal 0, @doc.versions.count
31
+ end
32
+ should "be latest version" do
33
+ assert @doc.latest_version?
31
34
  end
32
35
  end
33
36
 
@@ -39,12 +42,15 @@ class VersionedTest < ActiveSupport::TestCase
39
42
  assert_equal 1, @doc.version_number
40
43
  end
41
44
  should "have 1 (initial) version" do
42
- assert_equal 1, @doc.version_count
45
+ assert_equal 1, @doc.versions.count
46
+ end
47
+ should "be latest version" do
48
+ assert @doc.latest_version?
43
49
  end
44
50
 
45
51
  context "when saved with no changes" do
46
52
  setup do
47
- @version_count = @doc.version_count
53
+ @version_count = @doc.versions.count
48
54
  @version_number = @doc.version_number
49
55
  @doc.save
50
56
  end
@@ -52,23 +58,29 @@ class VersionedTest < ActiveSupport::TestCase
52
58
  assert_equal @version_number, @doc.version_number
53
59
  end
54
60
  should "not create new version" do
55
- assert_equal @version_count, @doc.version_count
61
+ assert_equal @version_count, @doc.versions.count
62
+ end
63
+ should "be latest version" do
64
+ assert @doc.latest_version?
56
65
  end
57
66
  end
58
67
 
59
68
  context "after a change" do
60
69
  setup do
61
- @version_count = @doc.version_count
70
+ @version_count = @doc.versions.count
62
71
  @version_number = @doc.version_number
63
72
  @title = @doc.title
64
73
  @doc.update_attributes(:title => "Krabaty")
65
74
  end
66
75
  should "increase number of versions" do
67
- assert_equal @version_count+1, @doc.version_count
76
+ assert_equal @version_count+1, @doc.versions.count
68
77
  end
69
78
  should "increase version number" do
70
79
  assert_equal @version_number+1, @doc.version_number
71
80
  end
81
+ should "be latest version" do
82
+ assert @doc.latest_version?
83
+ end
72
84
  end
73
85
 
74
86
  end
@@ -96,7 +108,10 @@ class VersionedTest < ActiveSupport::TestCase
96
108
  assert_equal "Arnett", @doc.body
97
109
  end
98
110
  should "not create new version" do
99
- assert_equal 5, @doc.version_count
111
+ assert_equal 5, @doc.versions.count
112
+ end
113
+ should "not be latest version" do
114
+ assert !@doc.latest_version?
100
115
  end
101
116
  end
102
117
 
@@ -114,7 +129,10 @@ class VersionedTest < ActiveSupport::TestCase
114
129
  assert_equal "Arnett", @doc.body
115
130
  end
116
131
  should "not create new version" do
117
- assert_equal 5, @doc.version_count
132
+ assert_equal 5, @doc.versions.count
133
+ end
134
+ should "not be latest version" do
135
+ assert !@doc.latest_version?
118
136
  end
119
137
  context "after save" do
120
138
  setup do
@@ -124,7 +142,10 @@ class VersionedTest < ActiveSupport::TestCase
124
142
  assert_equal 6, @doc.version_number
125
143
  end
126
144
  should "have 6 versions" do
127
- assert_equal 6, @doc.version_count
145
+ assert_equal 6, @doc.versions.count
146
+ end
147
+ should "be latest version" do
148
+ assert @doc.latest_version?
128
149
  end
129
150
  end
130
151
 
@@ -144,7 +165,7 @@ class VersionedTest < ActiveSupport::TestCase
144
165
  assert_equal "Arnett", @doc.body
145
166
  end
146
167
  should "not create new version" do
147
- assert_equal 5, @doc.version_count
168
+ assert_equal 5, @doc.versions.count
148
169
  end
149
170
  end
150
171
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper_versioned
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- version: "0.1"
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Tomas Celizna
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-12-22 00:00:00 +01:00
18
+ date: 2010-12-24 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency