rails_sql_counter 0.1.1 → 0.2.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: 5bbc30585158b380077f576278e1cbc18ed380793af58e0520f3d843647d8714
4
- data.tar.gz: 9293aababdf01166e3b96b179531e0666efe044fbbd78e95c2f9953d95fc2c3a
3
+ metadata.gz: a3da1f83702e6199bfe68eb3dd67ce419f97b529e157d6e6b1cf4f5ef92f158d
4
+ data.tar.gz: 9ab44fbbed52564fcdb72552843c195dacccfe203299b544fd9d1885fa5cce36
5
5
  SHA512:
6
- metadata.gz: 23b0c23659a1b376cb10c62b79313026e9e5da34b85cb00cb8a09757bf810b8e75e11324657313935dd5f81bbe3142ac28d20d8114204158a6d85755149d1da0
7
- data.tar.gz: d6e364fdfa43a107eff3330d2788786aca3baf0bed37c829b766a07b45e734475136dc33a178d380be2e960e4c30542e60c4d98add0efd4fb9d95fd5d76defac
6
+ metadata.gz: 830489aefd50d4ee2efaa57d2b7cc63a26f9808e084ee59e56b8c31e3325c81dc6aac264e0653e7b5faf73f84dbf7037729a1280d453f277bfd026fee3c8a53e
7
+ data.tar.gz: 66bf1ccdb4f39433ca921b5c012661b9e963c077c07f4f0400383574045fa4a3e6a416de2b153ebd2156349832410c090ced7e2b60a3536bb9ca77f5241cfcb0
data/.gitignore CHANGED
@@ -7,5 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ *.gem
11
+
10
12
  # rspec failure tracking
11
13
  .rspec_status
data/CHANGELOG.md CHANGED
@@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [0.2.0] - 2021-08-25
8
+
9
+ ### Added
10
+ - `.profile` method has been added
11
+ - ActiveSupport has been added as explicit dependency
12
+
13
+ ### Changed
14
+ - `.end` doesn't reset the counter
15
+ - `.process` has been redeclared as private member
16
+
17
+ ## [0.1.1] - 2021-08-18
18
+
19
+ ### Fixed
20
+ - Clean subscriber after end
8
21
 
9
22
  ## [0.1.0] - 2021-08-17
10
23
 
data/Gemfile.lock CHANGED
@@ -2,11 +2,22 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  rails_sql_counter (0.1.1)
5
+ activesupport
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ activesupport (6.1.4.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ concurrent-ruby (1.1.9)
9
17
  diff-lcs (1.4.4)
18
+ i18n (1.8.10)
19
+ concurrent-ruby (~> 1.0)
20
+ minitest (5.14.4)
10
21
  rake (12.3.3)
11
22
  rspec (3.10.0)
12
23
  rspec-core (~> 3.10.0)
@@ -21,6 +32,9 @@ GEM
21
32
  diff-lcs (>= 1.2.0, < 2.0)
22
33
  rspec-support (~> 3.10.0)
23
34
  rspec-support (3.10.2)
35
+ tzinfo (2.0.4)
36
+ concurrent-ruby (~> 1.0)
37
+ zeitwerk (2.4.2)
24
38
 
25
39
  PLATFORMS
26
40
  ruby
data/README.md CHANGED
@@ -29,12 +29,12 @@ Or install it yourself as:
29
29
 
30
30
  * **start**: starts to count sql queries
31
31
  * **end**: ends to count sql queries
32
- * **counter**: returns number of sql quieries from start
32
+ * **counter**: returns number of sql queries from start
33
+ * **profile**: syntax sugar to facilitate start/end
33
34
 
34
35
  ## Usage
35
36
 
36
37
  Test example:
37
-
38
38
  ```ruby
39
39
  context '...' do
40
40
  before { RailsSqlCounter.start }
@@ -46,6 +46,32 @@ context '...' do
46
46
  expect(RailsSqlCounter.counter).to eq(1)
47
47
  end
48
48
  end
49
+
50
+ # You could also use .profile
51
+ context '...' do
52
+ it 'returns results with only one query' do
53
+ RailsSqlCounter.profile { get path }
54
+
55
+ expect(RailsSqlCounter.counter).to eq(1)
56
+ end
57
+ end
58
+ ```
59
+ You may want to wrap the tests as:
60
+
61
+ ```ruby
62
+ config.around(:each, :max_queries) do |example|
63
+ RailsSqlCounter.profile { example.run }
64
+
65
+ if RailsSqlCounter.counter > example.metadata[:max_queries]
66
+ raise 'Maximum number of queries overpassed.'
67
+ end
68
+ end
69
+
70
+ (...)
71
+
72
+ it 'returns results with only one query', max_queries: 1 do
73
+ get path
74
+ end
49
75
  ```
50
76
 
51
77
  ## Development
@@ -1,3 +1,3 @@
1
1
  module RailsSqlCounter
2
- VERSION = "0.1.1"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rails_sql_counter/version'
4
+ require 'active_support'
4
5
 
5
6
  # Count sql queries
6
7
  module RailsSqlCounter
@@ -30,9 +31,14 @@ module RailsSqlCounter
30
31
  end
31
32
  end
32
33
 
33
- def self.end
34
- Thread.current[:rails_sql_counter] = nil
34
+ def self.profile(&block)
35
+ start
36
+ block.call
37
+ ensure
38
+ self.end
39
+ end
35
40
 
41
+ def self.end
36
42
  ActiveSupport::Notifications.unsubscribe(@@subscriber)
37
43
  @@subscriber = nil
38
44
  end
@@ -50,5 +56,5 @@ module RailsSqlCounter
50
56
  end
51
57
  end
52
58
 
53
- private_class_method :inc, :show_backtrace
59
+ private_class_method :inc, :show_backtrace, :process
54
60
  end
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.bindir = 'exe'
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'activesupport'
23
25
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_sql_counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-19 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Allows to control how many queries are launched between two points
14
28
  email:
15
29
  - rjurado@nosolosoftware.es
@@ -49,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
63
  - !ruby/object:Gem::Version
50
64
  version: '0'
51
65
  requirements: []
52
- rubygems_version: 3.1.4
66
+ rubygems_version: 3.1.2
53
67
  signing_key:
54
68
  specification_version: 4
55
69
  summary: Keep under control how many sql queries are launched in your App