rspec-activerecord-formatter 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eaf70a87ed79a750607124b849bc8f75325f3cbd8b27c6c6c378008bec7d058
|
4
|
+
data.tar.gz: 339da336745315f324dcac1a71ae2ec9800623b250c1f1cbb3e2bf7f7c1c2461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 671d5e6dc1b7a4abf41c831a26fe6d7f0e599babfb95bcdca2cc5e08e9704bfef855fc9327a349bbd5f5ad9e81032f529ca50d8cb09344589c35bd04c63a22ca
|
7
|
+
data.tar.gz: 27dd9d446ebf122ce2ef1fb442440a36965557e99f34e4fe730bcaa18607470b23dbb24dc0e0a8405961ea582bc9920817e9ac193d1dff33b19690a32b5f4cd1
|
@@ -3,12 +3,14 @@ require 'active_support/notifications'
|
|
3
3
|
module ActiveRecordFormatterHelpers
|
4
4
|
class Collector
|
5
5
|
attr_reader :query_count, :objects_count, :total_queries, :total_objects,
|
6
|
-
:query_names, :active_groups, :group_counts
|
6
|
+
:query_names, :active_groups, :group_counts, :groups_encountered
|
7
7
|
|
8
8
|
SKIP_QUERIES = ["SELECT tablename FROM pg_tables", "select sum(ct) from (select count(*) ct from"]
|
9
9
|
|
10
10
|
def initialize
|
11
|
+
#@unnamed_queries = []
|
11
12
|
@query_count = 0
|
13
|
+
@groups_encountered = 0
|
12
14
|
@objects_count = 0
|
13
15
|
@total_queries = 0
|
14
16
|
@total_objects = 0
|
@@ -41,6 +43,8 @@ module ActiveRecordFormatterHelpers
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def group_started(group)
|
46
|
+
@groups_encountered += 1
|
47
|
+
|
44
48
|
return unless group.parent_groups.length > 1
|
45
49
|
|
46
50
|
active_groups.push(group_path(group))
|
@@ -77,8 +81,33 @@ module ActiveRecordFormatterHelpers
|
|
77
81
|
if data[:name] == "SQL" && query_is_an_insert?(data[:sql])
|
78
82
|
table = data[:sql].scan(/INSERT INTO "(\w+)"/).first.first
|
79
83
|
name = "#{table} Create"
|
84
|
+
elsif query_is_a_full_table_delete?(data[:sql])
|
85
|
+
table = data[:sql].scan(/DELETE FROM "(\w+)"/).first.first
|
86
|
+
name = "Full Delete Table"
|
87
|
+
# TODO: truncate table
|
88
|
+
elsif query_is_transaction_management?(data[:sql])
|
89
|
+
name = "Transaction Management"
|
90
|
+
elsif query_is_schema_detection?(data[:sql])
|
91
|
+
name = "SCHEMA"
|
92
|
+
elsif query_is_trigger_management?(data[:sql])
|
93
|
+
name = "Trigger Management"
|
94
|
+
elsif query_refreshes_materialized_view?(data[:sql])
|
95
|
+
name = "Refresh Materialized View"
|
80
96
|
end
|
81
97
|
|
98
|
+
|
99
|
+
# In older versions of Rails, insert statements are just counted as SQL
|
100
|
+
# queries, which means that all the queries are just bunchedup at the top.
|
101
|
+
# Makes this data pretty useless. So anyway, try to suss out a name for
|
102
|
+
# at least those insertions (which are much more frequent than, say,
|
103
|
+
# updates in a test suite anyway).
|
104
|
+
#if data[:name].nil? && query_is_a_delete?(data[:sql])
|
105
|
+
# table = data[:sql].scan(/DELETE FROM "(\w+)"/).first.first
|
106
|
+
# name = "#{table} Delete"
|
107
|
+
#end
|
108
|
+
|
109
|
+
#@unnamed_queries << data if name == "Unnamed"
|
110
|
+
|
82
111
|
query_names[name] += 1
|
83
112
|
end
|
84
113
|
|
@@ -89,7 +118,32 @@ module ActiveRecordFormatterHelpers
|
|
89
118
|
# TODO: what happens if we try to create many records at once?
|
90
119
|
# TODO: are there any false positives we need to worry about? false negatives?
|
91
120
|
def query_is_an_insert?(query)
|
92
|
-
query =~
|
121
|
+
query =~ /^INSERT INTO/
|
122
|
+
end
|
123
|
+
|
124
|
+
def query_is_a_delete?(query)
|
125
|
+
query =~ /^DELETE FROM/
|
126
|
+
end
|
127
|
+
|
128
|
+
def query_is_a_full_table_delete?(query)
|
129
|
+
query =~ /^DELETE FROM [a-z_\."]*;$/i
|
130
|
+
end
|
131
|
+
|
132
|
+
def query_is_transaction_management?(query)
|
133
|
+
query =~ /^(COMMIT|BEGIN|ROLLBACK|SAVEPOINT|RELEASE SAVEPOINT)/
|
134
|
+
end
|
135
|
+
|
136
|
+
def query_is_schema_detection?(query)
|
137
|
+
query =~ /SELECT .* FROM pg_tables/m ||
|
138
|
+
query =~ /SELECT .* FROM information_schema.views/
|
139
|
+
end
|
140
|
+
|
141
|
+
def query_is_trigger_management?(query)
|
142
|
+
query =~ /(DISABLE|ENABLE) TRIGGER ALL/m
|
143
|
+
end
|
144
|
+
|
145
|
+
def query_refreshes_materialized_view?(query)
|
146
|
+
query =~ /REFRESH MATERIALIZED VIEW/m
|
93
147
|
end
|
94
148
|
end
|
95
149
|
end
|
@@ -26,6 +26,7 @@ module ActiveRecordFormatterHelpers
|
|
26
26
|
|
27
27
|
File.open(file_path, "wb") do |f|
|
28
28
|
f.puts "#{collector.total_objects} AR objects, #{collector.total_queries} AR queries"
|
29
|
+
f.puts "#{collector.groups_encountered} example groups executed"
|
29
30
|
|
30
31
|
f.puts ""
|
31
32
|
f.puts "Worst Example Groups by Object Creation"
|
@@ -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 = "2.
|
9
|
+
gem.version = "2.1.0"
|
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: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Mastey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,7 +86,7 @@ homepage: http://github.com/jmmastey/rspec-activerecord-formatter
|
|
86
86
|
licenses:
|
87
87
|
- MIT
|
88
88
|
metadata: {}
|
89
|
-
post_install_message:
|
89
|
+
post_install_message:
|
90
90
|
rdoc_options: []
|
91
91
|
require_paths:
|
92
92
|
- lib
|
@@ -101,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
|
105
|
-
|
106
|
-
signing_key:
|
104
|
+
rubygems_version: 3.1.4
|
105
|
+
signing_key:
|
107
106
|
specification_version: 4
|
108
107
|
summary: Adds object creations and queries to Rspec output.
|
109
108
|
test_files: []
|