-
Notifications
You must be signed in to change notification settings - Fork 21.4k
/
bind_parameter_test.rb
58 lines (48 loc) · 1.69 KB
/
bind_parameter_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
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
require "cases/helper"
require "models/post"
module ActiveRecord
module ConnectionAdapters
class SQLite3Adapter
class BindParameterTest < ActiveRecord::SQLite3TestCase
fixtures :posts
def test_where_with_string_for_string_column_using_bind_parameters
assert_quoted_as "'Welcome to the weblog'", "Welcome to the weblog", match: 1
end
def test_where_with_integer_for_string_column_using_bind_parameters
assert_quoted_as "0", 0
end
def test_where_with_float_for_string_column_using_bind_parameters
assert_quoted_as "0.0", 0.0
end
def test_where_with_boolean_for_string_column_using_bind_parameters
assert_quoted_as "0", false
end
def test_where_with_decimal_for_string_column_using_bind_parameters
assert_quoted_as "0.0", BigDecimal(0)
end
def test_where_with_rational_for_string_column_using_bind_parameters
assert_quoted_as "0/1", Rational(0)
end
def test_where_with_duration_for_string_column_using_bind_parameters
assert_deprecated(ActiveRecord.deprecator) do
assert_quoted_as "0", 0.seconds
end
end
private
def assert_quoted_as(expected, value, match: 0)
relation = Post.where("title = ?", value)
assert_equal(
%{SELECT "posts".* FROM "posts" WHERE (title = #{expected})},
relation.to_sql,
)
if match == 0
assert_empty relation.to_a
else
assert_equal match, relation.count
end
end
end
end
end
end