ar-query-matchers 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/ar_query_matchers.rb +43 -0
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a549f325b6c39998321fedc7e7e9833134bd5437602caf762b6d825b51b6d4f
4
- data.tar.gz: 131b22ca3c3826cb18e77d976427eab1307378324cffc752e6097bf6b17db3d3
3
+ metadata.gz: e73f1af783ac0aea8a1342b20e01d139106e29c2c4048bf3d30086a13675f204
4
+ data.tar.gz: 64b309608ae8f52ba8d7a998ea0e7658eebb2ee7d11122d8e1c0934f042131b6
5
5
  SHA512:
6
- metadata.gz: 4c7984246a589e58544a4189e8b2df3c5faaab444d1a41d26e98d676ee8167149f8efd775f9aff56a6d870ed8916e1b82df04833d62e4e2d0e894acd3259e5c0
7
- data.tar.gz: 80a8a6f06dcd91e56153800af77bc44dcebe9677c0313d53690d878072b738001d866f6998d6fac46daae4080def3c7c52673c8a2880d8486d62b2a53d492e22
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
@@ -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.6.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-05 00:00:00.000000000 Z
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