mm-versionable 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/versionable/plugins/versionable.rb +17 -2
- data/lib/versionable/version.rb +1 -1
- data/test/unit/test_versioning.rb +25 -0
- metadata +4 -4
@@ -10,7 +10,8 @@ module Versionable
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def save(options={})
|
13
|
-
|
13
|
+
updater_id = options.delete(:updater_id)
|
14
|
+
save_version(updater_id) if self.respond_to?(:rolling_back) && !rolling_back
|
14
15
|
super
|
15
16
|
end
|
16
17
|
|
@@ -67,6 +68,21 @@ module Versionable
|
|
67
68
|
Version.where(:doc_id => self._id.to_s).sort(:pos.desc)
|
68
69
|
end
|
69
70
|
|
71
|
+
define_method(:delete_version) do |pos|
|
72
|
+
case pos
|
73
|
+
when :all
|
74
|
+
@versions_count = 0
|
75
|
+
self.all_versions.each(&:delete)
|
76
|
+
else
|
77
|
+
@versions_count -= 1
|
78
|
+
self.version_at(pos).delete
|
79
|
+
# resetting position of all versions after the one at pos
|
80
|
+
self.all_versions.where(['pos > ?', pos]).each do |version|
|
81
|
+
version.update_attributes(:pos => version.pos - 1)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
70
86
|
define_method(:rollback) do |*args|
|
71
87
|
pos = args.first #workaround for optional args in ruby1.8
|
72
88
|
#The last version is always same as the current version, so -2 instead of -1
|
@@ -132,4 +148,3 @@ module Versionable
|
|
132
148
|
end
|
133
149
|
end
|
134
150
|
end
|
135
|
-
|
data/lib/versionable/version.rb
CHANGED
@@ -38,6 +38,9 @@ class VersioningTest < Test::Unit::TestCase
|
|
38
38
|
should 'respond to method save_version' do
|
39
39
|
assert @user.respond_to?(:save_version)
|
40
40
|
end
|
41
|
+
should 'respond to method delete_version' do
|
42
|
+
assert @user.respond_to?(:delete_version)
|
43
|
+
end
|
41
44
|
end
|
42
45
|
|
43
46
|
context 'Version manipulations' do
|
@@ -115,6 +118,28 @@ class VersioningTest < Test::Unit::TestCase
|
|
115
118
|
end
|
116
119
|
end
|
117
120
|
|
121
|
+
context 'deleting versions' do
|
122
|
+
setup do
|
123
|
+
@user = User.create :fname => 'Dhruva', :lname => 'Sagar'
|
124
|
+
@user.posts << Post.new(:title => 'New', :body => 'Test', :date => Time.now)
|
125
|
+
@user.save
|
126
|
+
end
|
127
|
+
should "delete all versions on calling delete_version with :all as argument" do
|
128
|
+
@user.delete_version(:all)
|
129
|
+
assert @user.versions_count == 0
|
130
|
+
assert @user.all_versions.count == 0
|
131
|
+
end
|
132
|
+
should "delete specific version on calling delete_version with position index as argument and reset position of all subsequent versions" do
|
133
|
+
versions_count = @user.versions_count
|
134
|
+
@user.delete_version(:first)
|
135
|
+
assert_equal @user.version_at(:first).pos, 0
|
136
|
+
assert_equal versions_count, (@user.versions_count + 1)
|
137
|
+
end
|
138
|
+
teardown do
|
139
|
+
@user.delete
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
118
143
|
context 'Versioning with update_attributes' do
|
119
144
|
setup do
|
120
145
|
@user = User.first
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm-versionable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -174,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
segments:
|
176
176
|
- 0
|
177
|
-
hash:
|
177
|
+
hash: -2921783502865972979
|
178
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
179
|
none: false
|
180
180
|
requirements:
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
segments:
|
185
185
|
- 0
|
186
|
-
hash:
|
186
|
+
hash: -2921783502865972979
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
189
|
rubygems_version: 1.8.21
|