Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Modified acts_as_versioned to work with ActiveRecord's dirty attribut…

…e checking.
  • Loading branch information...
commit bec7502c17b7fd969f6ef0e4e8aec5c00fe66b96 1 parent 70e8ad4
Asa Calow asacalow authored

Showing 2 changed files with 9 additions and 10 deletions. Show diff stats Hide diff stats

  1. +1 1  lib/acts_as_versioned.rb
  2. +8 9 test/versioned_test.rb
2  lib/acts_as_versioned.rb
@@ -355,7 +355,7 @@ def versioned_attributes
355 355 end
356 356
357 357 def altered?
358   - self.track_altered_attributes ? (self.version_if_changed.map(&:to_s) - changed).length > 0 : changed?
  358 + self.track_altered_attributes ? (self.version_if_changed.map(&:to_s) - changed).length == 0 : changed?
359 359 end
360 360
361 361 # Clones a model. Used when saving a new version or reverting a model's version.
17 test/versioned_test.rb
@@ -187,7 +187,10 @@ def test_version_no_limit
187 187 p.save
188 188 p.save
189 189 5.times do |i|
190   - assert_page_title p, i
  190 + p.title = "title#{i}"
  191 + p.save
  192 + assert_equal "title#{i}", p.title
  193 + assert_equal (i+2), p.version
191 194 end
192 195 end
193 196
@@ -196,7 +199,10 @@ def test_version_max_limit
196 199 p.update_attributes(:title => "title1")
197 200 p.update_attributes(:title => "title2")
198 201 5.times do |i|
199   - assert_page_title p, i, :lock_version
  202 + p.title = "title#{i}"
  203 + p.save
  204 + assert_equal "title#{i}", p.title
  205 + assert_equal (i+4), p.lock_version
200 206 assert p.versions(true).size <= 2, "locked version can only store 2 versions"
201 207 end
202 208 end
@@ -236,13 +242,6 @@ def test_track_altered_attributes
236 242 assert_equal 2, p.versions(true).size # version 1 deleted
237 243 end
238 244
239   - def assert_page_title(p, i, version_field = :version)
240   - p.title = "title#{i}"
241   - p.save
242   - assert_equal "title#{i}", p.title
243   - assert_equal (i+4), p.send(version_field)
244   - end
245   -
246 245 def test_find_versions
247 246 assert_equal 2, locked_pages(:welcome).versions.size
248 247 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.