acts_as_versionable 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -1
- data/README.rdoc +1 -0
- data/lib/acts_as_versionable/version.rb +1 -1
- data/lib/acts_as_versionable.rb +9 -3
- data/test/acts_as_versionable_test.rb +14 -0
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
data/lib/acts_as_versionable.rb
CHANGED
@@ -34,6 +34,12 @@ module ActsAsVersionable
|
|
34
34
|
def actual_columns
|
35
35
|
columns.reject { |c| REJECT_COLUMNS.include?(c.name) }
|
36
36
|
end
|
37
|
+
|
38
|
+
def get_version(version)
|
39
|
+
revision = self.find_by_versioned_as(version)
|
40
|
+
raise NoSuchVersionError, "Couldn't find #{version} version" if revision.blank?
|
41
|
+
revision
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
include InstanceMethods
|
@@ -48,7 +54,7 @@ module ActsAsVersionable
|
|
48
54
|
end
|
49
55
|
|
50
56
|
def revert_to(version)
|
51
|
-
revision = get_version(version)
|
57
|
+
revision = versions.get_version(version)
|
52
58
|
|
53
59
|
move_columns revision, self
|
54
60
|
|
@@ -58,7 +64,7 @@ module ActsAsVersionable
|
|
58
64
|
end
|
59
65
|
|
60
66
|
def new_from_version(version)
|
61
|
-
revision = get_version(version)
|
67
|
+
revision = versions.get_version(version)
|
62
68
|
dummy = self.class.new
|
63
69
|
|
64
70
|
move_columns revision, dummy
|
@@ -68,7 +74,7 @@ module ActsAsVersionable
|
|
68
74
|
|
69
75
|
private
|
70
76
|
|
71
|
-
def
|
77
|
+
def _get_version(version)
|
72
78
|
revision = versions.find_by_versioned_as(version)
|
73
79
|
raise NoSuchVersionError, "Couldn't find #{version} version" if revision.blank?
|
74
80
|
revision
|
@@ -113,6 +113,20 @@ class VersionableTest < Test::Unit::TestCase
|
|
113
113
|
assert_equal dummy.body, article.body
|
114
114
|
end
|
115
115
|
|
116
|
+
def test_get_version
|
117
|
+
article = Article.first
|
118
|
+
assert_not_nil article
|
119
|
+
|
120
|
+
article.update_attributes(:title => '5', :body => '5')
|
121
|
+
assert_equal 2, article.versions.count
|
122
|
+
|
123
|
+
first = article.versions[1]
|
124
|
+
one = article.versions.get_version(2)
|
125
|
+
|
126
|
+
assert_equal first.title, one.title
|
127
|
+
assert_equal first.body, one.body
|
128
|
+
end
|
129
|
+
|
116
130
|
def test_dependent_destroy
|
117
131
|
Article.destroy_all
|
118
132
|
assert_equal [], ArticleVersions.all
|