diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-10-06 14:02:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-06 14:02:58 -0400 |
commit | 5cc7e774bb4d2190236cdbf46d66c89507ac6933 (patch) | |
tree | 7832ebfa6bfd2b46ae076ece193a726833d8cb00 | |
parent | 1ede2ad3c7ae41ed1e06a92358b37c880dea9837 (diff) | |
parent | b416fca38780fb3305d836944ff8880f7097b4b3 (diff) | |
download | rails-5cc7e774bb4d2190236cdbf46d66c89507ac6933.tar.gz rails-5cc7e774bb4d2190236cdbf46d66c89507ac6933.tar.bz2 rails-5cc7e774bb4d2190236cdbf46d66c89507ac6933.zip |
Merge pull request #500 from jcoleman/fix_incorrect_typecasting_of_raw_sql_strings
Type-castable attributes should not try to cast SqlLiteral nodes
-rw-r--r-- | lib/arel/nodes/casted.rb | 2 | ||||
-rw-r--r-- | test/attributes/test_attribute.rb | 12 |
2 files changed, 13 insertions, 1 deletions
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 |