rspec-sql 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec/sql/query_summary.rb +47 -0
- data/lib/rspec/sql.rb +8 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 604f3e80d1493fef761a5cd6c4cc1f2b16ddeaea989fd06a52f6e5266c30a015
|
4
|
+
data.tar.gz: caf7ab6da1bb00e2c49fae1be3ca2ed8c787adab7f3983e02ac0972f410f1140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fecdb314d1af946b4c1d37807f25ece49c3d0ce2a969984c7d8ac9ec325afee4359021e3623792a85085c0c77e17f1510b568f7d43733eb0a12ee6151cf4e1bb
|
7
|
+
data.tar.gz: 01afcbf7343a73735ade838e1b0c1991cd8d4b62d9d38a9e75fc5c66b34c3d1fd34b38b8a97d3ddb9b297781624237e250e1775012f2e2cb4451240d62e90a14
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Sql
|
5
|
+
class QuerySummary
|
6
|
+
QUERY_TYPES = [:delete, :insert, :select, :update].freeze
|
7
|
+
|
8
|
+
attr_reader :summary
|
9
|
+
|
10
|
+
def initialize(queries)
|
11
|
+
@summary = {}
|
12
|
+
queries.each do |payload|
|
13
|
+
type = get_type(payload[:sql])
|
14
|
+
next if QUERY_TYPES.exclude?(type) || pg_query?(payload[:sql])
|
15
|
+
|
16
|
+
table = get_table(payload[:sql])
|
17
|
+
@summary[type] ||= {}
|
18
|
+
@summary[type][table] ||= 0
|
19
|
+
@summary[type][table] += 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def get_table(sql)
|
26
|
+
sql_parts = sql.split
|
27
|
+
case get_type(sql)
|
28
|
+
when :insert
|
29
|
+
sql_parts[2]
|
30
|
+
when :update
|
31
|
+
sql_parts[1]
|
32
|
+
else
|
33
|
+
table_index = sql_parts.index("FROM")
|
34
|
+
sql_parts[table_index + 1]
|
35
|
+
end.gsub(/(\\|")/, "").to_sym
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_type(sql)
|
39
|
+
sql.split[0].downcase.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
def pg_query?(sql)
|
43
|
+
sql.include?("SELECT a.attname") || sql.include?("pg_attribute")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/rspec/sql.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require "active_support"
|
4
4
|
require "rspec"
|
5
5
|
|
6
|
+
require_relative "sql/query_summary"
|
7
|
+
|
6
8
|
module RSpec
|
7
9
|
module Sql; end
|
8
10
|
|
@@ -18,6 +20,8 @@ module RSpec
|
|
18
20
|
@queries.size == expected.size
|
19
21
|
elsif expected.is_a?(Array)
|
20
22
|
query_names == expected
|
23
|
+
elsif expected.is_a?(Hash)
|
24
|
+
query_summary == expected
|
21
25
|
else
|
22
26
|
raise "What are you expecting?"
|
23
27
|
end
|
@@ -52,6 +56,10 @@ module RSpec
|
|
52
56
|
@queries.map { |q| "#{q[:name]} #{q[:sql]}" }
|
53
57
|
end
|
54
58
|
|
59
|
+
def query_summary
|
60
|
+
Sql::QuerySummary.new(@queries).summary
|
61
|
+
end
|
62
|
+
|
55
63
|
def scribe_queries(&)
|
56
64
|
queries = []
|
57
65
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maikel Linke
|
8
|
-
|
8
|
+
- Open Food Network contributors
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2024-
|
12
|
+
date: 2024-03-01 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
@@ -45,11 +46,12 @@ extensions: []
|
|
45
46
|
extra_rdoc_files: []
|
46
47
|
files:
|
47
48
|
- lib/rspec/sql.rb
|
49
|
+
- lib/rspec/sql/query_summary.rb
|
48
50
|
homepage: https://github.com/openfoodfoundation/rspec-sql
|
49
51
|
licenses:
|
50
52
|
- AGPL-3.0-or-later
|
51
53
|
metadata: {}
|
52
|
-
post_install_message:
|
54
|
+
post_install_message:
|
53
55
|
rdoc_options: []
|
54
56
|
require_paths:
|
55
57
|
- lib
|
@@ -68,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
70
|
version: '0'
|
69
71
|
requirements: []
|
70
72
|
rubygems_version: 3.3.26
|
71
|
-
signing_key:
|
73
|
+
signing_key:
|
72
74
|
specification_version: 4
|
73
75
|
summary: RSpec::Sql matcher
|
74
76
|
test_files: []
|