aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/topic.rb
diff options
context:
space:
mode:
authorMike Busch <mbusch@heroku.com>2017-01-23 12:09:14 -0500
committerMike Busch <mbusch@heroku.com>2017-12-22 07:41:33 -0500
commitc53287b2370af2b011cdc4c583a50fbcd6fd88ed (patch)
treedbd665902c1f6ec070f057a8b063923e12b4a2d3 /activerecord/test/models/topic.rb
parent0901755283645be1a59d625deb3471c40d664712 (diff)
downloadrails-c53287b2370af2b011cdc4c583a50fbcd6fd88ed.tar.gz
rails-c53287b2370af2b011cdc4c583a50fbcd6fd88ed.tar.bz2
rails-c53287b2370af2b011cdc4c583a50fbcd6fd88ed.zip
save attributes changed by callbacks after update_attribute
update_attribute previously stopped execution, before saving and before running callbacks, if the record's attributes hadn't changed. [The documentation](http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_attribute) says that "Callbacks are invoked", which was not happening if the persisted attributes hadn't changed.
Diffstat (limited to 'activerecord/test/models/topic.rb')
-rw-r--r--activerecord/test/models/topic.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index 2154b50ef7..8cd4dc352a 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -65,6 +65,9 @@ class Topic < ActiveRecord::Base
after_initialize :set_email_address
+ attr_accessor :change_approved_before_save
+ before_save :change_approved_callback
+
class_attribute :after_initialize_called
after_initialize do
self.class.after_initialize_called = true
@@ -96,6 +99,10 @@ class Topic < ActiveRecord::Base
def before_destroy_for_transaction; end
def after_save_for_transaction; end
def after_create_for_transaction; end
+
+ def change_approved_callback
+ self.approved = change_approved_before_save unless change_approved_before_save.nil?
+ end
end
class ImportantTopic < Topic