rspec-sqlimit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb112af9504128b90adde574c3ec62eb7853a35e
4
- data.tar.gz: 5a7a2d7ed16fc1224168435263f27d59e943530d
2
+ SHA256:
3
+ metadata.gz: 17f8ef5a19ac39f9a9a2c67a32a196de82bf9b1764f04f4101b8cb57ff182799
4
+ data.tar.gz: 15cd5e3c7c9f8b035240eb0028ff03686f75b1812d6c215b9388f697f0c83423
5
5
  SHA512:
6
- metadata.gz: 943305eafecad8557ed1ef7baaca8eb02ae9c2f05da61f538c6412fb49a568ac5df7e686c8455b47fc20d919ade80704d071e328197c51d54b96e6699d7b8b24
7
- data.tar.gz: 8cede3b49a91a9ce2ab17869e94fa4a674c157ecd7043f73a95a0d25552fb51e63b4648a7cc2c2c1320642233f585234137a087ca71a2954f6c7c3b34a50af58
6
+ metadata.gz: 3f902b99903af0400fbe4ed04609de1abecfd5c24568eb0a4a65123d115da82de09b1bdbae7b7ec4637a461378f77a939af9aaa9a1fd1db2aabd6232ff824b1d
7
+ data.tar.gz: bf775886da70792c4cb468297ce6e85910e26a17a3ce6661d3ddd6177027213d312819309d76f5588bca13b3b1aaffe2dfff04d2c96f0743f506765a60748913
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
+ /gemfiles/*.gemfile.lock
4
5
  /_yardoc/
5
6
  /coverage/
6
7
  /doc/
@@ -8,3 +9,6 @@
8
9
  /spec/reports/
9
10
  /tmp/
10
11
  /spec/dummy/db/*.sqlite3
12
+ *.gem
13
+ .rspec_status
14
+ .idea/
@@ -3,10 +3,11 @@ AllCops:
3
3
  DisplayCopNames: true
4
4
  DisplayStyleGuide: true
5
5
  StyleGuideCopsOnly: true
6
- TargetRubyVersion: 2.3
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
- EnforcedStyle: compact
18
+ Enabled: false
18
19
 
19
20
  Style/FileName:
20
21
  Enabled: false
@@ -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.0
13
+ - 2.3
14
+ - 2.6
9
15
  - ruby-head
10
- before_install: gem install bundler
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
@@ -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
@@ -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
@@ -3,6 +3,9 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in tram-form.gemspec
4
4
  gemspec
5
5
 
6
+ gem "rails"
7
+ gem "sqlite3"
8
+
6
9
  group :test, :development do
7
10
  gem "pry"
8
11
  gem "pry-byebug"
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(dummy:db:create dummy:db:migrate) do
12
- system "bundle exec rspec spec"
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
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+ gem "sqlite3", "~> 1.3.0"
7
+
8
+ group :test, :development do
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+ gem "sqlite3", "~> 1.3.0"
7
+
8
+ group :test, :development do
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.1.0"
6
+ gem "sqlite3", "~> 1.3.0"
7
+
8
+ group :test, :development do
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.0"
6
+ gem "sqlite3", "~> 1.4"
7
+
8
+ group :test, :development do
9
+ gem "pry"
10
+ gem "pry-byebug"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -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(CACHE SCHEMA).include? values[:name]
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} (#{query[:duration].round(3)} ms)"
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "rspec-sqlimit"
3
- gem.version = "0.0.2"
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.0", "< 6.0"
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.44"
24
+ gem.add_development_dependency "rubocop", "~> 0.49"
24
25
  end
@@ -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: 20170211104800) do
13
+ ActiveRecord::Schema.define(version: 2017_02_11_104800) do
14
14
 
15
15
  create_table "users", force: :cascade do |t|
16
16
  end
@@ -2,6 +2,7 @@ require "active_record"
2
2
  require "bundler/setup"
3
3
 
4
4
  module Dummy
5
+ require_relative "dummy/compatibility"
5
6
  require_relative "dummy/application"
6
7
  require_relative "../config/environment"
7
8
  require_relative "../app/models/user.rb"
@@ -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 'no params were passed to the query' do
7
- let(:counter) { RSpec::SQLimit::Counter[/CREATE/, Proc.new{ User.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 'query contains params' do
16
- context 'nil was passed as param' do
17
- let(:counter) { RSpec::SQLimit::Counter[/CREATE/, Proc.new{ User.create(id: nil) }] }
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 'single param was passed' do
26
- let(:counter) { RSpec::SQLimit::Counter[/CREATE/, Proc.new{ User.create(id: 1) }] }
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 'prints param as an array with one element' do
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 'array was passed as a param' do
35
- let(:counter) { RSpec::SQLimit::Counter[/SELECT/, Proc.new{ User.where(id: [1, 2, 3]).to_a }] }
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 'prints all params' do
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
- expect(subject.call).to include("IN (1, 2, 3)")
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
@@ -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 }.to exceed_query_limit(0).with(/SELECT/)
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.2
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: 2017-06-17 00:00:00.000000000 Z
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.0'
19
+ version: '4.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.0'
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.0'
29
+ version: '4.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.0'
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.44'
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.44'
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
- rubyforge_project:
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