diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-01-03 23:42:59 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-01-04 11:58:43 -0300 |
commit | 634ecdbf1b6401ded0e145b1e7c7f4808ad89398 (patch) | |
tree | 11a8fcd4f0dd1b9b9d49165ac36f7f8ba640f69b /activerecord/test | |
parent | 82043ab53cb186d59b1b3be06122861758f814b2 (diff) | |
download | rails-634ecdbf1b6401ded0e145b1e7c7f4808ad89398.tar.gz rails-634ecdbf1b6401ded0e145b1e7c7f4808ad89398.tar.bz2 rails-634ecdbf1b6401ded0e145b1e7c7f4808ad89398.zip |
Return a null column from `column_for_attribute` when no column exists.
This reverts commit ae96f229f6501d8635811d6b22d75d43cdb880a4.
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/attribute_methods.rb
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/reflection_test.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index e86b892a0a..a2252a836f 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -80,10 +80,24 @@ class ReflectionTest < ActiveRecord::TestCase assert_equal :integer, @first.column_for_attribute("id").type end - def test_non_existent_columns_return_nil - assert_deprecated do - assert_nil @first.column_for_attribute("attribute_that_doesnt_exist") - end + def test_non_existent_columns_return_null_object + column = @first.column_for_attribute("attribute_that_doesnt_exist") + assert_instance_of ActiveRecord::ConnectionAdapters::NullColumn, column + assert_equal "attribute_that_doesnt_exist", column.name + assert_equal nil, column.sql_type + assert_equal nil, column.type + assert_not column.number? + assert_not column.text? + assert_not column.binary? + end + + def test_non_existent_columns_are_identity_types + column = @first.column_for_attribute("attribute_that_doesnt_exist") + object = Object.new + + assert_equal object, column.type_cast_from_database(object) + assert_equal object, column.type_cast_from_user(object) + assert_equal object, column.type_cast_for_database(object) end def test_reflection_klass_for_nested_class_name |