- A
- C
- D
- N
- S
- T
-
- teardown,
- test_bind_from_join_in_subquery,
- test_binds_are_logged,
- test_find_one_uses_binds,
- test_logs_binds_after_type_cast,
- test_logs_legacy_binds_after_type_cast,
- test_statement_cache,
- test_statement_cache_with_find,
- test_statement_cache_with_find_by,
- test_statement_cache_with_in_clause,
- test_statement_cache_with_query_cache,
- test_statement_cache_with_sql_string_literal,
- test_too_many_binds,
- test_too_many_binds_with_query_cache,
- to_sql_key
Source: show
# File activerecord/test/cases/bind_parameter_test.rb 200 def initialize 201 super 202 @debugs = [] 203 end
Source: show
# 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
Source: show
# File activerecord/test/cases/bind_parameter_test.rb 34 def teardown 35 ActiveSupport::Notifications.unsubscribe(@subscription) 36 end
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# 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
Source: show
# File activerecord/test/cases/bind_parameter_test.rb 182 def assert_logs_binds(binds) 183 payload = { 184 name: "SQL", 185 sql: "select * from topics where id = ?", 186 binds: binds, 187 type_casted_binds: @connection.send(:type_casted_binds, binds) 188 } 189 190 event = ActiveSupport::Notifications::Event.new( 191 "foo", 192 Time.now, 193 Time.now, 194 123, 195 payload) 196 197 logger = Class.new(ActiveRecord::LogSubscriber) { 198 attr_reader :debugs 199 200 def initialize 201 super 202 @debugs = [] 203 end 204 205 def debug(str) 206 @debugs << str 207 end 208 }.new 209 210 logger.sql(event) 211 assert_match([[@pk.name, 10]].inspect, logger.debugs.first) 212 end
Source: show
# File activerecord/test/cases/bind_parameter_test.rb 171 def cached_statement(klass, key) 172 cache = klass.send(:cached_find_by_statement, key) do 173 raise "#{klass} has no cached statement by #{key.inspect}" 174 end 175 cache.send(:query_builder).instance_variable_get(:@sql) 176 end
Source: show
# File activerecord/test/cases/bind_parameter_test.rb 205 def debug(str) 206 @debugs << str 207 end