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:
parent
686f94e768
commit
30468f58a7
3 changed files with 14 additions and 1 deletions
|
@ -210,7 +210,7 @@ module ActiveRecord
|
||||||
|
|
||||||
@attributes = cloned_attributes
|
@attributes = cloned_attributes
|
||||||
|
|
||||||
_run_after_initialize_callbacks if respond_to?(:_run_after_initialize_callbacks)
|
_run_initialize_callbacks if _initialize_callbacks.any?
|
||||||
|
|
||||||
@changed_attributes = {}
|
@changed_attributes = {}
|
||||||
self.class.column_defaults.each do |attr, orig_value|
|
self.class.column_defaults.each do |attr, orig_value|
|
||||||
|
|
|
@ -99,5 +99,13 @@ module ActiveRecord
|
||||||
assert_not_nil new_topic.created_at
|
assert_not_nil new_topic.created_at
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,6 +80,11 @@ class Topic < ActiveRecord::Base
|
||||||
|
|
||||||
after_initialize :set_email_address
|
after_initialize :set_email_address
|
||||||
|
|
||||||
|
class_attribute :after_initialize_called
|
||||||
|
after_initialize do
|
||||||
|
self.class.after_initialize_called = true
|
||||||
|
end
|
||||||
|
|
||||||
def approved=(val)
|
def approved=(val)
|
||||||
@custom_approved = val
|
@custom_approved = val
|
||||||
write_attribute(:approved, val)
|
write_attribute(:approved, val)
|
||||||
|
|
Loading…
Reference in a new issue