Skip to content

Commit

Permalink
restore behavior of touch for models without :updated_xx [#5439 state…
Browse files Browse the repository at this point in the history
…:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
tnp authored and josevalim committed Sep 24, 2010
1 parent 8d30193 commit 55b6fa9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 2 additions & 3 deletions activerecord/lib/active_record/persistence.rb
Expand Up @@ -222,9 +222,8 @@ def reload(options = nil)
# @brake.touch # @brake.touch
def touch(name = nil) def touch(name = nil)
attributes = timestamp_attributes_for_update_in_model attributes = timestamp_attributes_for_update_in_model
unless attributes.blank? attributes << name if name
attributes << name if name unless attributes.empty?

current_time = current_time_from_proper_timezone current_time = current_time_from_proper_timezone
changes = {} changes = {}


Expand Down
18 changes: 13 additions & 5 deletions activerecord/test/cases/timestamp_test.rb
Expand Up @@ -4,14 +4,14 @@
require 'models/pet' require 'models/pet'
require 'models/toy' require 'models/toy'
require 'models/car' require 'models/car'
require 'models/task'


class TimestampTest < ActiveRecord::TestCase class TimestampTest < ActiveRecord::TestCase
fixtures :developers, :owners, :pets, :toys, :cars fixtures :developers, :owners, :pets, :toys, :cars, :tasks


def setup def setup
@developer = Developer.first @developer = Developer.first
@previously_updated_at = @developer.updated_at @previously_updated_at = @developer.updated_at
@car = Car.first
end end


def test_saving_a_changed_record_updates_its_timestamp def test_saving_a_changed_record_updates_its_timestamp
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_saving_when_record_timestamps_is_false_doesnt_update_its_timestamp
Developer.record_timestamps = true Developer.record_timestamps = true
end end


def test_touching_a_different_attribute def test_touching_an_attribute_updates_timestamp
previously_created_at = @developer.created_at previously_created_at = @developer.created_at
@developer.touch(:created_at) @developer.touch(:created_at)


Expand All @@ -60,8 +60,16 @@ def test_touching_a_different_attribute
assert_not_equal @previously_updated_at, @developer.updated_at assert_not_equal @previously_updated_at, @developer.updated_at
end end


def test_touch_a_record_without_timestamps def test_touching_an_attribute_updates_it
assert_nothing_raised { @car.touch } task = Task.first
previous_value = task.ending
task.touch(:ending)
assert_not_equal previous_value, task.ending
assert_in_delta Time.now, task.ending, 1
end

def test_touching_a_record_without_timestamps_is_unexceptional
assert_nothing_raised { Car.first.touch }
end end


def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
Expand Down

0 comments on commit 55b6fa9

Please sign in to comment.