aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-10-13 14:22:24 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-10-13 14:24:16 -0700
commit2a0d97bc89fc230241453cbbf55621309e1f3ac6 (patch)
treee7f24e5eb94ff076295e557ba41d85a008b9b345 /activerecord/test/cases/associations
parent74a9b3777e8d01aed15f000f486bef0877830aee (diff)
downloadrails-2a0d97bc89fc230241453cbbf55621309e1f3ac6.tar.gz
rails-2a0d97bc89fc230241453cbbf55621309e1f3ac6.tar.bz2
rails-2a0d97bc89fc230241453cbbf55621309e1f3ac6.zip
measure record instantiation time in AS::Notifications
emit an event when we instantiate AR objects so we can see how many records were instantiated and how long it took
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index b852bd3536..8234ee95be 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -935,6 +935,42 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal 3, authors(:david).posts_with_comments.where("length(comments.body) > 15").references(:comments).count
end
+ def test_association_loading_notification
+ notifications = messages_for('instantiation.active_record') do
+ Developer.all.merge!(:includes => 'projects', :where => { 'developers_projects.access_level' => 1 }, :limit => 5).to_a.size
+ end
+
+ message = notifications.first
+ payload = message.last
+ count = Developer.all.merge!(:includes => 'projects', :where => { 'developers_projects.access_level' => 1 }, :limit => 5).to_a.size
+
+ # eagerloaded row count should be greater than just developer count
+ assert_operator payload[:record_count], :>, count
+ assert_equal Developer.name, payload[:class_name]
+ end
+
+ def test_base_messages
+ notifications = messages_for('instantiation.active_record') do
+ Developer.all.to_a
+ end
+ message = notifications.first
+ payload = message.last
+
+ assert_equal Developer.all.to_a.count, payload[:record_count]
+ assert_equal Developer.name, payload[:class_name]
+ end
+
+ def messages_for(name)
+ notifications = []
+ ActiveSupport::Notifications.subscribe(name) do |*args|
+ notifications << args
+ end
+ yield
+ notifications
+ ensure
+ ActiveSupport::Notifications.unsubscribe(name)
+ end
+
def test_load_with_sti_sharing_association
assert_queries(2) do #should not do 1 query per subclass
Comment.includes(:post).to_a