Skip to content
Browse files

Swap Timestamp/Callbacks inheritance in ActiveRecord::Base

Fixes a regression in the lookup chain for update_record &
create_record. Timestamp's methods were being executed before
Callback's.
  • Loading branch information...
1 parent 93ed89d commit 3de4c5627356ed5ebb98abb8720a6fa420e208f2 @tiegz tiegz committed with tiegz
Showing with 19 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/base.rb
  2. +18 −0 activerecord/test/cases/timestamp_test.rb
View
2 activerecord/lib/active_record/base.rb
@@ -305,8 +305,8 @@ class Base
include Locking::Optimistic
include Locking::Pessimistic
include AttributeMethods
- include Callbacks
include Timestamp
+ include Callbacks
include Associations
include ActiveModel::SecurePassword
include AutosaveAssociation
View
18 activerecord/test/cases/timestamp_test.rb
@@ -70,6 +70,24 @@ def test_saving_when_instance_record_timestamps_is_false_doesnt_update_its_times
assert_equal @previously_updated_at, @developer.updated_at
end
+ def test_saving_when_callback_sets_record_timestamps_to_false_doesnt_update_its_timestamp
+ klass = Class.new(Developer) do
+ before_update :cancel_record_timestamps
+ def cancel_record_timestamps
+ self.record_timestamps = false
+ return true
+ end
+ end
+
+ developer = klass.first
+ previously_updated_at = developer.updated_at
+
+ developer.name = "New Name"
+ developer.save!
+
+ assert_equal previously_updated_at, developer.updated_at
+ end
+
def test_touching_an_attribute_updates_timestamp
previously_created_at = @developer.created_at
@developer.touch(:created_at)

0 comments on commit 3de4c56

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