diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-12-29 01:14:01 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-12-29 01:14:51 -0500 |
commit | 1e24cd4525c7ff58f9f2d1323292c2d67244ec01 (patch) | |
tree | bd48510dd18101825cd7eab363a854bf4281f1ab /test | |
parent | 6ef13ec5d29b3ec66900c60bcfdf1ac5be8d20ac (diff) | |
download | rails-1e24cd4525c7ff58f9f2d1323292c2d67244ec01.tar.gz rails-1e24cd4525c7ff58f9f2d1323292c2d67244ec01.tar.bz2 rails-1e24cd4525c7ff58f9f2d1323292c2d67244ec01.zip |
Remove deprecated type cast support in Arel
Diffstat (limited to 'test')
-rw-r--r-- | test/attributes/test_attribute.rb | 8 | ||||
-rw-r--r-- | test/helper.rb | 2 | ||||
-rw-r--r-- | test/support/fake_record.rb | 15 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 73 |
4 files changed, 5 insertions, 93 deletions
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 |