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 --- test/attributes/test_attribute.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/attributes') 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