db-query-matchers 0.2.3 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e1172f88f20bbbc9c437ff4f4f0f8cc39647265
4
- data.tar.gz: 317c16fbe2d356a93596427ec0d08c025ed9c467
3
+ metadata.gz: c7c9f607891bbb0b674c410baae4a3fe9456e83c
4
+ data.tar.gz: 8d6f264f879659422b69ac07c3b4b0441952d7a6
5
5
  SHA512:
6
- metadata.gz: 8e82a658b056699b88c9b13ecc76089367c8138150f9e3bf5d9375675fb18443057c3eef7ac576cf99e44d8555b37d5e35f63149216779f8b99e016ddea8e11d
7
- data.tar.gz: eb4da12508affb0086fb89d9baca061af701a99ee176e4d1fbef4b8bec3c612f4023d5a1355bb3840fd75a10960d12cd6d5faa67d473ace897a022907b57ceeb
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
- supports_block_expectations
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
- @counter = DBQueryMatchers::QueryCounter.new
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 DBQueryMatchers.configuration.ignores.any? do |pattern|
42
- payload[:sql] =~ pattern
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
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module DBQueryMatchers
3
- VERSION = '0.2.3'
3
+ VERSION = '0.3.0'
4
4
  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.2.3
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: 2014-08-12 00:00:00.000000000 Z
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.0
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: