rspec-activerecord-formatter 0.2.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 3c8cb5d2c352d6067bb7b6a1005ce9d80f257ef818e94da07b03530e705d5934
4
- data.tar.gz: a21d87f0badc6b92de0906f3bc7782b6c13dbe89ee40b59ec1b07bf2a40ca1f1
2
+ SHA1:
3
+ metadata.gz: ae073f4da31f6b04309fcef6a1b27b284e06e87a
4
+ data.tar.gz: 1228a0ffe035026514734be050855488541b1f96
5
5
  SHA512:
6
- metadata.gz: d31c6f727a9c54acde509ce7f8b66185eedeb7825ff18af6b7da27f583ed460e38fafcb17a65bd66b0ceadef2b5a2a2db9cdd7a6821d199568e4b2170a81f23f
7
- data.tar.gz: 1265045f094776141c99699dc6f35514de052cb60c7c40893808bb6ebe4ace017c2244c55d3681adb16c3cc7472dcd197bd3e41566ee6cd17ad9a4e102cf556e
6
+ metadata.gz: c89d5e11bb515e57f3d64708c0d4628ab7904a95e0f26e9c48ce0605f95eef2cf5c6afb6d083fb41513b2bdcf45f9358c86fe616e0fe27eff1213881ecc14d20
7
+ data.tar.gz: 6a3b5e64c086e7b572d1e247e4bb408c70743608d591a347a799ec2a043ad830b99d41ba68ed9f099dfe5f8e8a83e47b1c05e086f2ead5af95b9a0ccedab0919
data/README.md CHANGED
@@ -14,9 +14,10 @@ This library plays nicely with DatabaseCleaner.
14
14
  Installation
15
15
  ------------
16
16
 
17
- Normal bundle stuff.
17
+ Normal bundle stuff. You'll almost certainly need to add this gem to your
18
+ bundle at least temporarily, since you'll be running rspec using bundler.
18
19
 
19
- gem rspec-activerecord-formatter
20
+ gem 'rspec-activerecord-formatter'
20
21
 
21
22
 
22
23
  Usage
@@ -31,6 +31,16 @@ class ActiveRecordFormatter < ::RSpec::Core::Formatters::DocumentationFormatter
31
31
  end
32
32
 
33
33
  output.puts formatted
34
+ output.puts record_type_summaries
35
+ end
36
+
37
+ def record_type_summaries
38
+ summary = ["", "Summary of Queries"]
39
+ collector.most_common_query_names.each do |name, count|
40
+ summary << "%-4s %s" % [count, name]
41
+ end
42
+
43
+ summary.join("\n")
34
44
  end
35
45
 
36
46
  protected
@@ -2,7 +2,7 @@ require 'active_support/notifications'
2
2
 
3
3
  module ActiveRecordFormatterHelpers
4
4
  class Collector
5
- attr_reader :query_count, :objects_count, :total_queries, :total_objects
5
+ attr_reader :query_count, :objects_count, :total_queries, :total_objects, :query_names
6
6
  SKIP_QUERIES = ["SELECT tablename FROM pg_tables", "select sum(ct) from (select count(*) ct from"]
7
7
 
8
8
  def initialize
@@ -10,6 +10,7 @@ module ActiveRecordFormatterHelpers
10
10
  @objects_count = 0
11
11
  @total_queries = 0
12
12
  @total_objects = 0
13
+ @query_names = Hash.new(0)
13
14
 
14
15
  ActiveSupport::Notifications.subscribe("sql.active_record", method(:record_query))
15
16
  end
@@ -24,6 +25,13 @@ module ActiveRecordFormatterHelpers
24
25
  @objects_count += 1
25
26
  @total_objects += 1
26
27
  end
28
+
29
+ name = data[:name] || "Unnamed"
30
+ @query_names[name] += 1
31
+ end
32
+
33
+ def most_common_query_names
34
+ @query_names.sort_by(&:last).reverse
27
35
  end
28
36
 
29
37
  def reset_example
@@ -6,7 +6,7 @@ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
6
6
  Gem::Specification.new do |gem|
7
7
 
8
8
  gem.name = "rspec-activerecord-formatter"
9
- gem.version = "0.2.0"
9
+ gem.version = "1.0.1"
10
10
 
11
11
  gem.summary = "Adds object creations and queries to Rspec output."
12
12
  gem.description = "Creates a new formatter for ActiveRecord that can help you diagnose performance issues in RSpec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-activerecord-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Mastey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-21 00:00:00.000000000 Z
11
+ date: 2019-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.7.6
115
+ rubygems_version: 2.5.2.3
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Adds object creations and queries to Rspec output.