1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed after_initialize callbacks call on AR model #dup

This commit is contained in:
Bogdan Gusiev 2012-01-07 11:11:04 +02:00
parent 686f94e768
commit 30468f58a7
3 changed files with 14 additions and 1 deletions

View file

@ -210,7 +210,7 @@ module ActiveRecord
@attributes = cloned_attributes
_run_after_initialize_callbacks if respond_to?(:_run_after_initialize_callbacks)
_run_initialize_callbacks if _initialize_callbacks.any?
@changed_attributes = {}
self.class.column_defaults.each do |attr, orig_value|

View file

@ -99,5 +99,13 @@ module ActiveRecord
assert_not_nil new_topic.created_at
end
def test_dup_after_initialize_callbacks
topic = Topic.new
assert Topic.after_initialize_called
Topic.after_initialize_called = false
topic.dup
assert Topic.after_initialize_called
end
end
end

View file

@ -80,6 +80,11 @@ class Topic < ActiveRecord::Base
after_initialize :set_email_address
class_attribute :after_initialize_called
after_initialize do
self.class.after_initialize_called = true
end
def approved=(val)
@custom_approved = val
write_attribute(:approved, val)