From 6d7ac31ddb9b5457177ee6b127624ad7e8cdd9d3 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 20 Jun 2014 11:36:23 -0600 Subject: Return a null object from `AttributeSet#[]` --- activerecord/test/cases/attribute_set_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/attribute_set_test.rb b/activerecord/test/cases/attribute_set_test.rb index 091f7e396a..e3f0304de2 100644 --- a/activerecord/test/cases/attribute_set_test.rb +++ b/activerecord/test/cases/attribute_set_test.rb @@ -18,6 +18,14 @@ module ActiveRecord assert_equal 4, attributes[:bar].value end + test "[] returns a null object" do + builder = AttributeSet::Builder.new(foo: Type::Float.new) + attributes = builder.build_from_database(foo: '3.3') + + assert_equal '3.3', attributes[:foo].value_before_type_cast + assert_equal nil, attributes[:bar].value_before_type_cast + end + test "duping creates a new hash and dups each attribute" do builder = AttributeSet::Builder.new(foo: Type::Integer.new, bar: Type::String.new) attributes = builder.build_from_database(foo: 1, bar: 'foo') -- cgit v1.2.3