aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/bind_parameter_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/bind_parameter_test.rb')
-rw-r--r--activerecord/test/cases/bind_parameter_test.rb37
1 files changed, 23 insertions, 14 deletions
diff --git a/activerecord/test/cases/bind_parameter_test.rb b/activerecord/test/cases/bind_parameter_test.rb
index fa924fe4cb..98d202dd79 100644
--- a/activerecord/test/cases/bind_parameter_test.rb
+++ b/activerecord/test/cases/bind_parameter_test.rb
@@ -1,7 +1,7 @@
-require 'cases/helper'
-require 'models/topic'
-require 'models/author'
-require 'models/post'
+require "cases/helper"
+require "models/topic"
+require "models/author"
+require "models/post"
module ActiveRecord
class BindParameterTest < ActiveRecord::TestCase
@@ -24,7 +24,7 @@ module ActiveRecord
@connection = ActiveRecord::Base.connection
@subscriber = LogListener.new
@pk = Topic.columns_hash[Topic.primary_key]
- @subscription = ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
+ @subscription = ActiveSupport::Notifications.subscribe("sql.active_record", @subscriber)
end
teardown do
@@ -34,8 +34,8 @@ module ActiveRecord
if ActiveRecord::Base.connection.supports_statement_cache? &&
ActiveRecord::Base.connection.prepared_statements
def test_bind_from_join_in_subquery
- subquery = Author.joins(:thinking_posts).where(name: 'David')
- scope = Author.from(subquery, 'authors').where(id: 1)
+ subquery = Author.joins(:thinking_posts).where(name: "David")
+ scope = Author.from(subquery, "authors").where(id: 1)
assert_equal 1, scope.count
end
@@ -44,7 +44,7 @@ module ActiveRecord
binds = [Relation::QueryAttribute.new("id", 1, Type::Value.new)]
sql = "select * from topics where id = #{sub.to_sql}"
- @connection.exec_query(sql, 'SQL', binds)
+ @connection.exec_query(sql, "SQL", binds)
message = @subscriber.calls.find { |args| args[4][:sql] == sql }
assert_equal binds, message[4][:binds]
@@ -53,17 +53,20 @@ module ActiveRecord
def test_find_one_uses_binds
Topic.find(1)
message = @subscriber.calls.find { |args| args[4][:binds].any? { |attr| attr.value == 1 } }
- assert message, 'expected a message with binds'
+ assert message, "expected a message with binds"
end
def test_logs_bind_vars_after_type_cast
+ binds = [Relation::QueryAttribute.new("id", "10", Type::Integer.new)]
+ type_casted_binds = binds.map { |attr| type_cast(attr.value_for_database) }
payload = {
- :name => 'SQL',
- :sql => 'select * from topics where id = ?',
- :binds => [Relation::QueryAttribute.new("id", "10", Type::Integer.new)]
+ name: "SQL",
+ sql: "select * from topics where id = ?",
+ binds: binds,
+ type_casted_binds: type_casted_binds
}
event = ActiveSupport::Notifications::Event.new(
- 'foo',
+ "foo",
Time.now,
Time.now,
123,
@@ -76,7 +79,7 @@ module ActiveRecord
@debugs = []
end
- def debug str
+ def debug(str)
@debugs << str
end
}.new
@@ -84,6 +87,12 @@ module ActiveRecord
logger.sql event
assert_match([[@pk.name, 10]].inspect, logger.debugs.first)
end
+
+ private
+
+ def type_cast(value)
+ ActiveRecord::Base.connection.type_cast(value)
+ end
end
end
end