Skip to content

Commit

Permalink
fixed the problem where if_changed only triggered if all listed colum…
Browse files Browse the repository at this point in the history
…ns were changed
  • Loading branch information
pelle committed Jun 23, 2008
1 parent 36b0783 commit 50e6282
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/acts_as_versioned.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def save_without_revision!
end

def altered?
track_altered_attributes ? (version_if_changed.map(&:to_s) - changed).length == 0 : changed?
track_altered_attributes ? (version_if_changed.map(&:to_s) - changed).length < version_if_changed.length : changed?
end

# Clones a model. Used when saving a new version or reverting a model's version.
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/landmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ washington:
name: Washington, D.C.
latitude: 38.895
longitude: -77.036667
doesnt_trigger_version: This is not important
version: 1
2 changes: 2 additions & 0 deletions test/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
t.column :name, :string
t.column :latitude, :float
t.column :longitude, :float
t.column :doesnt_trigger_version,:string
t.column :version, :integer
end

Expand All @@ -63,6 +64,7 @@
t.column :name, :string
t.column :latitude, :float
t.column :longitude, :float
t.column :doesnt_trigger_version,:string
t.column :version, :integer
end
end
21 changes: 21 additions & 0 deletions test/versioned_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,25 @@ def test_should_find_next_version
def test_should_find_version_count
assert_equal 2, pages(:welcome).versions.size
end

def test_if_changed_creates_version_if_a_listed_column_is_changed
landmarks(:washington).name="Washington"
assert landmarks(:washington).changed?
assert landmarks(:washington).altered?
end

def test_if_changed_creates_version_if_all_listed_columns_are_changed
landmarks(:washington).name="Washington"
landmarks(:washington).latitude=1.0
landmarks(:washington).longitude=1.0
assert landmarks(:washington).changed?
assert landmarks(:washington).altered?
end

def test_if_changed_does_not_create_new_version_if_unlisted_column_is_changed
landmarks(:washington).doesnt_trigger_version="This should not trigger version"
assert landmarks(:washington).changed?
assert !landmarks(:washington).altered?
end

end

0 comments on commit 50e6282

Please sign in to comment.