aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_set_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-14 11:20:28 -0700
committerSean Griffin <sean@thoughtbot.com>2014-11-14 14:30:40 -0700
commit0f29c216074c5da6644feddb5184c4881c078b0d (patch)
tree5ace61c20fc1f4b54c9187567ffccc8c695c3c7e /activerecord/test/cases/attribute_set_test.rb
parent70d1b5a7f8e25b077168deaf592e0e58c3f2bdd1 (diff)
downloadrails-0f29c216074c5da6644feddb5184c4881c078b0d.tar.gz
rails-0f29c216074c5da6644feddb5184c4881c078b0d.tar.bz2
rails-0f29c216074c5da6644feddb5184c4881c078b0d.zip
Reduce the amount of work performed when instantiating AR models
We don't know which attributes will or won't be used, and we don't want to create massive bottlenecks at instantiation. Rather than doing *any* iteration over types and values, we can lazily instantiate the object. The lazy attribute hash should not fully implement hash, or subclass hash at any point in the future. It is not meant to be a replacement, but instead implement its own interface which happens to overlap.
Diffstat (limited to 'activerecord/test/cases/attribute_set_test.rb')
-rw-r--r--activerecord/test/cases/attribute_set_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_set_test.rb b/activerecord/test/cases/attribute_set_test.rb
index dc20c3c676..a531be482e 100644
--- a/activerecord/test/cases/attribute_set_test.rb
+++ b/activerecord/test/cases/attribute_set_test.rb
@@ -123,6 +123,15 @@ module ActiveRecord
assert_nil attributes.fetch_value(:bar)
end
+ test "the primary_key is always initialized" do
+ builder = AttributeSet::Builder.new({ foo: Type::Integer.new }, :foo)
+ attributes = builder.build_from_database
+
+ assert attributes.key?(:foo)
+ assert_equal [:foo], attributes.keys
+ assert attributes[:foo].initialized?
+ end
+
class MyType
def type_cast_from_user(value)
return if value.nil?