aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_set_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-14 11:58:35 -0700
committerSean Griffin <sean@thoughtbot.com>2014-11-14 14:30:40 -0700
commit3f63ac4e4dd22a452a37ad7a654cf5e4f4e66349 (patch)
tree63179c74db0ccd44be244849d5471311273d2407 /activerecord/test/cases/attribute_set_test.rb
parent0f29c216074c5da6644feddb5184c4881c078b0d (diff)
downloadrails-3f63ac4e4dd22a452a37ad7a654cf5e4f4e66349.tar.gz
rails-3f63ac4e4dd22a452a37ad7a654cf5e4f4e66349.tar.bz2
rails-3f63ac4e4dd22a452a37ad7a654cf5e4f4e66349.zip
Correctly determine if an attribute is uninitialized
In real usage, we give the builder a types hash with a default value of `Type::Value.new`. This means we need to explicitly check for the key, rather than the truthiness of the type to determine if it's a known but uninitialized attribute
Diffstat (limited to 'activerecord/test/cases/attribute_set_test.rb')
-rw-r--r--activerecord/test/cases/attribute_set_test.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/test/cases/attribute_set_test.rb b/activerecord/test/cases/attribute_set_test.rb
index a531be482e..de63672963 100644
--- a/activerecord/test/cases/attribute_set_test.rb
+++ b/activerecord/test/cases/attribute_set_test.rb
@@ -109,7 +109,15 @@ module ActiveRecord
test "fetch_value returns nil for unknown attributes" do
attributes = attributes_with_uninitialized_key
- assert_nil attributes.fetch_value(:wibble)
+ assert_nil attributes.fetch_value(:wibble) { "hello" }
+ end
+
+ test "fetch_value returns nil for unknown attributes when types has a default" do
+ types = Hash.new(Type::Value.new)
+ builder = AttributeSet::Builder.new(types)
+ attributes = builder.build_from_database
+
+ assert_nil attributes.fetch_value(:wibble) { "hello" }
end
test "fetch_value uses the given block for uninitialized attributes" do