aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--History.txt4
-rw-r--r--lib/arel/visitors/to_sql.rb49
-rw-r--r--test/attributes/test_attribute.rb8
-rw-r--r--test/helper.rb2
-rw-r--r--test/support/fake_record.rb15
-rw-r--r--test/visitors/test_to_sql.rb73
6 files changed, 14 insertions, 137 deletions
diff --git a/History.txt b/History.txt
index ccc170c4a2..aacf6d7a16 100644
--- a/History.txt
+++ b/History.txt
@@ -1,3 +1,7 @@
+* Enhancements
+
+ * Remove deprecated type casting support in Arel
+
=== 7.1.1 / 2016-07-27
* Bug Fixes
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 506b33f4b6..ad2666fb10 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -76,10 +76,6 @@ module Arel
private
- def schema_cache
- @connection.schema_cache
- end
-
def visit_Arel_Nodes_DeleteStatement o, collector
collector << 'DELETE FROM '
collector = visit o.relation, collector
@@ -170,24 +166,6 @@ module Arel
collector << "FALSE"
end
- def table_exists? name
- schema_cache.data_source_exists?(name)
- end
-
- def column_for attr
- return unless attr
- name = attr.name.to_s
- table = attr.relation.table_name
-
- return nil unless table_exists? table
-
- column_cache(table)[name]
- end
-
- def column_cache(table)
- schema_cache.columns_hash(table)
- end
-
def visit_Arel_Nodes_Values o, collector
collector << "VALUES ("
@@ -197,7 +175,7 @@ module Arel
when Nodes::SqlLiteral, Nodes::BindParam
collector = visit value, collector
else
- collector << quote(value, attr && column_for(attr)).to_s
+ collector << quote(value).to_s
end
unless i == len
collector << COMMA
@@ -653,7 +631,7 @@ module Arel
else
collector = visit o.left, collector
collector << " = "
- collector << quote(o.right, column_for(o.left)).to_s
+ collector << quote(o.right).to_s
end
end
@@ -749,7 +727,7 @@ module Arel
if a && a.able_to_type_cast?
quote(a.type_cast_for_database(o))
else
- quote(o, column_for(a))
+ quote(o)
end
end
@@ -793,12 +771,9 @@ module Arel
end
alias :visit_Set :visit_Array
- def quote value, column = nil
+ def quote value
return value if Arel::Nodes::SqlLiteral === value
- if column
- print_type_cast_deprecation
- end
- @connection.quote value, column
+ @connection.quote value
end
def quote_table_name name
@@ -847,20 +822,6 @@ module Arel
collector
end
end
-
- def print_type_cast_deprecation
- unless defined?($arel_silence_type_casting_deprecation) && $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, and the `Arel::Table` object was constructed manually. The easiest way to remove this warning is to use an `Arel::Table` object returned from calling `arel_table` on an ActiveRecord::Base subclass.
-
-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 must either give an appropriate type caster object to the `Arel::Table`, or manually cast the value before passing it to Arel.
- eowarn
- end
- end
end
end
end
diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb
index f6b73adf6a..928b23ed7b 100644
--- a/test/attributes/test_attribute.rb
+++ b/test/attributes/test_attribute.rb
@@ -996,14 +996,6 @@ module Arel
assert table.able_to_type_cast?
condition.to_sql.must_equal %("foo"."id" = 1 AND "foo"."other_id" = '2')
end
-
- it 'falls back to using the connection adapter for type casting' do
- table = Table.new(:users)
- condition = table["id"].eq("1")
-
- refute table.able_to_type_cast?
- condition.to_sql.must_equal %("users"."id" = 1)
- end
end
end
end
diff --git a/test/helper.rb b/test/helper.rb
index 87f5756d24..6e8ac836fc 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -6,8 +6,6 @@ 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
diff --git a/test/support/fake_record.rb b/test/support/fake_record.rb
index 3d4c7d5630..4867dad5dc 100644
--- a/test/support/fake_record.rb
+++ b/test/support/fake_record.rb
@@ -59,16 +59,7 @@ module FakeRecord
self
end
- def quote thing, column = nil
- if column && !thing.nil?
- case column.type
- when :integer
- thing = thing.to_i
- when :string
- thing = thing.to_s
- end
- end
-
+ def quote thing
case thing
when DateTime
"'#{thing.strftime("%Y-%m-%d %H:%M:%S")}'"
@@ -116,8 +107,8 @@ module FakeRecord
connection
end
- def quote thing, column = nil
- connection.quote thing, column
+ def quote thing
+ connection.quote thing
end
end
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb
index 6833d4e8f5..451c267b34 100644
--- a/test/visitors/test_to_sql.rb
+++ b/test/visitors/test_to_sql.rb
@@ -120,19 +120,6 @@ module Arel
sql.must_be_like %{ 'f' = 'f' }
end
- it 'should use the column to quote' do
- table = Table.new(:users)
- val = Nodes.build_quoted('1-fooo', table[:id])
- sql = compile Nodes::Equality.new(table[:id], val)
- sql.must_be_like %{ "users"."id" = 1 }
- end
-
- it 'should use the column to quote integers' do
- table = Table.new(:users)
- sql = compile table[:name].eq(0)
- sql.must_be_like %{ "users"."name" = '0' }
- end
-
it 'should handle nil' do
sql = compile Nodes::Equality.new(@table[:name], nil)
sql.must_be_like %{ "users"."name" IS NULL }
@@ -191,24 +178,15 @@ module Arel
it "should quote LIMIT without column type coercion" do
table = Table.new(:users)
sc = table.where(table[:name].eq(0)).take(1).ast
- assert_match(/WHERE "users"."name" = '0' LIMIT 1/, compile(sc))
+ assert_match(/WHERE "users"."name" = 0 LIMIT 1/, compile(sc))
end
it "should visit_DateTime" do
- called_with = nil
- @conn.connection.extend(Module.new {
- define_method(:quote) do |thing, column|
- called_with = column
- super(thing, column)
- end
- })
-
dt = DateTime.now
table = Table.new(:users)
test = table[:created_at].eq dt
sql = compile test
- assert_equal "created_at", called_with.name
sql.must_be_like %{"users"."created_at" = '#{dt.strftime("%Y-%m-%d %H:%M:%S")}'}
end
@@ -252,20 +230,11 @@ module Arel
end
it "should visit_Date" do
- called_with = nil
- @conn.connection.extend(Module.new {
- define_method(:quote) do |thing, column|
- called_with = column
- super(thing, column)
- end
- })
-
dt = Date.today
table = Table.new(:users)
test = table[:created_at].eq dt
sql = compile test
- assert_equal "created_at", called_with.name
sql.must_be_like %{"users"."created_at" = '#{dt.strftime("%Y-%m-%d")}'}
end
@@ -427,25 +396,6 @@ module Arel
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
}
end
-
- it 'uses the same column for escaping values' do
- @attr = Table.new(:users)[:name]
- visitor = Class.new(ToSql) do
- attr_accessor :expected
-
- def quote value, column = nil
- raise unless column == expected
- super
- end
- end
- vals = %w{ a b c }.map { |x| Nodes.build_quoted(x, @attr) }
- in_node = Nodes::In.new @attr, vals
- visitor = visitor.new(Table.engine.connection)
- visitor.expected = Table.engine.connection.columns(:users).find { |x|
- x.name == 'name'
- }
- visitor.accept(in_node, Collectors::SQLString.new).value.must_equal %("users"."name" IN ('a', 'b', 'c'))
- end
end
describe "Nodes::InfixOperation" do
@@ -574,25 +524,6 @@ module Arel
"users"."id" NOT IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
}
end
-
- it 'uses the same column for escaping values' do
- @attr = Table.new(:users)[:name]
- visitor = Class.new(ToSql) do
- attr_accessor :expected
-
- def quote value, column = nil
- raise unless column == expected
- super
- end
- end
- vals = %w{ a b c }.map { |x| Nodes.build_quoted(x, @attr) }
- in_node = Nodes::NotIn.new @attr, vals
- visitor = visitor.new(Table.engine.connection)
- visitor.expected = Table.engine.connection.columns(:users).find { |x|
- x.name == 'name'
- }
- compile(in_node).must_equal %("users"."name" NOT IN ('a', 'b', 'c'))
- end
end
describe 'Constants' do
@@ -615,7 +546,7 @@ module Arel
it "should use the underlying table for checking columns" do
test = Table.new(:users).alias('zomgusers')[:id].eq '3'
compile(test).must_be_like %{
- "zomgusers"."id" = 3
+ "zomgusers"."id" = '3'
}
end
end