Skip to content

Commit

Permalink
Don't halt save when checking for new version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmckible committed May 4, 2008
1 parent c17e38d commit 367c986
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/version_fu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ def find_version(number)

def check_for_new_version
instatiate_revision if create_new_version?
true # Never halt save
end

# This the method to override if you want to have more control over when to version
def create_new_version?
any_versioned_column_changed?
end

def any_versioned_column_changed?
# Any versioned column changed?
self.class.versioned_columns.detect {|a| __send__ "#{a}_changed?"}
end

Expand Down
9 changes: 7 additions & 2 deletions test/version_fu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,17 @@ def test_do_not_create_version_if_untracked_attribute_changed
pages(:welcome).update_attributes :author=>authors(:sara)
assert_equal old_count, Page::Version.count
end

def test_allow_version_checking_override
def test_do_not_create_version_if_custom_version_check
old_count = Author::Version.count
authors(:larry).update_attributes :last_name=>'Lessig'
assert_equal old_count, Author::Version.count
end

def test_still_save_if_no_new_version_with_custom_version_check
authors(:larry).update_attributes :last_name=>'Lessig'
assert_equal 'Lessig', authors(:larry).reload.last_name
end

#############################################################################
# F I N D #
Expand Down

0 comments on commit 367c986

Please sign in to comment.