sql_query 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -2
- data/lib/sql_query.rb +5 -1
- data/spec/sql_query_spec.rb +22 -11
- data/sql_query.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8726a8dd720904305975d654dca7d89e6f15c5c
|
4
|
+
data.tar.gz: 7a9756044cde8b2658ba19e1246f62cbae1bdf2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19a3717cfaf7c5465a7c8c5ed289cfbcfe55bba972951a58a82665b38382a75009a1af08486de8b1a748e9240afa1679e31814f25d21116c8ee422872e0a4551
|
7
|
+
data.tar.gz: 3b9e8c25f91d635e3225c47c5f36f1718879519791ce017ea620cfec1bd204e633104dda4fb6a361a00b191d841c44e4227e347dfa73ed3cada1ce30d760ce7a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SqlQuery change log
|
2
2
|
|
3
|
-
## 0.7.
|
3
|
+
## 0.7.4 / Unreleased
|
4
4
|
|
5
5
|
* [Added]
|
6
6
|
|
@@ -10,9 +10,14 @@
|
|
10
10
|
|
11
11
|
* [Fixed]
|
12
12
|
|
13
|
+
## 0.7.3 / 2023-02-04
|
14
|
+
|
15
|
+
* [Fixed] when sql parameter had multiple whitespaces than prepared_for_logs was changing them
|
16
|
+
to single space. https://github.com/sufleR/sql_query/pull/17
|
17
|
+
|
13
18
|
## 0.7.2 / 2022-01-23
|
14
19
|
|
15
|
-
* [Added] rails
|
20
|
+
* [Added] rails 7.0 as supported version https://github.com/sufleR/sql_query/pull/12
|
16
21
|
|
17
22
|
## 0.7.1 / 2021-12-14
|
18
23
|
|
data/lib/sql_query.rb
CHANGED
@@ -46,7 +46,11 @@ class SqlQuery
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def prepared_for_logs
|
49
|
-
sql
|
49
|
+
sql
|
50
|
+
.split("'")
|
51
|
+
.each_with_index
|
52
|
+
.map { |s, index| index % 2 == 0 ? s.gsub(/(\n|\s)+/, ' ') : s }
|
53
|
+
.join("'")
|
50
54
|
end
|
51
55
|
|
52
56
|
def partial(partial_name, partial_options = {})
|
data/spec/sql_query_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe SqlQuery do
|
6
|
-
let(:options) { { email:
|
6
|
+
let(:options) { { email: "e@mail.dev ' " } }
|
7
7
|
let(:file_name) { :get_player_by_email }
|
8
8
|
let(:query) { described_class.new(file_name, options) }
|
9
9
|
|
@@ -13,7 +13,7 @@ describe SqlQuery do
|
|
13
13
|
|
14
14
|
describe '#initialize' do
|
15
15
|
it 'sets instance variables for all options' do
|
16
|
-
expect(query.instance_variable_get(:@email)).to eq
|
16
|
+
expect(query.instance_variable_get(:@email)).to eq options[:email]
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'when options are set not in parentheses' do
|
@@ -82,7 +82,7 @@ describe SqlQuery do
|
|
82
82
|
describe '#sql' do
|
83
83
|
it 'returns query string' do
|
84
84
|
expect(query.sql)
|
85
|
-
.to eq("SELECT *\nFROM players\nWHERE email = 'e@mail.dev'\n")
|
85
|
+
.to eq("SELECT *\nFROM players\nWHERE email = 'e@mail.dev '' '\n")
|
86
86
|
end
|
87
87
|
|
88
88
|
context 'when file is .erb.sql' do
|
@@ -98,7 +98,7 @@ describe SqlQuery do
|
|
98
98
|
describe '#pretty_sql' do
|
99
99
|
it 'returns query string' do
|
100
100
|
expect(query.pretty_sql)
|
101
|
-
.to eq("SELECT *\nFROM players\nWHERE email = 'e@mail.dev'\n")
|
101
|
+
.to eq("SELECT *\nFROM players\nWHERE email = 'e@mail.dev '' '\n")
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -107,7 +107,7 @@ describe SqlQuery do
|
|
107
107
|
it 'returns explain string' do
|
108
108
|
expect(explain).to include 'EXPLAIN for:'
|
109
109
|
expect(explain).to include 'FROM players'
|
110
|
-
expect(explain).to include "WHERE email = 'e@mail.dev'"
|
110
|
+
expect(explain).to include "WHERE email = 'e@mail.dev '' '"
|
111
111
|
expect(explain).to include 'QUERY PLAN'
|
112
112
|
expect(explain).to include 'Seq Scan on players'
|
113
113
|
end
|
@@ -116,7 +116,7 @@ describe SqlQuery do
|
|
116
116
|
describe '#execute' do
|
117
117
|
before do
|
118
118
|
ActiveRecord::Base.connection.execute(
|
119
|
-
"INSERT INTO players (email) VALUES ('e@mail.dev')"
|
119
|
+
"INSERT INTO players (email) VALUES ('e@mail.dev '' ')"
|
120
120
|
)
|
121
121
|
end
|
122
122
|
|
@@ -127,7 +127,7 @@ describe SqlQuery do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'returns data from database' do
|
130
|
-
expect(query.execute).to eq [{ 'email' =>
|
130
|
+
expect(query.execute).to eq [{ 'email' => "e@mail.dev ' " }]
|
131
131
|
end
|
132
132
|
|
133
133
|
context 'when prepare argument is true' do
|
@@ -148,7 +148,7 @@ describe SqlQuery do
|
|
148
148
|
describe '#exec_query' do
|
149
149
|
before do
|
150
150
|
ActiveRecord::Base.connection.execute(
|
151
|
-
"INSERT INTO players (email) VALUES ('e@mail.dev')"
|
151
|
+
"INSERT INTO players (email) VALUES ('e@mail.dev '' ')"
|
152
152
|
)
|
153
153
|
end
|
154
154
|
|
@@ -159,7 +159,7 @@ describe SqlQuery do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'returns data from database' do
|
162
|
-
expect(query.exec_query).to eq [{ 'email' =>
|
162
|
+
expect(query.exec_query).to eq [{ 'email' => "e@mail.dev ' " }]
|
163
163
|
end
|
164
164
|
|
165
165
|
context 'when prepare argument is true' do
|
@@ -181,7 +181,7 @@ describe SqlQuery do
|
|
181
181
|
let(:file_name) { :get_player_by_email_with_template }
|
182
182
|
it 'resolves partials as parts of sql queries' do
|
183
183
|
expect(query.sql)
|
184
|
-
.to eq("SELECT *\nFROM players\nWHERE players.email = 'e@mail.dev'\n\n")
|
184
|
+
.to eq("SELECT *\nFROM players\nWHERE players.email = 'e@mail.dev '' '\n\n")
|
185
185
|
end
|
186
186
|
|
187
187
|
context 'when partial name is string with file path' do
|
@@ -197,9 +197,20 @@ describe SqlQuery do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
describe '#prepared_for_logs' do
|
200
|
+
let(:options) { { email: 'e@mail.dev ' } }
|
201
|
+
|
200
202
|
it 'returns string without new lines' do
|
201
203
|
expect(query.prepared_for_logs)
|
202
|
-
.to eq("SELECT * FROM players WHERE email = 'e@mail.dev' ")
|
204
|
+
.to eq("SELECT * FROM players WHERE email = 'e@mail.dev ' ")
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'when qote is inside parameter' do
|
208
|
+
let(:options) { { email: "e@mail.dev ' " } }
|
209
|
+
|
210
|
+
it 'returns string without new lines and changed parameter' do
|
211
|
+
expect(query.prepared_for_logs)
|
212
|
+
.to eq("SELECT * FROM players WHERE email = 'e@mail.dev '' ' ")
|
213
|
+
end
|
203
214
|
end
|
204
215
|
end
|
205
216
|
|
data/sql_query.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'sql_query'
|
8
|
-
spec.version = '0.7.
|
8
|
+
spec.version = '0.7.3'
|
9
9
|
spec.authors = ['sufleR']
|
10
10
|
spec.email = ['szymon.fracczak@gmail.com']
|
11
11
|
spec.summary = 'Ruby gem to load and execute SQL queries from `.sql.erb` templates'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sufleR
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|