/
inline_param_encoder_test.rb
49 lines (39 loc) · 1.26 KB
/
inline_param_encoder_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
require 'test_helper'
module MiniSql
class TestInlineParamEncoder < MiniTest::Test
def setup
@connection = pg_connection
@encoder = InlineParamEncoder.new(@connection)
end
def test_basic_encoding
result = @encoder.encode("select :int::int", int: 22)
assert_equal("select 22::int", result)
end
def test_string_encoding
result = @encoder.encode("select :str", str: "hello's")
assert_equal("select 'hello''s'", result)
end
def test_symbol_encoding
result = @encoder.encode("select :str", str: :value)
assert_equal("select 'value'", result)
end
def test_array_encoding
result = @encoder.encode("select :str", str: ["a", "a'"])
assert_equal("select 'a', 'a'''", result)
end
def test_empty_array_encoding
result = @encoder.encode("select :str", str: [])
assert_equal("select NULL", result)
end
def test_encode_times
t = Time.parse('2010-10-01T02:22:00Z')
result = @encoder.encode("select :t", t: t)
assert_equal("select '2010-10-01T02:22:00Z'", result)
end
def test_question_encoding
result = @encoder.encode("select 1,?,?", "a", 2)
assert_equal("select 1,'a',2", result)
end
end
end