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 +5 -5
- data/README.md +3 -2
- data/lib/rspec/activerecord/formatter.rb +10 -0
- data/lib/rspec/activerecord/helpers/collector.rb +9 -1
- data/rspec-activerecord-formatter.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae073f4da31f6b04309fcef6a1b27b284e06e87a
|
4
|
+
data.tar.gz: 1228a0ffe035026514734be050855488541b1f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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-
|
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.
|
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.
|