ar-query-matchers 0.5.0 → 0.5.3
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8890df1fae037a9adc6cfd2ee413c4c405a05fd31e680ed7ec69f26cccddfa9
|
4
|
+
data.tar.gz: ee84a0a237c35d6f315e868002382c600c06ecbcbc542ccd4f1c19e4d71730c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bdf3296e2c16cc60425f3eede226c25ab210270203443d0eef62ab1f34a8c5640d9b34ebf5b6239f24f0e56064528fbfabbd7e344ae11f2d9c48c41c1d30bd7
|
7
|
+
data.tar.gz: a0464fd47a18b306958468e511e782f4e0c5aa5457da6d0120277da2a2b54d82218a9c668868dd875dfcdf4b4934752f9542f02d119f95ba26c500014bde7072
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.5.3] - 2021-05-26
|
10
|
+
### Changed
|
11
|
+
- Re-release of previous version due to accidental premature release
|
12
|
+
|
13
|
+
## [0.5.2] - 2021-05-26
|
14
|
+
### Changed
|
15
|
+
- Update MODEL_SQL_PATTERN to allow for more accurate matches against SQL strings
|
16
|
+
|
17
|
+
## [0.5.1] - 2020-11-19
|
18
|
+
### Changed
|
19
|
+
- Removes zero count expectations from hash before comparing
|
20
|
+
|
9
21
|
## [0.5.0] - 2020-07-23
|
10
22
|
### Changed
|
11
23
|
- Add time information to query counter
|
@@ -27,7 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
27
39
|
### Added
|
28
40
|
- First versions as a public ruby gem.
|
29
41
|
|
30
|
-
[Unreleased]: https://github.com/gusto/ar-query-matchers/compare/v0.5.
|
42
|
+
[Unreleased]: https://github.com/gusto/ar-query-matchers/compare/v0.5.1...HEAD
|
43
|
+
[0.5.1]: https://github.com/gusto/ar-query-matchers/releases/tag/v0.5.1
|
31
44
|
[0.5.0]: https://github.com/gusto/ar-query-matchers/releases/tag/v0.5.0
|
32
45
|
[0.4.0]: https://github.com/gusto/ar-query-matchers/releases/tag/v0.4.0
|
33
46
|
[0.3.0]: https://github.com/gusto/ar-query-matchers/releases/tag/v0.3.0
|
data/lib/ar_query_matchers.rb
CHANGED
@@ -7,6 +7,12 @@ require 'bigdecimal'
|
|
7
7
|
|
8
8
|
module ArQueryMatchers
|
9
9
|
module ArQueryMatchers
|
10
|
+
class Utility
|
11
|
+
def self.remove_superfluous_expectations(expected)
|
12
|
+
expected.select { |_, v| v.positive? }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
module CreateModels
|
11
17
|
# The following will succeed:
|
12
18
|
# expect {
|
@@ -23,7 +29,7 @@ module ArQueryMatchers
|
|
23
29
|
|
24
30
|
match do |block|
|
25
31
|
@query_stats = Queries::CreateCounter.instrument(&block)
|
26
|
-
expected == @query_stats.query_counts
|
32
|
+
Utility.remove_superfluous_expectations(expected) == @query_stats.query_counts
|
27
33
|
end
|
28
34
|
|
29
35
|
def failure_text
|
@@ -83,7 +89,7 @@ module ArQueryMatchers
|
|
83
89
|
|
84
90
|
match do |block|
|
85
91
|
@query_stats = Queries::LoadCounter.instrument(&block)
|
86
|
-
expected == @query_stats.query_counts
|
92
|
+
Utility.remove_superfluous_expectations(expected) == @query_stats.query_counts
|
87
93
|
end
|
88
94
|
|
89
95
|
def failure_text
|
@@ -147,7 +153,7 @@ module ArQueryMatchers
|
|
147
153
|
|
148
154
|
match do |block|
|
149
155
|
@query_stats = Queries::UpdateCounter.instrument(&block)
|
150
|
-
expected == @query_stats.query_counts
|
156
|
+
Utility.remove_superfluous_expectations(expected) == @query_stats.query_counts
|
151
157
|
end
|
152
158
|
|
153
159
|
def failure_text
|
@@ -21,7 +21,7 @@ module ArQueryMatchers
|
|
21
21
|
|
22
22
|
# Matches unnamed SQL operations like the following:
|
23
23
|
# "SELECT COUNT(*) FROM `users` ..."
|
24
|
-
MODEL_SQL_PATTERN = /SELECT
|
24
|
+
MODEL_SQL_PATTERN = /SELECT (?:(?!SELECT).)* FROM [`"](?<table_name>[^`"]+)[`"]/.freeze
|
25
25
|
|
26
26
|
def filter_map(name, sql)
|
27
27
|
# First check for a `SELECT * FROM` query that ActiveRecord has
|
@@ -79,7 +79,7 @@ module ArQueryMatchers
|
|
79
79
|
return if payload[:cached]
|
80
80
|
|
81
81
|
# Given a `sql.active_record` event, figure out which model is being
|
82
|
-
# accessed. Some of the simpler queries have a :
|
82
|
+
# accessed. Some of the simpler queries have a :name key that makes this
|
83
83
|
# really easy. Others require parsing the SQL by hand.
|
84
84
|
model_name = @query_filter.filter_map(payload[:name] || '', payload[:sql] || '')&.model_name
|
85
85
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-query-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matan Zruya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
190
|
- !ruby/object:Gem::Version
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
|
-
rubygems_version: 3.0.3
|
193
|
+
rubygems_version: 3.0.3.1
|
194
194
|
signing_key:
|
195
195
|
specification_version: 4
|
196
196
|
summary: Ruby test matchers for instrumenting ActiveRecord query counts
|