Permalink
Browse files

Fixed after_initialize callbacks call on AR model #dup

  • Loading branch information...
1 parent 686f94e commit 30468f58a7bd36143daddc64ac23f86684c1de16 @bogdan bogdan committed Jan 7, 2012
View
2 activerecord/lib/active_record/core.rb
@@ -210,7 +210,7 @@ def initialize_dup(other)
@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
8 activerecord/test/cases/dup_test.rb
@@ -99,5 +99,13 @@ def test_dup_timestamps_are_cleared
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
5 activerecord/test/models/topic.rb
@@ -80,6 +80,11 @@ def topic_id
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)

0 comments on commit 30468f5

Please sign in to comment.