Skip to content

Commit

Permalink
Modified acts_as_versioned to work with ActiveRecord's dirty attribut…
Browse files Browse the repository at this point in the history
…e checking.
  • Loading branch information
asacalow committed May 29, 2008
1 parent 70e8ad4 commit bec7502
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/acts_as_versioned.rb
Expand Up @@ -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.
Expand Down
17 changes: 8 additions & 9 deletions test/versioned_test.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bec7502

Please sign in to comment.