Permalink
Browse files

Merge pull request #4376 from bogdan/after_initialize_on_dup

Fixed after_initialize callbacks call on AR model #dup
  • Loading branch information...
josevalim committed Jan 7, 2012
2 parents b5dceaf + 30468f5 commit ef023ce1d88691461a03fb90f0b8bff94d9fa4e1
@@ -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|
@@ -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
@@ -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 ef023ce

Please sign in to comment.