aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-20 11:36:23 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-20 11:36:23 -0600
commit6d7ac31ddb9b5457177ee6b127624ad7e8cdd9d3 (patch)
tree692509e1b8a71c952f3b803d0cec8acb91b60949 /activerecord/test
parent081eec4ba68d161623791d4f6c885ce0d442f31c (diff)
downloadrails-6d7ac31ddb9b5457177ee6b127624ad7e8cdd9d3.tar.gz
rails-6d7ac31ddb9b5457177ee6b127624ad7e8cdd9d3.tar.bz2
rails-6d7ac31ddb9b5457177ee6b127624ad7e8cdd9d3.zip
Return a null object from `AttributeSet#[]`
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/attribute_set_test.rb8
1 files changed, 8 insertions, 0 deletions
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')