aboutsummaryrefslogtreecommitdiffstats
path: root/test/attributes/test_attribute.rb
diff options
context:
space:
mode:
authorJames Coleman <jtc331@gmail.com>2017-09-29 16:29:50 -0500
committerJames Coleman <jtc331@gmail.com>2017-09-29 16:29:50 -0500
commitb416fca38780fb3305d836944ff8880f7097b4b3 (patch)
tree7832ebfa6bfd2b46ae076ece193a726833d8cb00 /test/attributes/test_attribute.rb
parent1ede2ad3c7ae41ed1e06a92358b37c880dea9837 (diff)
downloadrails-b416fca38780fb3305d836944ff8880f7097b4b3.tar.gz
rails-b416fca38780fb3305d836944ff8880f7097b4b3.tar.bz2
rails-b416fca38780fb3305d836944ff8880f7097b4b3.zip
Type-castable attributes should not try to cast SqlLiteral nodes
Diffstat (limited to 'test/attributes/test_attribute.rb')
-rw-r--r--test/attributes/test_attribute.rb12
1 files changed, 12 insertions, 0 deletions
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