Skip to content

Commit

Permalink
Merge pull request #14469 from tiegz/timestamp_inheritance_fix
Browse files Browse the repository at this point in the history
Swap Timestamp/Callbacks order in ActiveRecord::Base
  • Loading branch information
rafaelfranca committed Mar 27, 2014
1 parent 5cf456a commit dd3ea17
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
* Make possible to change `record_timestamps` inside Callbacks.

*Tieg Zaharia*

* Fixed error where .persisted? throws SystemStackError for an unsaved model with a
custom primary key that didn't save due to validation error.

Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -310,8 +310,8 @@ class Base
include Locking::Optimistic
include Locking::Pessimistic
include AttributeMethods
include Callbacks
include Timestamp
include Callbacks
include Associations
include ActiveModel::SecurePassword
include AutosaveAssociation
Expand Down
18 changes: 18 additions & 0 deletions activerecord/test/cases/timestamp_test.rb
Expand Up @@ -71,6 +71,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)
Expand Down

0 comments on commit dd3ea17

Please sign in to comment.