db-query-matchers 0.2.3 → 0.3.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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c9f607891bbb0b674c410baae4a3fe9456e83c
|
4
|
+
data.tar.gz: 8d6f264f879659422b69ac07c3b4b0441952d7a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23b5db77346a98ecd7c9ab0db61bd3cec815f42532e819a3310847c8241211c6dbc9b0aae21acf7e803d8243c195bcb15c49dd666bf377db96561ef657bb92b5
|
7
|
+
data.tar.gz: 12217e1be76989c510ce4b46665b6ff8e0b7ffb6caa334b441eda7c23de0aced5cae097aaaf3a4e88fe86733692a3e13792ff678abfbd915d070fbc4d7eb81bb
|
@@ -10,9 +10,26 @@ require 'rspec/mocks'
|
|
10
10
|
# @example
|
11
11
|
# expect { subject }.to make_database_queries(count: 1)
|
12
12
|
#
|
13
|
+
# @example
|
14
|
+
# expect { subject }.to make_database_queries(manipulative: true)
|
15
|
+
#
|
13
16
|
# @see DBQueryMatchers::QueryCounter
|
14
17
|
RSpec::Matchers.define :make_database_queries do |options = {}|
|
15
|
-
|
18
|
+
if RSpec::Core::Version::STRING =~ /^2/
|
19
|
+
def self.failure_message_when_negated(&block)
|
20
|
+
failure_message_for_should_not(&block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.failure_message(&block)
|
24
|
+
failure_message_for_should(&block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def supports_block_expectations?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
else
|
31
|
+
supports_block_expectations
|
32
|
+
end
|
16
33
|
|
17
34
|
# Taken from ActionView::Helpers::TextHelper
|
18
35
|
def pluralize(count, singular, plural = nil)
|
@@ -26,7 +43,11 @@ RSpec::Matchers.define :make_database_queries do |options = {}|
|
|
26
43
|
end
|
27
44
|
|
28
45
|
match do |block|
|
29
|
-
|
46
|
+
counter_options = {}
|
47
|
+
if options[:manipulative]
|
48
|
+
counter_options[:matches] = [/^\ *(INSERT|UPDATE|DELETE\ FROM)/]
|
49
|
+
end
|
50
|
+
@counter = DBQueryMatchers::QueryCounter.new(counter_options)
|
30
51
|
ActiveSupport::Notifications.subscribed(@counter.to_proc,
|
31
52
|
'sql.active_record',
|
32
53
|
&block)
|
@@ -16,7 +16,8 @@ module DBQueryMatchers
|
|
16
16
|
class QueryCounter
|
17
17
|
attr_reader :count, :log
|
18
18
|
|
19
|
-
def initialize
|
19
|
+
def initialize(options = {})
|
20
|
+
@matches = options[:matches]
|
20
21
|
@count = 0
|
21
22
|
@log = []
|
22
23
|
end
|
@@ -38,11 +39,16 @@ module DBQueryMatchers
|
|
38
39
|
# @param _message_id [String] unique ID for this notification
|
39
40
|
# @param payload [Hash] the payload
|
40
41
|
def callback(_name, _start, _finish, _message_id, payload)
|
41
|
-
return if
|
42
|
-
|
43
|
-
end
|
42
|
+
return if @matches && !any_match?(@matches, payload[:sql])
|
43
|
+
return if any_match?(DBQueryMatchers.configuration.ignores, payload[:sql])
|
44
44
|
@count += 1
|
45
45
|
@log << payload[:sql]
|
46
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def any_match?(patterns, sql)
|
51
|
+
patterns.any? { |pattern| sql =~ pattern }
|
52
|
+
end
|
47
53
|
end
|
48
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db-query-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Causes Engineering
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -103,8 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.2.
|
106
|
+
rubygems_version: 2.2.2
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: RSpec matchers for database queries
|
110
110
|
test_files: []
|
111
|
+
has_rdoc:
|