ar-query-matchers 0.6.0 → 0.7.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/ar_query_matchers.rb +43 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e73f1af783ac0aea8a1342b20e01d139106e29c2c4048bf3d30086a13675f204
|
4
|
+
data.tar.gz: 64b309608ae8f52ba8d7a998ea0e7658eebb2ee7d11122d8e1c0934f042131b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13b5fe44e89c7e0df944882d4d15dac2ff72b8fe3a679591c46b15015587159246c4e2344d2e604b6a31a0ee6dc5a450eacd85ef638d90d578f1b4073fca2f58
|
7
|
+
data.tar.gz: 61d48528375466023a71bf17ad2e453ec62ce5520f43200f88de94ff2f116522be3694fe2c0116f83093fa5f1087cf4774471143e63deb8f465dd03173bda8cd
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.7.0] - 2022-01-27
|
10
|
+
### Added
|
11
|
+
- A new matcher, `only_load_at_most_models`, will do a less-than-or-equal-to (<=) check on model counts. This is a method that makes tests less noisy as performance gets better.
|
12
|
+
|
9
13
|
## [0.6.0] - 2022-01-05
|
10
14
|
### Changed
|
11
15
|
- Support Rails 7
|
data/lib/ar_query_matchers.rb
CHANGED
@@ -97,6 +97,49 @@ module ArQueryMatchers
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
# The following will fail because the call to `User` is not expected, even
|
101
|
+
# though the Payroll count is correct:
|
102
|
+
#
|
103
|
+
# expect {
|
104
|
+
# Payroll.count
|
105
|
+
# Payroll.count
|
106
|
+
# User.count
|
107
|
+
# }.to only_load_at_most_models(
|
108
|
+
# 'Payroll' => 2,
|
109
|
+
# )
|
110
|
+
#
|
111
|
+
# The following will succeed because the counts are exact:
|
112
|
+
#
|
113
|
+
# expect {
|
114
|
+
# Payroll.count
|
115
|
+
# Payroll.count
|
116
|
+
# User.count
|
117
|
+
# }.to only_load_at_most_models(
|
118
|
+
# 'Payroll' => 2,
|
119
|
+
# 'User' => 1,
|
120
|
+
# )
|
121
|
+
#
|
122
|
+
RSpec::Matchers.define(:only_load_at_most_models) do |expected = {}|
|
123
|
+
include MatcherConfiguration
|
124
|
+
include MatcherErrors
|
125
|
+
|
126
|
+
match do |block|
|
127
|
+
@query_stats = Queries::LoadCounter.instrument(&block)
|
128
|
+
expected_queries = Utility.remove_superfluous_expectations(expected)
|
129
|
+
actual_queries = @query_stats.query_counts
|
130
|
+
|
131
|
+
all_models = expected_queries.keys | actual_queries.keys
|
132
|
+
|
133
|
+
all_models.each do |model|
|
134
|
+
expect(actual_queries[model] || 0).to be <= expected_queries[model]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def failure_text
|
139
|
+
expectation_failed_message('load at most')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
100
143
|
RSpec::Matchers.define(:not_load_any_models) do
|
101
144
|
include MatcherConfiguration
|
102
145
|
include MatcherErrors
|
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.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matan Zruya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rake
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|