rspec-activerecord-expectations 1.3.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +38 -8
- data/CHANGELOG.md +13 -5
- data/README.md +20 -6
- data/lib/rspec/activerecord/expectations/query_inspector.rb +2 -2
- data/rspec-activerecord-expectations.gemspec +8 -3
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d320c1e0f80e96c3bbb2cb07df63b941aa9bb1aa3878f9ca46e6fa1fed483569
|
4
|
+
data.tar.gz: 69487efb7a89d208d28a0d26faa3c74fc3315645803a1ec4162a6bd9f3677008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7db71325cbfa0abd65c7128cceb18ba8017af399bee5cdd4502d84a988c3865605f0c5d34f858af352c1520b401651723fbf1c2335d652ec45f9ef0308a675bb
|
7
|
+
data.tar.gz: 44082fc8ad08369ea9e578f6cb3a11ec3dd7f92445b63ef4d415e10e14c79e350ded3a39828821b613513c382fd71b72db9b0669e7c14bd2e900655e03cffa5d
|
data/.github/workflows/main.yml
CHANGED
@@ -11,19 +11,19 @@ jobs:
|
|
11
11
|
strategy:
|
12
12
|
matrix:
|
13
13
|
os: [ubuntu-latest, macos-latest]
|
14
|
-
|
14
|
+
ruby-version: ['3.1', '3.0', '2.7']
|
15
15
|
rails: ['5.0', '5.1', '5.2', '6.0', '6.1', '7.0']
|
16
16
|
|
17
17
|
runs-on: ${{ matrix.os }}
|
18
|
-
name: ruby ${{ matrix.
|
18
|
+
name: ruby ${{ matrix.ruby-version }}, rails ${{ matrix.rails }}, ${{ matrix.os }}
|
19
19
|
|
20
20
|
steps:
|
21
21
|
- uses: actions/checkout@v2
|
22
22
|
|
23
|
-
- name: Set up Ruby ${{ matrix.
|
23
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
24
24
|
uses: ruby/setup-ruby@v1
|
25
25
|
with:
|
26
|
-
|
26
|
+
ruby-version: ${{ matrix.ruby-version }}
|
27
27
|
bundler-cache: true
|
28
28
|
|
29
29
|
- name: Install Gems w/ Rails ${{ matrix.rails }}
|
@@ -40,19 +40,19 @@ jobs:
|
|
40
40
|
test_legacy:
|
41
41
|
strategy:
|
42
42
|
matrix:
|
43
|
-
|
43
|
+
ruby-version: ['2.6', '2.5']
|
44
44
|
rails: ['5.0', '5.1', '5.2']
|
45
45
|
|
46
46
|
runs-on: ubuntu-latest
|
47
|
-
name:
|
47
|
+
name: ruby ${{ matrix.ruby-version }}, rails ${{ matrix.rails }}
|
48
48
|
|
49
49
|
steps:
|
50
50
|
- uses: actions/checkout@v2
|
51
51
|
|
52
|
-
- name: Set up Ruby ${{ matrix.
|
52
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
53
53
|
uses: ruby/setup-ruby@v1
|
54
54
|
with:
|
55
|
-
|
55
|
+
ruby-version: ${{ matrix.ruby-version }}
|
56
56
|
bundler-cache: true
|
57
57
|
|
58
58
|
- name: Install Gems w/ Rails ${{ matrix.rails }}
|
@@ -65,3 +65,33 @@ jobs:
|
|
65
65
|
|
66
66
|
- name: Run tests
|
67
67
|
run: bundle exec rspec
|
68
|
+
|
69
|
+
test_alt_rubies:
|
70
|
+
strategy:
|
71
|
+
matrix:
|
72
|
+
ruby-version: ['jruby', 'truffleruby']
|
73
|
+
rails: ['6.0', '6.1'] # jruby / jdbc-sqlite3 end up tightly bound to rails 6.x
|
74
|
+
|
75
|
+
runs-on: ubuntu-latest
|
76
|
+
name: ${{ matrix.ruby-version }}, rails ${{ matrix.rails }}
|
77
|
+
|
78
|
+
steps:
|
79
|
+
- uses: actions/checkout@v2
|
80
|
+
|
81
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
82
|
+
uses: ruby/setup-ruby@v1
|
83
|
+
with:
|
84
|
+
ruby-version: ${{ matrix.ruby-version }}
|
85
|
+
bundler-cache: true
|
86
|
+
|
87
|
+
- name: Install Gems w/ Rails ${{ matrix.rails }}
|
88
|
+
env:
|
89
|
+
MATRIX_RAILS_VERSION: ${{ matrix.rails }}
|
90
|
+
run: |
|
91
|
+
export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/rails_${MATRIX_RAILS_VERSION}.gemfile"
|
92
|
+
gem install bundler
|
93
|
+
bundle install --jobs 4 --retry 3
|
94
|
+
|
95
|
+
- name: Run tests
|
96
|
+
run: bundle exec rspec
|
97
|
+
|
data/CHANGELOG.md
CHANGED
@@ -1,25 +1,33 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [1.
|
3
|
+
## [2.1.0] - 2022-01-12
|
4
|
+
- change CI matrix for more version compatibility
|
5
|
+
- update gemspec to move some deps into development only
|
6
|
+
- README changes
|
7
|
+
|
8
|
+
## [2.0.0] - 2022-01-07
|
9
|
+
- Require much more recent ruby, to use syntax that's been around since 2017
|
10
|
+
|
11
|
+
## [1.3.0] - 2021-12-31
|
4
12
|
- Add `repeatedly_load` matcher
|
5
13
|
- Add query type matchers for `load_queries`, `schema_queries`, `transaction_queries`, `destroy_queries`
|
6
14
|
- Allow singular version of all query types (e.g. `transaction_queries` vs `transaction_query`)
|
7
15
|
- Fix failure message for `execute.exactly` matcher
|
8
16
|
|
9
|
-
## [1.2.0] -
|
17
|
+
## [1.2.0] - 2021-12-31
|
10
18
|
- Add `query` as a synonym for `queries`
|
11
19
|
- Ignore schema and transaction queries in query count
|
12
20
|
- Add beginning of recording specific query types
|
13
21
|
- Add query count matcher for `exactly`
|
14
22
|
|
15
|
-
## [1.1.0] -
|
23
|
+
## [1.1.0] - 2021-12-30
|
16
24
|
- Add query count matchers for e.g. `less_than_or_equal_to`, `greater_than`
|
17
25
|
|
18
|
-
## [1.0.1] -
|
26
|
+
## [1.0.1] - 2021-12-30
|
19
27
|
- Pin all the dependencies to a proper working subset
|
20
28
|
- Expand testing to many rails / ruby combinations
|
21
29
|
|
22
|
-
## [1.0.0] -
|
30
|
+
## [1.0.0] - 2021-12-30
|
23
31
|
- Basic gem w/ all the fixins and README and such
|
24
32
|
- Add `less_than` comparison, and `queries` type
|
25
33
|
- Basic tests in place, and not bad tbh
|
data/README.md
CHANGED
@@ -30,7 +30,8 @@ group 'test' do
|
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
33
|
-
Then, include the functionality within your
|
33
|
+
Then, include the functionality within your `rails_helper.rb` (or in a support
|
34
|
+
file).
|
34
35
|
|
35
36
|
```ruby
|
36
37
|
RSpec.configure do |config|
|
@@ -109,11 +110,24 @@ This matcher will track ActiveRecord's built in load methods to prevent those
|
|
109
110
|
N+1 situations. Using eager loading (e.g. `Track.all.includes(:album)`) will
|
110
111
|
allow these expectations to pass as expected!
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
### Testing Batch Queries
|
114
|
+
|
115
|
+
If your code loads records in batches, it may be more difficult to create
|
116
|
+
expectations for repeated loading. After all, each batch will execute its own
|
117
|
+
queries, which may look like repeated loading.
|
118
|
+
|
119
|
+
If your test has a small enough number of records that only one batch is
|
120
|
+
loaded, your tests may work just fine. But otherwise, you may want to allow
|
121
|
+
your code to specify a batch size in order to guarantee only a single batch
|
122
|
+
is loaded:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
tracks = Track.all
|
126
|
+
|
127
|
+
expect {
|
128
|
+
TrackSerializer.perform(tracks, batch_size: tracks.count)
|
129
|
+
}.not_to repeatedly_load('Track')
|
130
|
+
```
|
117
131
|
|
118
132
|
## Counting Queries
|
119
133
|
|
@@ -8,7 +8,7 @@ module RSpec::ActiveRecord::Expectations
|
|
8
8
|
def categorize(query)
|
9
9
|
if query[:name] == "SCHEMA"
|
10
10
|
[:schema_queries]
|
11
|
-
elsif query[:name] == "TRANSACTION"
|
11
|
+
elsif query[:name] == "TRANSACTION" || query[:sql] =~ /^begin/i || query[:sql] =~ /^commit/i
|
12
12
|
[:transaction_queries]
|
13
13
|
elsif query[:name] =~ /Create$/
|
14
14
|
[:queries, :insert_queries]
|
@@ -18,7 +18,7 @@ module RSpec::ActiveRecord::Expectations
|
|
18
18
|
[:queries, :destroy_queries]
|
19
19
|
elsif query[:name] =~ /Delete All$/
|
20
20
|
[:queries, :destroy_queries]
|
21
|
-
elsif query[:name] =~ /Exists
|
21
|
+
elsif query[:name] =~ /Exists\??$/
|
22
22
|
[:queries, :exists_queries]
|
23
23
|
else
|
24
24
|
[:queries]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "rspec-activerecord-expectations"
|
3
|
-
spec.version = '1.
|
3
|
+
spec.version = '2.1.0'
|
4
4
|
spec.authors = ["Joseph Mastey"]
|
5
5
|
spec.email = ["hello@joemastey.com"]
|
6
6
|
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.description = %q{Adds new matchers to rspec to help you test whether your code is executing an unreasonable number of queries.}
|
9
9
|
spec.homepage = "https://github.com/jmmastey/rspec-activerecord-expectations"
|
10
10
|
spec.license = "MIT"
|
11
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
11
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
12
12
|
|
13
13
|
spec.metadata["homepage_uri"] = spec.homepage
|
14
14
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -23,7 +23,12 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
25
|
spec.add_dependency "activerecord", ">= 5.0.0", "< 7.1.0"
|
26
|
-
|
26
|
+
|
27
|
+
if RUBY_PLATFORM == 'java'
|
28
|
+
spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", '>= 60'
|
29
|
+
else
|
30
|
+
spec.add_development_dependency "sqlite3", "~> 1.0"
|
31
|
+
end
|
27
32
|
|
28
33
|
spec.add_development_dependency "pry", "~> 0.0"
|
29
34
|
spec.add_development_dependency "appraisal", "~> 2"
|
metadata
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-activerecord-expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Mastey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: activerecord
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
@@ -20,8 +19,9 @@ dependencies:
|
|
20
19
|
- - "<"
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: 7.1.0
|
23
|
-
|
22
|
+
name: activerecord
|
24
23
|
prerelease: false
|
24
|
+
type: :runtime
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
@@ -31,42 +31,42 @@ dependencies:
|
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 7.1.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name: sqlite3
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
36
35
|
requirements:
|
37
|
-
- - "
|
36
|
+
- - ">="
|
38
37
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
40
|
-
|
38
|
+
version: '60'
|
39
|
+
name: activerecord-jdbcsqlite3-adapter
|
41
40
|
prerelease: false
|
41
|
+
type: :development
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '60'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name: pry
|
49
48
|
requirement: !ruby/object:Gem::Requirement
|
50
49
|
requirements:
|
51
50
|
- - "~>"
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: '0.0'
|
54
|
-
|
53
|
+
name: pry
|
55
54
|
prerelease: false
|
55
|
+
type: :development
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name: appraisal
|
63
62
|
requirement: !ruby/object:Gem::Requirement
|
64
63
|
requirements:
|
65
64
|
- - "~>"
|
66
65
|
- !ruby/object:Gem::Version
|
67
66
|
version: '2'
|
68
|
-
|
67
|
+
name: appraisal
|
69
68
|
prerelease: false
|
69
|
+
type: :development
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
@@ -121,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.
|
124
|
+
version: 2.5.0
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
131
|
+
rubygems_version: 3.2.29
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: A gem to test how many activerecord queries your code executes.
|