rspec-sqlimit 0.0.2 → 0.0.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 +5 -5
- data/.gitignore +4 -0
- data/.rubocop.yml +4 -3
- data/.travis.yml +17 -2
- data/Appraisals +19 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -0
- data/Rakefile +18 -2
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4.2.gemfile +13 -0
- data/gemfiles/rails_5.0.gemfile +13 -0
- data/gemfiles/rails_5.1.gemfile +13 -0
- data/gemfiles/rails_6.0.gemfile +13 -0
- data/lib/rspec/sqlimit/counter.rb +13 -2
- data/lib/rspec/sqlimit/reporter.rb +3 -2
- data/rspec-sqlimit.gemspec +4 -3
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/lib/dummy.rb +1 -0
- data/spec/dummy/lib/dummy/compatibility.rb +11 -0
- data/spec/rspec/sqlimit/reporter_spec.rb +43 -12
- data/spec/rspec/sqlimit_spec.rb +3 -1
- metadata +31 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 17f8ef5a19ac39f9a9a2c67a32a196de82bf9b1764f04f4101b8cb57ff182799
|
4
|
+
data.tar.gz: 15cd5e3c7c9f8b035240eb0028ff03686f75b1812d6c215b9388f697f0c83423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f902b99903af0400fbe4ed04609de1abecfd5c24568eb0a4a65123d115da82de09b1bdbae7b7ec4637a461378f77a939af9aaa9a1fd1db2aabd6232ff824b1d
|
7
|
+
data.tar.gz: bf775886da70792c4cb468297ce6e85910e26a17a3ce6661d3ddd6177027213d312819309d76f5588bca13b3b1aaffe2dfff04d2c96f0743f506765a60748913
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -3,10 +3,11 @@ AllCops:
|
|
3
3
|
DisplayCopNames: true
|
4
4
|
DisplayStyleGuide: true
|
5
5
|
StyleGuideCopsOnly: true
|
6
|
-
TargetRubyVersion: 2.
|
6
|
+
TargetRubyVersion: 2.6
|
7
7
|
Exclude:
|
8
8
|
- spec/dummy/db/schema.rb
|
9
|
-
|
9
|
+
- vendor/bundle/**/*
|
10
|
+
- gemfiles/vendor/**/*
|
10
11
|
Metrics/ParameterLists:
|
11
12
|
Max: 5
|
12
13
|
|
@@ -14,7 +15,7 @@ Style/Alias:
|
|
14
15
|
Enabled: false
|
15
16
|
|
16
17
|
Style/ClassAndModuleChildren:
|
17
|
-
|
18
|
+
Enabled: false
|
18
19
|
|
19
20
|
Style/FileName:
|
20
21
|
Enabled: false
|
data/.travis.yml
CHANGED
@@ -2,12 +2,27 @@
|
|
2
2
|
sudo: false
|
3
3
|
language: ruby
|
4
4
|
cache: bundler
|
5
|
+
before_install:
|
6
|
+
- gem update --system
|
7
|
+
- gem uninstall -v '>= 1' -i $(rvm gemdir)@global -ax bundler || true
|
8
|
+
- gem install bundler -v 1.3.0
|
9
|
+
- gem update --system
|
5
10
|
script:
|
6
11
|
- bundle exec rake
|
7
12
|
rvm:
|
8
|
-
- 2.3
|
13
|
+
- 2.3
|
14
|
+
- 2.6
|
9
15
|
- ruby-head
|
10
|
-
|
16
|
+
gemfile:
|
17
|
+
- gemfiles/rails_4.2.gemfile
|
18
|
+
- gemfiles/rails_5.0.gemfile
|
19
|
+
- gemfiles/rails_5.1.gemfile
|
20
|
+
- gemfiles/rails_6.0.gemfile
|
11
21
|
matrix:
|
22
|
+
exclude:
|
23
|
+
- rvm: 2.3
|
24
|
+
gemfile: gemfiles/rails_6.0.gemfile
|
25
|
+
- rvm: ruby-head
|
26
|
+
gemfile: gemfiles/rails_4.2.gemfile
|
12
27
|
allow_failures:
|
13
28
|
- rvm: ruby-head
|
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
appraise "rails-4.2" do
|
2
|
+
gem "rails", "~> 4.2.0"
|
3
|
+
gem "sqlite3", "~> 1.3.0"
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "rails-5.0" do
|
7
|
+
gem "rails", "~> 5.0.0"
|
8
|
+
gem "sqlite3", "~> 1.3.0"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "rails-5.1" do
|
12
|
+
gem "rails", "~> 5.1.0"
|
13
|
+
gem "sqlite3", "~> 1.3.0"
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise "rails-6.0" do
|
17
|
+
gem "rails", "~> 6.0.0"
|
18
|
+
gem "sqlite3", "~> 1.4"
|
19
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [0.0.3] - [2019-10-02]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Support of Rails 6 (@quikly)
|
12
|
+
- Cached queries are ignored (@tyok)
|
13
|
+
|
8
14
|
## [0.0.2] - [2017-05-17]
|
9
15
|
|
10
16
|
### Added
|
@@ -16,3 +22,4 @@ This is a first public release (@nepalez)
|
|
16
22
|
[Unreleased]: https://github.com/tram-rb/tram-policy
|
17
23
|
[0.0.1]: https://github.com/nepalez/rspec-sqlimit/releases/tag/v0.0.1
|
18
24
|
[0.0.2]: https://github.com/nepalez/rspec-sqlimit/compare/v0.0.1...v0.0.2
|
25
|
+
[0.0.3]: https://github.com/nepalez/rspec-sqlimit/compare/v0.0.2...v0.0.3
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -7,7 +7,23 @@ require "rspec/core/rake_task"
|
|
7
7
|
load "spec/dummy/Rakefile"
|
8
8
|
|
9
9
|
# Declares gem's own tasks.
|
10
|
+
desc "Runs test suite over all rails versions."
|
11
|
+
task :default do
|
12
|
+
if ENV["BUNDLE_GEMFILE"] =~ /gemfiles/
|
13
|
+
Rake::Task["dummy:db:create"].reenable
|
14
|
+
Rake::Task["dummy:db:migrate"].reenable
|
15
|
+
Rake::Task[:spec].invoke
|
16
|
+
else
|
17
|
+
Rake::Task[:appraise].invoke
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
desc "Runs test suite."
|
11
|
-
task default: %w
|
12
|
-
|
22
|
+
task default: %w[dummy:db:create dummy:db:migrate] do
|
23
|
+
exec "bundle exec rspec spec"
|
24
|
+
exec "bundle exec rubocop"
|
25
|
+
end
|
26
|
+
|
27
|
+
task :appraise do
|
28
|
+
exec "appraisal install && appraisal rake"
|
13
29
|
end
|
@@ -30,13 +30,24 @@ module RSpec::SQLimit
|
|
30
30
|
|
31
31
|
def callback
|
32
32
|
@callback ||= lambda do |_name, start, finish, _message_id, values|
|
33
|
-
return if %w
|
33
|
+
return if %w[CACHE SCHEMA].include? values[:name]
|
34
|
+
return if cached_query?(values)
|
34
35
|
queries << {
|
35
36
|
sql: values[:sql],
|
36
37
|
duration: (finish - start) * 1_000,
|
37
|
-
binds: values[:type_casted_binds]
|
38
|
+
binds: values[:type_casted_binds] || type_cast(values[:binds])
|
38
39
|
}
|
39
40
|
end
|
40
41
|
end
|
42
|
+
|
43
|
+
def type_cast(binds)
|
44
|
+
binds.map do |column, value|
|
45
|
+
ActiveRecord::Base.connection.type_cast(value, column)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def cached_query?(values)
|
50
|
+
values[:type_casted_binds].respond_to?(:call)
|
51
|
+
end
|
41
52
|
end
|
42
53
|
end
|
@@ -28,8 +28,9 @@ module RSpec::SQLimit
|
|
28
28
|
|
29
29
|
def line(query, index)
|
30
30
|
prefix = (matcher && query[:sql] =~ matcher) ? "->" : " "
|
31
|
-
binds = query[:binds].any? ? "; #{query[:binds]} " :
|
32
|
-
"#{prefix} #{index + 1}) #{query[:sql]}#{binds}
|
31
|
+
binds = query[:binds].any? ? "; #{query[:binds]} " : ""
|
32
|
+
"#{prefix} #{index + 1}) #{query[:sql]}#{binds}" \
|
33
|
+
" (#{query[:duration].round(3)} ms)"
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
data/rspec-sqlimit.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "rspec-sqlimit"
|
3
|
-
gem.version = "0.0.
|
3
|
+
gem.version = "0.0.3"
|
4
4
|
gem.author = "Andrew Kozin (nepalez)"
|
5
5
|
gem.email = "andrew.kozin@gmail.com"
|
6
6
|
gem.homepage = "https://github.com/nepalez/rspec-sqlimit"
|
@@ -13,12 +13,13 @@ Gem::Specification.new do |gem|
|
|
13
13
|
|
14
14
|
gem.required_ruby_version = ">= 2.3"
|
15
15
|
|
16
|
-
gem.add_runtime_dependency "rails", "> 4.
|
16
|
+
gem.add_runtime_dependency "rails", "> 4.2", "< 7.0"
|
17
17
|
gem.add_runtime_dependency "rspec", "~> 3.0"
|
18
18
|
|
19
|
+
gem.add_development_dependency "appraisal", "~> 2.2"
|
19
20
|
gem.add_development_dependency "rspec", "~> 3.0"
|
20
21
|
gem.add_development_dependency "rake", "> 10.0"
|
21
22
|
gem.add_development_dependency "sqlite3", "~> 1.3"
|
22
23
|
gem.add_development_dependency "database_cleaner", "~> 1.5"
|
23
|
-
gem.add_development_dependency "rubocop", "~> 0.
|
24
|
+
gem.add_development_dependency "rubocop", "~> 0.49"
|
24
25
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2017_02_11_104800) do
|
14
14
|
|
15
15
|
create_table "users", force: :cascade do |t|
|
16
16
|
end
|
data/spec/dummy/lib/dummy.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# ActiveRecord::Migration['5.0'] syntax is not supported prior to Rails 5.0
|
2
|
+
# This snippet supports it on Rails 4.2
|
3
|
+
unless ActiveRecord::Migration.respond_to?(:[])
|
4
|
+
class ActiveRecord::Migration
|
5
|
+
class << self
|
6
|
+
def [](_version)
|
7
|
+
self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -3,8 +3,8 @@ require "spec_helper"
|
|
3
3
|
describe RSpec::SQLimit::Reporter do
|
4
4
|
subject { described_class.new(counter) }
|
5
5
|
|
6
|
-
context
|
7
|
-
let(:counter) { RSpec::SQLimit::Counter[/CREATE/,
|
6
|
+
context "no params were passed to the query" do
|
7
|
+
let(:counter) { RSpec::SQLimit::Counter[/CREATE/, proc{ User.create }] }
|
8
8
|
|
9
9
|
it "doesn't print binds" do
|
10
10
|
# INSERT INTO "users" DEFAULT VALUES (0.284 ms)
|
@@ -12,9 +12,11 @@ describe RSpec::SQLimit::Reporter do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context
|
16
|
-
context
|
17
|
-
let(:counter)
|
15
|
+
context "query contains params" do
|
16
|
+
context "nil was passed as param" do
|
17
|
+
let(:counter) do
|
18
|
+
RSpec::SQLimit::Counter[/CREATE/, proc { User.create(id: nil) }]
|
19
|
+
end
|
18
20
|
|
19
21
|
it "doesn't print binds" do
|
20
22
|
# INSERT INTO "users" DEFAULT VALUES (0.284 ms)
|
@@ -22,22 +24,51 @@ describe RSpec::SQLimit::Reporter do
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
context
|
26
|
-
let(:counter)
|
27
|
+
context "single param was passed" do
|
28
|
+
let(:counter) do
|
29
|
+
RSpec::SQLimit::Counter[/CREATE/, proc { User.create(id: 1) }]
|
30
|
+
end
|
27
31
|
|
28
|
-
it
|
32
|
+
it "prints param as an array with one element" do
|
29
33
|
# INSERT INTO "users" ("id") VALUES (?); [1] (0.234 ms)
|
30
34
|
expect(subject.call).to include("VALUES (?); [1]")
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
34
|
-
context
|
35
|
-
let(:counter)
|
38
|
+
context "array was passed as a param" do
|
39
|
+
let(:counter) do
|
40
|
+
RSpec::SQLimit::Counter[
|
41
|
+
/SELECT/, proc { User.where(id: [1, 2, 3]).to_a }
|
42
|
+
]
|
43
|
+
end
|
36
44
|
|
37
|
-
it
|
45
|
+
it "prints all params" do
|
46
|
+
# rubocop: disable Metrics/LineLength
|
38
47
|
# SELECT "users".* FROM "users" WHERE "users"."id" IN (1, 2, 3) (0.17 ms))
|
39
|
-
|
48
|
+
# Rails >= 6:
|
49
|
+
# SELECT "users".* FROM "users" WHERE "users"."id" IN (?, ?, ?); [1, 2, 3] (0.121 ms)
|
50
|
+
# rubocop: enable Metrics/LineLength
|
51
|
+
expect(subject.call).to include("1, 2, 3")
|
40
52
|
end
|
41
53
|
end
|
42
54
|
end
|
55
|
+
|
56
|
+
context "activerecord query caching was enabled" do
|
57
|
+
let(:counter) do
|
58
|
+
RSpec::SQLimit::Counter[/SELECT "users"/, proc { queries }]
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:queries) do
|
62
|
+
User.cache do
|
63
|
+
User.where(id: 1).to_a
|
64
|
+
User.where(id: 1).to_a
|
65
|
+
User.where(id: [2, 3]).to_a
|
66
|
+
User.where(id: [2, 3]).to_a
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "ignores cached queries" do
|
71
|
+
expect(subject.call).to include("2 queries were invoked")
|
72
|
+
end
|
73
|
+
end
|
43
74
|
end
|
data/spec/rspec/sqlimit_spec.rb
CHANGED
@@ -33,7 +33,9 @@ describe "exceed_query_limit" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "works when array is used as a restriction" do
|
36
|
-
expect { (User.where id: [1, 2, 3]).to_a }
|
36
|
+
expect { (User.where id: [1, 2, 3]).to_a }
|
37
|
+
.to exceed_query_limit(0)
|
38
|
+
.with(/SELECT/)
|
37
39
|
end
|
38
40
|
|
39
41
|
it "works when actual number of queries is below the limit" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sqlimit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin (nepalez)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '4.
|
19
|
+
version: '4.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '4.
|
29
|
+
version: '4.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rspec
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: appraisal
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.2'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.2'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: rspec
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,14 +120,14 @@ dependencies:
|
|
106
120
|
requirements:
|
107
121
|
- - "~>"
|
108
122
|
- !ruby/object:Gem::Version
|
109
|
-
version: '0.
|
123
|
+
version: '0.49'
|
110
124
|
type: :development
|
111
125
|
prerelease: false
|
112
126
|
version_requirements: !ruby/object:Gem::Requirement
|
113
127
|
requirements:
|
114
128
|
- - "~>"
|
115
129
|
- !ruby/object:Gem::Version
|
116
|
-
version: '0.
|
130
|
+
version: '0.49'
|
117
131
|
description:
|
118
132
|
email: andrew.kozin@gmail.com
|
119
133
|
executables: []
|
@@ -127,11 +141,17 @@ files:
|
|
127
141
|
- ".rspec"
|
128
142
|
- ".rubocop.yml"
|
129
143
|
- ".travis.yml"
|
144
|
+
- Appraisals
|
130
145
|
- CHANGELOG.md
|
131
146
|
- Gemfile
|
132
147
|
- LICENSE.txt
|
133
148
|
- README.md
|
134
149
|
- Rakefile
|
150
|
+
- gemfiles/.bundle/config
|
151
|
+
- gemfiles/rails_4.2.gemfile
|
152
|
+
- gemfiles/rails_5.0.gemfile
|
153
|
+
- gemfiles/rails_5.1.gemfile
|
154
|
+
- gemfiles/rails_6.0.gemfile
|
135
155
|
- lib/rspec-sqlimit.rb
|
136
156
|
- lib/rspec/sqlimit.rb
|
137
157
|
- lib/rspec/sqlimit/counter.rb
|
@@ -145,6 +165,7 @@ files:
|
|
145
165
|
- spec/dummy/db/schema.rb
|
146
166
|
- spec/dummy/lib/dummy.rb
|
147
167
|
- spec/dummy/lib/dummy/application.rb
|
168
|
+
- spec/dummy/lib/dummy/compatibility.rb
|
148
169
|
- spec/rspec/sqlimit/reporter_spec.rb
|
149
170
|
- spec/rspec/sqlimit_spec.rb
|
150
171
|
- spec/spec_helper.rb
|
@@ -167,8 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
188
|
- !ruby/object:Gem::Version
|
168
189
|
version: '0'
|
169
190
|
requirements: []
|
170
|
-
|
171
|
-
rubygems_version: 2.5.2
|
191
|
+
rubygems_version: 3.0.6
|
172
192
|
signing_key:
|
173
193
|
specification_version: 4
|
174
194
|
summary: RSpec matcher to control SQL queries made by block of code
|
@@ -181,6 +201,7 @@ test_files:
|
|
181
201
|
- spec/dummy/db/schema.rb
|
182
202
|
- spec/dummy/lib/dummy.rb
|
183
203
|
- spec/dummy/lib/dummy/application.rb
|
204
|
+
- spec/dummy/lib/dummy/compatibility.rb
|
184
205
|
- spec/rspec/sqlimit/reporter_spec.rb
|
185
206
|
- spec/rspec/sqlimit_spec.rb
|
186
207
|
- spec/spec_helper.rb
|