diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-03 19:30:34 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-03 19:30:34 -0300 |
commit | 1c6bb0efe0933cf0880c13ac0c379b65781a2353 (patch) | |
tree | 596553b7e8f59247b0ed7c53020a1b6aeaeb1720 /activerecord/test | |
parent | 18d19bf2a418f4e310e7792db6d8600c25f8b1b3 (diff) | |
parent | fb2a1c4b47800d6ed65662bed26fcdae66de5869 (diff) | |
download | rails-1c6bb0efe0933cf0880c13ac0c379b65781a2353.tar.gz rails-1c6bb0efe0933cf0880c13ac0c379b65781a2353.tar.bz2 rails-1c6bb0efe0933cf0880c13ac0c379b65781a2353.zip |
Merge pull request #15438 from sgrif/sg-null-column
Return a null column when no column exists for an attribute
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/reflection_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index e6603f28be..b3c02d29cb 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -80,6 +80,25 @@ class ReflectionTest < ActiveRecord::TestCase assert_equal :integer, @first.column_for_attribute("id").type end + def test_non_existent_columns_return_null_object + column = @first.column_for_attribute("attribute_that_doesnt_exist") + 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(object) + assert_equal object, column.type_cast_for_write(object) + assert_equal object, column.type_cast_for_database(object) + end + def test_reflection_klass_for_nested_class_name reflection = MacroReflection.new(:company, nil, nil, { :class_name => 'MyApplication::Business::Company' }, ActiveRecord::Base) assert_nothing_raised do |