Permalink
Browse files

Merge pull request #3438 from lazyatom/becomes-includes-errors

Becomes includes errors
  • Loading branch information...
2 parents a152fd3 + 73cb0f9 commit 540e929d75616feab3dc456b7a6bd616909d9684 @jonleighton jonleighton committed Nov 16, 2011
Showing with 9 additions and 0 deletions.
  1. +1 −0 activerecord/lib/active_record/persistence.rb
  2. +8 −0 activerecord/test/cases/base_test.rb
@@ -114,6 +114,7 @@ def becomes(klass)
became.instance_variable_set("@attributes_cache", @attributes_cache)
became.instance_variable_set("@new_record", new_record?)
became.instance_variable_set("@destroyed", destroyed?)
+ became.instance_variable_set("@errors", errors)
became.type = klass.name unless self.class.descends_from_active_record?
became
end
@@ -1761,6 +1761,14 @@ def test_becomes
assert_equal "The First Topic", topics(:first).becomes(Reply).title
end
+ def test_becomes_includes_errors
+ company = Company.new(:name => nil)
+ assert !company.valid?
+ original_errors = company.errors
+ client = company.becomes(Client)
+ assert_equal original_errors, client.errors
+ end
+
def test_silence_sets_log_level_to_error_in_block
original_logger = ActiveRecord::Base.logger
log = StringIO.new

0 comments on commit 540e929

Please sign in to comment.