From b416fca38780fb3305d836944ff8880f7097b4b3 Mon Sep 17 00:00:00 2001 From: James Coleman Date: Fri, 29 Sep 2017 16:29:50 -0500 Subject: Type-castable attributes should not try to cast SqlLiteral nodes --- lib/arel/nodes/casted.rb | 2 +- test/attributes/test_attribute.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/arel/nodes/casted.rb b/lib/arel/nodes/casted.rb index 290e4dd38c..1d7385d01b 100644 --- a/lib/arel/nodes/casted.rb +++ b/lib/arel/nodes/casted.rb @@ -30,7 +30,7 @@ module Arel def self.build_quoted other, attribute = nil case other - when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted + when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral other else case attribute diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb index 2b971ce54a..a67ef53a4c 100644 --- a/test/attributes/test_attribute.rb +++ b/test/attributes/test_attribute.rb @@ -997,6 +997,18 @@ module Arel assert table.able_to_type_cast? condition.to_sql.must_equal %("foo"."id" = 1 AND "foo"."other_id" = '2') end + + it 'does not type cast SqlLiteral nodes' do + fake_caster = Object.new + def fake_caster.type_cast_for_database(attr_name, value) + value.to_i + end + table = Table.new(:foo, type_caster: fake_caster) + condition = table["id"].eq(Arel.sql("(select 1)")) + + assert table.able_to_type_cast? + condition.to_sql.must_equal %("foo"."id" = (select 1)) + end end end end -- cgit v1.2.3