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 c81a78d commit 70e8ad4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 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) - self.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
19 changes: 11 additions & 8 deletions test/versioned_test.rb
Expand Up @@ -184,11 +184,10 @@ def test_version_if_condition_with_block

def test_version_no_limit
p = Page.create! :title => "title", :body => 'first body'
p.save
p.save
5.times do |i|
p.title = "title#{i}"
p.save
assert_equal "title#{i}", p.title
assert_equal i+2, p.version
assert_page_title p, i
end
end

Expand All @@ -197,10 +196,7 @@ def test_version_max_limit
p.update_attributes(:title => "title1")
p.update_attributes(:title => "title2")
5.times do |i|
p.title = "title#{i}"
p.save
assert_equal "title#{i}", p.title
assert_equal (i+4), p.send(:lock_version)
assert_page_title p, i, :lock_version
assert p.versions(true).size <= 2, "locked version can only store 2 versions"
end
end
Expand Down Expand Up @@ -240,6 +236,13 @@ 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 70e8ad4

Please sign in to comment.