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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f78d721c38dc71a9253a97fcfa30a776b3b5b721
4
- data.tar.gz: 92641ed402a948cea988adcc6bbdfe5a28c6ea13
3
+ metadata.gz: 4e9b67001d03e3aba3c3f24e3e9042c1791694cf
4
+ data.tar.gz: 9eec49081038cc104babaf0b6ffc7e8986c297ec
5
5
  SHA512:
6
- metadata.gz: 8225933bccc86b9dda7dd7d6ca23222b87be5867e9b683a7e9134992c19744d63155cbddb6128ae959684850a915bd701ca3a9b4b3115aa49d8353a15330cabf
7
- data.tar.gz: 31c22139aaeaa65f0849652049548333980b638ee2c86a7b327ddc7e1201c838d43888b92808db8290f984634e38dad364e0c8fd8c0486768c4da4b07aea5d94
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
@@ -1,3 +1,3 @@
1
1
  module QueryMatchers
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -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.8
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-04-28 00:00:00.000000000 Z
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.11
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