diff options
author | Vokhmin Alexey V <avokhmin@gmail.com> | 2015-12-03 21:18:57 +0300 |
---|---|---|
committer | Vokhmin Alexey V <avokhmin@gmail.com> | 2015-12-14 19:02:20 +0300 |
commit | 61e50814040d68c640b16afd2b9c419d2f12fad6 (patch) | |
tree | ac4d6a8ec0694b968670fc5d872a6b258f0410b3 /activerecord/test | |
parent | 574f255629a45cd67babcfb9bb8e163e091a53b8 (diff) | |
download | rails-61e50814040d68c640b16afd2b9c419d2f12fad6.tar.gz rails-61e50814040d68c640b16afd2b9c419d2f12fad6.tar.bz2 rails-61e50814040d68c640b16afd2b9c419d2f12fad6.zip |
`ActiveRecord::Base#becomes` should copy the errors
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index b2e59e3970..af15e63d9c 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -19,6 +19,8 @@ require 'models/person' require 'models/pet' require 'models/ship' require 'models/toy' +require 'models/admin' +require 'models/admin/user' require 'rexml/document' class PersistenceTest < ActiveRecord::TestCase @@ -161,7 +163,24 @@ class PersistenceTest < ActiveRecord::TestCase assert !company.valid? original_errors = company.errors client = company.becomes(Client) - assert_equal original_errors, client.errors + assert_equal original_errors.keys, client.errors.keys + end + + def test_becomes_errors_base + child_class = Class.new(Admin::User) do + store_accessor :settings, :foo + + def self.name; 'Admin::ChildUser'; end + end + + admin = Admin::User.new + admin.errors.add :token, :invalid + child = admin.becomes(child_class) + + assert_equal [:token], child.errors.keys + assert_nothing_raised do + child.errors.add :foo, :invalid + end end def test_dupd_becomes_persists_changes_from_the_original |