Permalink
Browse files

dirty tracking bug with after_create callbacks

  • Loading branch information...
1 parent 2596aeb commit 9b2725fc7f51c76fa92f9ba5f975c53eadb03b6e Matt Kimmel & Matt Parker committed Jun 28, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0 activerecord/test/cases/callbacks_test.rb
View
19 activerecord/test/cases/callbacks_test.rb
@@ -47,6 +47,18 @@ class CallbackDeveloperWithFalseValidation < CallbackDeveloper
before_validation proc { |model| model.history << [:before_validation, :should_never_get_here] }
end
+class ModelWithAfterCreateCallbacks < ActiveRecord::Base
+ self.table_name = 'developers'
+
+ NAME = "foo"
+ after_create :set_name
+
+ private
+ def set_name
+ self.name = NAME
+ end
+end
+
class ParentDeveloper < ActiveRecord::Base
self.table_name = 'developers'
attr_accessor :after_save_called
@@ -436,6 +448,13 @@ def test_before_destroy_returning_false
assert !someone.after_destroy_called
end
+ def test_after_create_callbacks_honor_dirty_tracking
+ m = ModelWithAfterCreateCallbacks.create
+ assert_equal m.valid?, true
+ assert_equal ModelWithAfterCreateCallbacks::NAME, m.name
+ assert_equal m.changed_attributes.has_key?("name"), true
+ end
+
def assert_save_callbacks_not_called(someone)
assert !someone.after_save_called
assert !someone.after_create_called

0 comments on commit 9b2725f

Please sign in to comment.