Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Becomes includes errors
  • Loading branch information...
commit 540e929d75616feab3dc456b7a6bd616909d9684 2 parents a152fd3 + 73cb0f9
@jonleighton jonleighton authored
View
1  activerecord/lib/active_record/persistence.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
View
8 activerecord/test/cases/base_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.