Skip to content
Browse files

Modified acts_as_versioned to work with ActiveRecord's dirty attribut…

…e checking.
  • Loading branch information...
1 parent 70e8ad4 commit bec7502c17b7fd969f6ef0e4e8aec5c00fe66b96 @asacalow asacalow committed May 29, 2008
Showing with 9 additions and 10 deletions.
  1. +1 −1 lib/acts_as_versioned.rb
  2. +8 −9 test/versioned_test.rb
View
2 lib/acts_as_versioned.rb
@@ -355,7 +355,7 @@ def versioned_attributes
end
def altered?
- self.track_altered_attributes ? (self.version_if_changed.map(&:to_s) - changed).length > 0 : changed?
+ self.track_altered_attributes ? (self.version_if_changed.map(&:to_s) - changed).length == 0 : changed?
end
# Clones a model. Used when saving a new version or reverting a model's version.
View
17 test/versioned_test.rb
@@ -187,7 +187,10 @@ def test_version_no_limit
p.save
p.save
5.times do |i|
- assert_page_title p, i
+ p.title = "title#{i}"
+ p.save
+ assert_equal "title#{i}", p.title
+ assert_equal (i+2), p.version
end
end
@@ -196,7 +199,10 @@ def test_version_max_limit
p.update_attributes(:title => "title1")
p.update_attributes(:title => "title2")
5.times do |i|
- assert_page_title p, i, :lock_version
+ p.title = "title#{i}"
+ p.save
+ assert_equal "title#{i}", p.title
+ assert_equal (i+4), p.lock_version
assert p.versions(true).size <= 2, "locked version can only store 2 versions"
end
end
@@ -236,13 +242,6 @@ def test_track_altered_attributes
assert_equal 2, p.versions(true).size # version 1 deleted
end
- def assert_page_title(p, i, version_field = :version)
- p.title = "title#{i}"
- p.save
- assert_equal "title#{i}", p.title
- assert_equal (i+4), p.send(version_field)
- end
-
def test_find_versions
assert_equal 2, locked_pages(:welcome).versions.size
assert_equal 1, locked_pages(:welcome).versions.find(:all, :conditions => ['title LIKE ?', '%weblog%']).length

0 comments on commit bec7502

Please sign in to comment.
Something went wrong with that request. Please try again.