Skip to content
This repository
Browse code

restore behavior of touch for models without :updated_xx [#5439 state…

…:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 55b6fa9370dbdac23b0df2bbcb70b2e2d604b410 1 parent 8d30193
tnp authored September 24, 2010 josevalim committed September 24, 2010
5  activerecord/lib/active_record/persistence.rb
@@ -222,9 +222,8 @@ def reload(options = nil)
222 222
     #   @brake.touch
223 223
     def touch(name = nil)
224 224
       attributes = timestamp_attributes_for_update_in_model
225  
-      unless attributes.blank?
226  
-        attributes << name if name
227  
-
  225
+      attributes << name if name
  226
+      unless attributes.empty?
228 227
         current_time = current_time_from_proper_timezone
229 228
         changes = {}
230 229
 
18  activerecord/test/cases/timestamp_test.rb
@@ -4,14 +4,14 @@
4 4
 require 'models/pet'
5 5
 require 'models/toy'
6 6
 require 'models/car'
  7
+require 'models/task'
7 8
 
8 9
 class TimestampTest < ActiveRecord::TestCase
9  
-  fixtures :developers, :owners, :pets, :toys, :cars
  10
+  fixtures :developers, :owners, :pets, :toys, :cars, :tasks
10 11
 
11 12
   def setup
12 13
     @developer = Developer.first
13 14
     @previously_updated_at = @developer.updated_at
14  
-    @car = Car.first
15 15
   end
16 16
 
17 17
   def test_saving_a_changed_record_updates_its_timestamp
@@ -50,7 +50,7 @@ def test_saving_when_record_timestamps_is_false_doesnt_update_its_timestamp
50 50
     Developer.record_timestamps = true
51 51
   end
52 52
 
53  
-  def test_touching_a_different_attribute
  53
+  def test_touching_an_attribute_updates_timestamp
54 54
     previously_created_at = @developer.created_at
55 55
     @developer.touch(:created_at)
56 56
 
@@ -60,8 +60,16 @@ def test_touching_a_different_attribute
60 60
     assert_not_equal @previously_updated_at, @developer.updated_at
61 61
   end
62 62
 
63  
-  def test_touch_a_record_without_timestamps
64  
-    assert_nothing_raised { @car.touch }
  63
+  def test_touching_an_attribute_updates_it
  64
+    task = Task.first
  65
+    previous_value = task.ending
  66
+    task.touch(:ending)
  67
+    assert_not_equal previous_value, task.ending
  68
+    assert_in_delta Time.now, task.ending, 1
  69
+  end
  70
+
  71
+  def test_touching_a_record_without_timestamps_is_unexceptional
  72
+    assert_nothing_raised { Car.first.touch }
65 73
   end
66 74
 
67 75
   def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at

0 notes on commit 55b6fa9

Please sign in to comment.
Something went wrong with that request. Please try again.