aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-12-26 18:02:56 -0700
committerSean Griffin <sean@thoughtbot.com>2014-12-26 18:02:56 -0700
commit008445d6fd5f825d9b445ac75a7be67f0f7ab52c (patch)
treef8d44ff38bb86196116152f05a10dab157fe972c
parentcf03bd45e39def057a2f63e42a3391b7d750dece (diff)
downloadrails-008445d6fd5f825d9b445ac75a7be67f0f7ab52c.tar.gz
rails-008445d6fd5f825d9b445ac75a7be67f0f7ab52c.tar.bz2
rails-008445d6fd5f825d9b445ac75a7be67f0f7ab52c.zip
Deprecate automatic type casting within Arel
Rails now performs all casting eagerly, before passing the value into Arel. Once we remove this, the code on both sides will be simplified greatly. Ideally, we can provide the appropriate public APIs on the Rails side to ease this transition for library authors who depend on this behavior.
-rw-r--r--lib/arel/nodes.rb11
-rw-r--r--test/helper.rb2
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index 7d900fe710..8432106719 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -87,6 +87,17 @@ module Arel
else
case attribute
when Arel::Attributes::Attribute
+ unless $arel_silence_type_casting_deprecation
+ warn <<-eowarn
+Arel performing automatic type casting is deprecated, and will be removed in Arel 8.0. If you are seeing this, it is because you are manually passing a value to an Arel predicate.
+
+If you're certain the value is already of the right type, change `attribute.eq(value)` to `attribute.eq(Arel::Nodes::Quoted.new(value))` (you will be able to remove that in Arel 8.0, it is only required to silence this deprecation warning).
+
+You can also silence this warning globally by setting `$arel_silence_type_casting_deprecation` to `true`. (Do NOT do this if you are a library author)
+
+If you are passing user input to a predicate, you are responsible for type casting appropriately before passing the value to Arel.
+ eowarn
+ end
Casted.new other, attribute
else
Quoted.new other
diff --git a/test/helper.rb b/test/helper.rb
index 6e8ac836fc..87f5756d24 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -6,6 +6,8 @@ require 'arel'
require 'support/fake_record'
Arel::Table.engine = FakeRecord::Base.new
+$arel_silence_type_casting_deprecation = true
+
class Object
def must_be_like other
gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip