query_matchers 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/query_matchers/query_counter.rb +6 -1
- data/lib/query_matchers/version.rb +1 -1
- data/spec/query_counter_spec.rb +19 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e9b67001d03e3aba3c3f24e3e9042c1791694cf
|
4
|
+
data.tar.gz: 9eec49081038cc104babaf0b6ffc7e8986c297ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a67e26e09c7e7b29a605f6f673085d7485c903435b0e5c52caad99da80311900af702bf040468a4631e77223d292674d254f4be467fa3782494d4a3e5fbc6d
|
7
|
+
data.tar.gz: d89c17cab0bcadfbae09c7d6c844a79b15ae8e73d0ad3715ebe67d5cd624058e8449e1f9260e3998f7ce019a7bd1ca31a01f974d8203abd805eebb484d04db72
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module QueryMatchers
|
2
2
|
class QueryCounter
|
3
3
|
OPERATIONS = %w(SELECT INSERT UPDATE DELETE)
|
4
|
+
RAILS5_INFORMATION_SCHEMA_REGEX = /^\s*SELECT.+FROM information_schema\./m
|
4
5
|
|
5
6
|
def initialize
|
6
7
|
@events = []
|
@@ -28,7 +29,11 @@ module QueryMatchers
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def count_query?(sql)
|
31
|
-
OPERATIONS.any? {|op| sql.start_with?(op) }
|
32
|
+
OPERATIONS.any? {|op| sql.lstrip.start_with?(op) } && !ignore_query?(sql)
|
33
|
+
end
|
34
|
+
|
35
|
+
def ignore_query?(sql)
|
36
|
+
sql.match?(RAILS5_INFORMATION_SCHEMA_REGEX)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
data/spec/query_counter_spec.rb
CHANGED
@@ -42,12 +42,31 @@ describe QueryMatchers::QueryCounter do
|
|
42
42
|
expect(counter.query_count).to eq(1)
|
43
43
|
end
|
44
44
|
|
45
|
+
it "counts queries with a bit of whitespace" do
|
46
|
+
counter.execute!(sql_target(" SELECT FROM inventory"))
|
47
|
+
|
48
|
+
expect(counter.query_count).to eq(1)
|
49
|
+
end
|
50
|
+
|
45
51
|
it "doesn't count any other type of query" do
|
46
52
|
counter.execute!(sql_target("BREAKDANCE"))
|
47
53
|
|
48
54
|
expect(counter.query_count).to eq(0)
|
49
55
|
end
|
50
56
|
|
57
|
+
it "ignores Rails 5's schema queries" do
|
58
|
+
counter.execute!(sql_target(<<-SQL))
|
59
|
+
SELECT column_name
|
60
|
+
FROM information_schema.key_column_usage
|
61
|
+
WHERE constraint_name = 'PRIMARY'
|
62
|
+
AND table_schema = DATABASE()
|
63
|
+
AND table_name = 'jokes'
|
64
|
+
ORDER BY ordinal_position
|
65
|
+
SQL
|
66
|
+
|
67
|
+
expect(counter.query_count).to eq(0)
|
68
|
+
end
|
69
|
+
|
51
70
|
def sql_target(sql)
|
52
71
|
proc { perform_sql(sql) }
|
53
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.6.
|
114
|
+
rubygems_version: 2.6.13
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: Match the number of queries performed in any block of code
|