sql_spy 0.3.0 → 0.4.0

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
2
  SHA256:
3
- metadata.gz: 98d9ae168c842d388db04918e4abf010ab0ece285bc4cad77d44b6606305c916
4
- data.tar.gz: acfa349aeec0b8f003dd21b36286e923fb697709b7b07d4ca57abd6c1ff80823
3
+ metadata.gz: d7fe6bcb2e50a0d51ae186f60566422043ab6a8dbb159a1cc26221654954521f
4
+ data.tar.gz: 9ed63e719d938fdbc94c1f44d2f304532dcc5ee28bedaef449b92db8a5ab38ab
5
5
  SHA512:
6
- metadata.gz: e464cc84c62c58935b5d3e8769b776a668edbfef35d51a7d0d0fc0f7de99b0545fcacc3a247dfc913ae4b2319c3bd5ce65856a581de3641a3173837f190aaf5a
7
- data.tar.gz: 547c8b53ae652c54be10b3d9e77b6c4dd9a882957d64e11c3b7903df988eb5229d6e48599f88f1497d5a9c5d6cbd9fe5590d73a6e7b371a8cad5167cd9d194c5
6
+ metadata.gz: 6c36e3858fd1dfdc83ab06538a245d0061721054bb2e17bcd5d9774a6fab23561cd7eedc0ae463f79c92eda415a52d2c430d4946dade83544fa8126382f1692f
7
+ data.tar.gz: d79894d45d4c62765e56bbd3b749a3d5f772366f4e91836eda77161bc45e6dab5cf6d7be91a48e5b6847faa1ffc4339261db72a17008109ab40e99c156b8a57d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sql_spy (0.2.0)
4
+ sql_spy (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,10 +4,19 @@
4
4
 
5
5
  A gem to track all SQL queries performed inside a block of code.
6
6
 
7
- You can use **SqlSpy** to test the total amount of queries performed by a piece of code, the amount of queries per table, selects vs. inserts vs. updates vs. deletes, or query duration. You can also use it to validate and debug your SQL or to prevent N+1 queries.
7
+ With **SqlSpy** you can test:
8
+
9
+ - The total amount of queries performed by a piece of code
10
+ - The amount of queries performed on a specific table
11
+ - The type of these queries: *SELECT*, *INSERT*, *UPDATE*, *DELETE*
12
+ - The query duration
13
+ - The SQL produced by your *ActiveRecord* code
14
+ - N+1 queries
8
15
 
9
16
  The implementation is inspired by how [ActiveRecord is tested](https://github.com/rails/rails/blob/6-0-stable/activerecord/test/cases/test_case.rb).
10
17
 
18
+ Check out [my blog post](https://lipanski.com/posts/activerecord-eager-loading#preventing-n1-regressions-with-tests) about writing controller tests with **SqlSpy** in order to prevent N+1 regressions.
19
+
11
20
  ## Usage
12
21
 
13
22
  Add the gem to your `Gemfile`:
@@ -16,7 +25,7 @@ Add the gem to your `Gemfile`:
16
25
  gem "sql_spy"
17
26
  ```
18
27
 
19
- ...and install it with:
28
+ Install it:
20
29
 
21
30
  ```sh
22
31
  bundle install
@@ -42,7 +51,7 @@ The `SqlSpy.track` method will return **an array containing all the queries perf
42
51
  - `#update?`: Is this an *UPDATE* query?
43
52
  - `#delete?`: Is this a *DELETE* query?
44
53
 
45
- Here are some **ideas** for how you could use this:
54
+ Here are some **ideas** of how you could use this:
46
55
 
47
56
  ```ruby
48
57
  # Expect less than 5 queries
@@ -57,7 +66,7 @@ assert_equal 2, queries.select { |query| query.model_name == "Post" }.size
57
66
  # None of the queries should be slower than 100ms
58
67
  assert queries.none? { |query| query.duration > 100 }
59
68
 
60
- # Fail on N+1 queries: expect no more than 1 query per table
69
+ # Fail on N+1 queries: expect at most 1 query per table
61
70
  queries_by_model = queries.group_by(&:model_name)
62
71
  assert queries_by_model.none? { |model_name, queries| queries.count > 1 }
63
72
  ```
@@ -69,7 +78,7 @@ The gem is tested with Postgres 9.6 and SQLite 3.
69
78
  To run tests with SQLite:
70
79
 
71
80
  ```sh
72
- bundle exec rake
81
+ rake
73
82
  ```
74
83
 
75
84
  To run tests with Postgres:
@@ -78,7 +87,7 @@ To run tests with Postgres:
78
87
  # Create a test database
79
88
  cretedb sql_spy_test
80
89
 
81
- DATABASE_URL=postgres:///sql_spy_test bundle exec rake
90
+ DATABASE_URL=postgres:///sql_spy_test rake
82
91
  ```
83
92
 
84
93
  ## License
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sql_spy"
3
- spec.version = "0.3.0"
3
+ spec.version = "0.4.0"
4
4
  spec.authors = ["Florin Lipan"]
5
5
  spec.email = ["florinlipan@gmail.com"]
6
6
 
7
- spec.summary = %q{A gem to track SQL queries triggered by a particular block of code}
7
+ spec.summary = %q{A gem to track all SQL queries performed inside a block of code}
8
8
  spec.homepage = "https://github.com/lipanski/sql-spy"
9
9
  spec.license = "MIT"
10
10
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_spy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florin Lipan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -24,10 +24,8 @@ files:
24
24
  - LICENSE.txt
25
25
  - README.md
26
26
  - Rakefile
27
- - bin/console
28
- - bin/setup
29
27
  - lib/sql_spy.rb
30
- - sql-spy.gemspec
28
+ - sql_spy.gemspec
31
29
  homepage: https://github.com/lipanski/sql-spy
32
30
  licenses:
33
31
  - MIT
@@ -53,5 +51,5 @@ requirements: []
53
51
  rubygems_version: 3.1.2
54
52
  signing_key:
55
53
  specification_version: 4
56
- summary: A gem to track SQL queries triggered by a particular block of code
54
+ summary: A gem to track all SQL queries performed inside a block of code
57
55
  test_files: []
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "sql/spy"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here