Namespace
Methods
N
S
T
Class Public methods
new()
    # File activerecord/test/cases/bind_parameter_test.rb
200 def initialize
201   super
202   @debugs = []
203 end
Instance Public methods
setup()
   # File activerecord/test/cases/bind_parameter_test.rb
26 def setup
27   super
28   @connection = ActiveRecord::Base.connection
29   @subscriber = LogListener.new
30   @pk = Topic.columns_hash[Topic.primary_key]
31   @subscription = ActiveSupport::Notifications.subscribe("sql.active_record", @subscriber)
32 end
teardown()
   # File activerecord/test/cases/bind_parameter_test.rb
34 def teardown
35   ActiveSupport::Notifications.unsubscribe(@subscription)
36 end
test_bind_from_join_in_subquery()
    # File activerecord/test/cases/bind_parameter_test.rb
132 def test_bind_from_join_in_subquery
133   subquery = Author.joins(:thinking_posts).where(name: "David")
134   scope = Author.from(subquery, "authors").where(id: 1)
135   assert_equal 1, scope.count
136 end
test_binds_are_logged()
    # File activerecord/test/cases/bind_parameter_test.rb
138 def test_binds_are_logged
139   sub   = Arel::Nodes::BindParam.new(1)
140   binds = [Relation::QueryAttribute.new("id", 1, Type::Value.new)]
141   sql   = "select * from topics where id = #{sub.to_sql}"
142 
143   @connection.exec_query(sql, "SQL", binds)
144 
145   message = @subscriber.calls.find { |args| args[4][:sql] == sql }
146   assert_equal binds, message[4][:binds]
147 end
test_find_one_uses_binds()
    # File activerecord/test/cases/bind_parameter_test.rb
149 def test_find_one_uses_binds
150   Topic.find(1)
151   message = @subscriber.calls.find { |args| args[4][:binds].any? { |attr| attr.value == 1 } }
152   assert message, "expected a message with binds"
153 end
test_logs_binds_after_type_cast()
    # File activerecord/test/cases/bind_parameter_test.rb
155 def test_logs_binds_after_type_cast
156   binds = [Relation::QueryAttribute.new("id", "10", Type::Integer.new)]
157   assert_logs_binds(binds)
158 end
test_logs_legacy_binds_after_type_cast()
    # File activerecord/test/cases/bind_parameter_test.rb
160 def test_logs_legacy_binds_after_type_cast
161   binds = [[@pk, "10"]]
162   assert_logs_binds(binds)
163 end
test_statement_cache()
   # File activerecord/test/cases/bind_parameter_test.rb
38 def test_statement_cache
39   @connection.clear_cache!
40 
41   topics = Topic.where(id: 1)
42   assert_equal [1], topics.map(&:id)
43   assert_includes statement_cache, to_sql_key(topics.arel)
44 
45   @connection.clear_cache!
46 
47   assert_not_includes statement_cache, to_sql_key(topics.arel)
48 end
test_statement_cache_with_find()
   # File activerecord/test/cases/bind_parameter_test.rb
61 def test_statement_cache_with_find
62   @connection.clear_cache!
63 
64   assert_equal 1, Topic.find(1).id
65   assert_raises(RecordNotFound) { SillyReply.find(2) }
66 
67   topic_sql = cached_statement(Topic, Topic.primary_key)
68   assert_includes statement_cache, to_sql_key(topic_sql)
69 
70   e = assert_raise { cached_statement(SillyReply, SillyReply.primary_key) }
71   assert_equal "SillyReply has no cached statement by \"id\"", e.message
72 
73   replies = SillyReply.where(id: 2).limit(1)
74   assert_includes statement_cache, to_sql_key(replies.arel)
75 end
test_statement_cache_with_find_by()
   # File activerecord/test/cases/bind_parameter_test.rb
77 def test_statement_cache_with_find_by
78   @connection.clear_cache!
79 
80   assert_equal 1, Topic.find_by!(id: 1).id
81   assert_raises(RecordNotFound) { SillyReply.find_by!(id: 2) }
82 
83   topic_sql = cached_statement(Topic, [:id])
84   assert_includes statement_cache, to_sql_key(topic_sql)
85 
86   e = assert_raise { cached_statement(SillyReply, [:id]) }
87   assert_equal "SillyReply has no cached statement by [:id]", e.message
88 
89   replies = SillyReply.where(id: 2).limit(1)
90   assert_includes statement_cache, to_sql_key(replies.arel)
91 end
test_statement_cache_with_in_clause()
   # File activerecord/test/cases/bind_parameter_test.rb
93 def test_statement_cache_with_in_clause
94   @connection.clear_cache!
95 
96   topics = Topic.where(id: [1, 3])
97   assert_equal [1, 3], topics.map(&:id)
98   assert_not_includes statement_cache, to_sql_key(topics.arel)
99 end
test_statement_cache_with_query_cache()
   # File activerecord/test/cases/bind_parameter_test.rb
50 def test_statement_cache_with_query_cache
51   @connection.enable_query_cache!
52   @connection.clear_cache!
53 
54   topics = Topic.where(id: 1)
55   assert_equal [1], topics.map(&:id)
56   assert_includes statement_cache, to_sql_key(topics.arel)
57 ensure
58   @connection.disable_query_cache!
59 end
test_statement_cache_with_sql_string_literal()
    # File activerecord/test/cases/bind_parameter_test.rb
101 def test_statement_cache_with_sql_string_literal
102   @connection.clear_cache!
103 
104   topics = Topic.where("topics.id = ?", 1)
105   assert_equal [1], topics.map(&:id)
106   assert_not_includes statement_cache, to_sql_key(topics.arel)
107 end
test_too_many_binds()
    # File activerecord/test/cases/bind_parameter_test.rb
109 def test_too_many_binds
110   bind_params_length = @connection.send(:bind_params_length)
111 
112   topics = Topic.where(id: (1 .. bind_params_length).to_a << 2**63)
113   assert_equal Topic.count, topics.count
114 
115   topics = Topic.where.not(id: (1 .. bind_params_length).to_a << 2**63)
116   assert_equal 0, topics.count
117 end
test_too_many_binds_with_query_cache()
    # File activerecord/test/cases/bind_parameter_test.rb
119 def test_too_many_binds_with_query_cache
120   @connection.enable_query_cache!
121 
122   bind_params_length = @connection.send(:bind_params_length)
123   topics = Topic.where(id: (1 .. bind_params_length + 1).to_a)
124   assert_equal Topic.count, topics.count
125 
126   topics = Topic.where.not(id: (1 .. bind_params_length + 1).to_a)
127   assert_equal 0, topics.count
128 ensure
129   @connection.disable_query_cache!
130 end