Address to the warning "DEPRECATED: global use of assertion methods"

This addresses to the warning "DEPRECATED: global use of assertion
methods" which is introduced in minitest v5.12.0.

e6bc448573

https://buildkite.com/rails/rails/builds/64121#880aecf2-849f-4603-95f1-228784c7d3f4/1003-1010
This commit is contained in:
Ryuta Kamizono 2019-10-04 17:16:33 +09:00
parent a0550aee11
commit 6158b83d2a
32 changed files with 553 additions and 551 deletions

View File

@ -317,7 +317,7 @@ GEM
mini_magick (4.9.5)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
minitest (5.12.2)
minitest-bisect (1.4.0)
minitest-server (~> 1.0)
path_expander (~> 1.0)
@ -340,6 +340,8 @@ GEM
mustache (1.1.0)
mustermann (1.0.3)
mysql2 (0.5.2)
mysql2 (0.5.2-x64-mingw32)
mysql2 (0.5.2-x86-mingw32)
nio4r (2.4.0)
nio4r (2.4.0-java)
nokogiri (1.10.4)

View File

@ -9,14 +9,14 @@ module Arel
describe "#not_eq" do
it "should create a NotEqual node" do
relation = Table.new(:users)
relation[:id].not_eq(10).must_be_kind_of Nodes::NotEqual
_(relation[:id].not_eq(10)).must_be_kind_of Nodes::NotEqual
end
it "should generate != in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq(10)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" != 10
}
end
@ -25,7 +25,7 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq(nil)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" IS NOT NULL
}
end
@ -34,14 +34,14 @@ module Arel
describe "#not_eq_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].not_eq_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].not_eq_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq_any([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 OR "users"."id" != 2)
}
end
@ -50,14 +50,14 @@ module Arel
describe "#not_eq_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].not_eq_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].not_eq_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq_all([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 AND "users"."id" != 2)
}
end
@ -66,14 +66,14 @@ module Arel
describe "#gt" do
it "should create a GreaterThan node" do
relation = Table.new(:users)
relation[:id].gt(10).must_be_kind_of Nodes::GreaterThan
_(relation[:id].gt(10)).must_be_kind_of Nodes::GreaterThan
end
it "should generate > in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt(10)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" > 10
}
end
@ -84,7 +84,7 @@ module Arel
avg = users.project(users[:karma].average)
mgr = users.project(Arel.star).where(users[:karma].gt(avg))
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT * FROM "users" WHERE "users"."karma" > (SELECT AVG("users"."karma") FROM "users")
}
end
@ -93,25 +93,25 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].gt("fake_name")
mgr.to_sql.must_match %{"users"."name" > 'fake_name'}
_(mgr.to_sql).must_match %{"users"."name" > 'fake_name'}
current_time = ::Time.now
mgr.where relation[:created_at].gt(current_time)
mgr.to_sql.must_match %{"users"."created_at" > '#{current_time}'}
_(mgr.to_sql).must_match %{"users"."created_at" > '#{current_time}'}
end
end
describe "#gt_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].gt_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].gt_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt_any([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 OR "users"."id" > 2)
}
end
@ -120,14 +120,14 @@ module Arel
describe "#gt_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].gt_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].gt_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt_all([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 AND "users"."id" > 2)
}
end
@ -136,14 +136,14 @@ module Arel
describe "#gteq" do
it "should create a GreaterThanOrEqual node" do
relation = Table.new(:users)
relation[:id].gteq(10).must_be_kind_of Nodes::GreaterThanOrEqual
_(relation[:id].gteq(10)).must_be_kind_of Nodes::GreaterThanOrEqual
end
it "should generate >= in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gteq(10)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" >= 10
}
end
@ -152,25 +152,25 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].gteq("fake_name")
mgr.to_sql.must_match %{"users"."name" >= 'fake_name'}
_(mgr.to_sql).must_match %{"users"."name" >= 'fake_name'}
current_time = ::Time.now
mgr.where relation[:created_at].gteq(current_time)
mgr.to_sql.must_match %{"users"."created_at" >= '#{current_time}'}
_(mgr.to_sql).must_match %{"users"."created_at" >= '#{current_time}'}
end
end
describe "#gteq_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].gteq_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].gteq_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gteq_any([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 OR "users"."id" >= 2)
}
end
@ -179,14 +179,14 @@ module Arel
describe "#gteq_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].gteq_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].gteq_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gteq_all([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 AND "users"."id" >= 2)
}
end
@ -195,14 +195,14 @@ module Arel
describe "#lt" do
it "should create a LessThan node" do
relation = Table.new(:users)
relation[:id].lt(10).must_be_kind_of Nodes::LessThan
_(relation[:id].lt(10)).must_be_kind_of Nodes::LessThan
end
it "should generate < in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lt(10)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" < 10
}
end
@ -211,25 +211,25 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].lt("fake_name")
mgr.to_sql.must_match %{"users"."name" < 'fake_name'}
_(mgr.to_sql).must_match %{"users"."name" < 'fake_name'}
current_time = ::Time.now
mgr.where relation[:created_at].lt(current_time)
mgr.to_sql.must_match %{"users"."created_at" < '#{current_time}'}
_(mgr.to_sql).must_match %{"users"."created_at" < '#{current_time}'}
end
end
describe "#lt_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].lt_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].lt_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lt_any([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 OR "users"."id" < 2)
}
end
@ -238,14 +238,14 @@ module Arel
describe "#lt_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].lt_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].lt_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lt_all([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 AND "users"."id" < 2)
}
end
@ -254,14 +254,14 @@ module Arel
describe "#lteq" do
it "should create a LessThanOrEqual node" do
relation = Table.new(:users)
relation[:id].lteq(10).must_be_kind_of Nodes::LessThanOrEqual
_(relation[:id].lteq(10)).must_be_kind_of Nodes::LessThanOrEqual
end
it "should generate <= in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lteq(10)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" <= 10
}
end
@ -270,25 +270,25 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].lteq("fake_name")
mgr.to_sql.must_match %{"users"."name" <= 'fake_name'}
_(mgr.to_sql).must_match %{"users"."name" <= 'fake_name'}
current_time = ::Time.now
mgr.where relation[:created_at].lteq(current_time)
mgr.to_sql.must_match %{"users"."created_at" <= '#{current_time}'}
_(mgr.to_sql).must_match %{"users"."created_at" <= '#{current_time}'}
end
end
describe "#lteq_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].lteq_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].lteq_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lteq_any([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 OR "users"."id" <= 2)
}
end
@ -297,14 +297,14 @@ module Arel
describe "#lteq_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].lteq_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].lteq_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lteq_all([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 AND "users"."id" <= 2)
}
end
@ -313,13 +313,13 @@ module Arel
describe "#average" do
it "should create a AVG node" do
relation = Table.new(:users)
relation[:id].average.must_be_kind_of Nodes::Avg
_(relation[:id].average).must_be_kind_of Nodes::Avg
end
it "should generate the proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].average
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT AVG("users"."id")
FROM "users"
}
@ -329,13 +329,13 @@ module Arel
describe "#maximum" do
it "should create a MAX node" do
relation = Table.new(:users)
relation[:id].maximum.must_be_kind_of Nodes::Max
_(relation[:id].maximum).must_be_kind_of Nodes::Max
end
it "should generate proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].maximum
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT MAX("users"."id")
FROM "users"
}
@ -345,13 +345,13 @@ module Arel
describe "#minimum" do
it "should create a Min node" do
relation = Table.new(:users)
relation[:id].minimum.must_be_kind_of Nodes::Min
_(relation[:id].minimum).must_be_kind_of Nodes::Min
end
it "should generate proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].minimum
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT MIN("users"."id")
FROM "users"
}
@ -361,13 +361,13 @@ module Arel
describe "#sum" do
it "should create a SUM node" do
relation = Table.new(:users)
relation[:id].sum.must_be_kind_of Nodes::Sum
_(relation[:id].sum).must_be_kind_of Nodes::Sum
end
it "should generate the proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].sum
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT SUM("users"."id")
FROM "users"
}
@ -377,14 +377,14 @@ module Arel
describe "#count" do
it "should return a count node" do
relation = Table.new(:users)
relation[:id].count.must_be_kind_of Nodes::Count
_(relation[:id].count).must_be_kind_of Nodes::Count
end
it "should take a distinct param" do
relation = Table.new(:users)
count = relation[:id].count(nil)
count.must_be_kind_of Nodes::Count
count.distinct.must_be_nil
_(count).must_be_kind_of Nodes::Count
_(count.distinct).must_be_nil
end
end
@ -392,16 +392,16 @@ module Arel
it "should return an equality node" do
attribute = Attribute.new nil, nil
equality = attribute.eq 1
equality.left.must_equal attribute
equality.right.val.must_equal 1
equality.must_be_kind_of Nodes::Equality
_(equality.left).must_equal attribute
_(equality.right.val).must_equal 1
_(equality).must_be_kind_of Nodes::Equality
end
it "should generate = in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq(10)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" = 10
}
end
@ -410,7 +410,7 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq(nil)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" IS NULL
}
end
@ -419,14 +419,14 @@ module Arel
describe "#eq_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].eq_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].eq_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq_any([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 OR "users"."id" = 2)
}
end
@ -436,21 +436,21 @@ module Arel
mgr = relation.project relation[:id]
values = [1, 2]
mgr.where relation[:id].eq_any(values)
values.must_equal [1, 2]
_(values).must_equal [1, 2]
end
end
describe "#eq_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].eq_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].eq_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq_all([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2)
}
end
@ -460,21 +460,21 @@ module Arel
mgr = relation.project relation[:id]
values = [1, 2]
mgr.where relation[:id].eq_all(values)
values.must_equal [1, 2]
_(values).must_equal [1, 2]
end
end
describe "#matches" do
it "should create a Matches node" do
relation = Table.new(:users)
relation[:name].matches("%bacon%").must_be_kind_of Nodes::Matches
_(relation[:name].matches("%bacon%")).must_be_kind_of Nodes::Matches
end
it "should generate LIKE in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].matches("%bacon%")
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."name" LIKE '%bacon%'
}
end
@ -483,14 +483,14 @@ module Arel
describe "#matches_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:name].matches_any(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
_(relation[:name].matches_any(["%chunky%", "%bacon%"])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].matches_any(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' OR "users"."name" LIKE '%bacon%')
}
end
@ -499,14 +499,14 @@ module Arel
describe "#matches_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:name].matches_all(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
_(relation[:name].matches_all(["%chunky%", "%bacon%"])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].matches_all(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' AND "users"."name" LIKE '%bacon%')
}
end
@ -515,14 +515,14 @@ module Arel
describe "#does_not_match" do
it "should create a DoesNotMatch node" do
relation = Table.new(:users)
relation[:name].does_not_match("%bacon%").must_be_kind_of Nodes::DoesNotMatch
_(relation[:name].does_not_match("%bacon%")).must_be_kind_of Nodes::DoesNotMatch
end
it "should generate NOT LIKE in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].does_not_match("%bacon%")
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."name" NOT LIKE '%bacon%'
}
end
@ -531,14 +531,14 @@ module Arel
describe "#does_not_match_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:name].does_not_match_any(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
_(relation[:name].does_not_match_any(["%chunky%", "%bacon%"])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].does_not_match_any(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' OR "users"."name" NOT LIKE '%bacon%')
}
end
@ -547,14 +547,14 @@ module Arel
describe "#does_not_match_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:name].does_not_match_all(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
_(relation[:name].does_not_match_all(["%chunky%", "%bacon%"])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].does_not_match_all(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' AND "users"."name" NOT LIKE '%bacon%')
}
end
@ -565,7 +565,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(1..3)
node.must_equal Nodes::Between.new(
_(node).must_equal Nodes::Between.new(
attribute,
Nodes::And.new([
Nodes::Casted.new(1, attribute),
@ -578,7 +578,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(-::Float::INFINITY..3)
node.must_equal Nodes::LessThanOrEqual.new(
_(node).must_equal Nodes::LessThanOrEqual.new(
attribute,
Nodes::Casted.new(3, attribute)
)
@ -588,7 +588,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(-::Float::INFINITY, 3, false))
node.must_equal Nodes::LessThanOrEqual.new(
_(node).must_equal Nodes::LessThanOrEqual.new(
attribute,
Nodes::Quoted.new(3)
)
@ -598,7 +598,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(-::Float::INFINITY...3)
node.must_equal Nodes::LessThan.new(
_(node).must_equal Nodes::LessThan.new(
attribute,
Nodes::Casted.new(3, attribute)
)
@ -608,7 +608,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(-::Float::INFINITY, 3, true))
node.must_equal Nodes::LessThan.new(
_(node).must_equal Nodes::LessThan.new(
attribute,
Nodes::Quoted.new(3)
)
@ -618,21 +618,21 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(-::Float::INFINITY..::Float::INFINITY)
node.must_equal Nodes::NotIn.new(attribute, [])
_(node).must_equal Nodes::NotIn.new(attribute, [])
end
it "can be constructed with a quoted infinite range" do
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(-::Float::INFINITY, ::Float::INFINITY, false))
node.must_equal Nodes::NotIn.new(attribute, [])
_(node).must_equal Nodes::NotIn.new(attribute, [])
end
it "can be constructed with a range ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(0..::Float::INFINITY)
node.must_equal Nodes::GreaterThanOrEqual.new(
_(node).must_equal Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Casted.new(0, attribute)
)
@ -643,7 +643,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(eval("..0")) # eval for backwards compatibility
node.must_equal Nodes::LessThanOrEqual.new(
_(node).must_equal Nodes::LessThanOrEqual.new(
attribute,
Nodes::Casted.new(0, attribute)
)
@ -655,7 +655,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(eval("0..")) # Use eval for compatibility with Ruby < 2.6 parser
node.must_equal Nodes::GreaterThanOrEqual.new(
_(node).must_equal Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Casted.new(0, attribute)
)
@ -666,7 +666,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(0, ::Float::INFINITY, false))
node.must_equal Nodes::GreaterThanOrEqual.new(
_(node).must_equal Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Quoted.new(0)
)
@ -676,7 +676,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.between(0...3)
node.must_equal Nodes::And.new([
_(node).must_equal Nodes::And.new([
Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Casted.new(0, attribute)
@ -698,14 +698,14 @@ module Arel
node = attribute.in(mgr)
node.must_equal Nodes::In.new(attribute, mgr.ast)
_(node).must_equal Nodes::In.new(attribute, mgr.ast)
end
it "can be constructed with a list" do
attribute = Attribute.new nil, nil
node = attribute.in([1, 2, 3])
node.must_equal Nodes::In.new(
_(node).must_equal Nodes::In.new(
attribute,
[
Nodes::Casted.new(1, attribute),
@ -720,7 +720,7 @@ module Arel
random_object = Object.new
node = attribute.in(random_object)
node.must_equal Nodes::In.new(
_(node).must_equal Nodes::In.new(
attribute,
Nodes::Casted.new(random_object, attribute)
)
@ -730,7 +730,7 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].in([1, 2, 3])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" IN (1, 2, 3)
}
end
@ -739,14 +739,14 @@ module Arel
describe "#in_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].in_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].in_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].in_any([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) OR "users"."id" IN (3, 4))
}
end
@ -755,14 +755,14 @@ module Arel
describe "#in_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].in_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].in_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].in_all([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) AND "users"."id" IN (3, 4))
}
end
@ -773,7 +773,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(1..3)
node.must_equal Nodes::Grouping.new(
_(node).must_equal Nodes::Grouping.new(
Nodes::Or.new(
Nodes::LessThan.new(
attribute,
@ -791,7 +791,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(-::Float::INFINITY..3)
node.must_equal Nodes::GreaterThan.new(
_(node).must_equal Nodes::GreaterThan.new(
attribute,
Nodes::Casted.new(3, attribute)
)
@ -801,7 +801,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(quoted_range(-::Float::INFINITY, 3, false))
node.must_equal Nodes::GreaterThan.new(
_(node).must_equal Nodes::GreaterThan.new(
attribute,
Nodes::Quoted.new(3)
)
@ -811,7 +811,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(-::Float::INFINITY...3)
node.must_equal Nodes::GreaterThanOrEqual.new(
_(node).must_equal Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Casted.new(3, attribute)
)
@ -821,7 +821,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(quoted_range(-::Float::INFINITY, 3, true))
node.must_equal Nodes::GreaterThanOrEqual.new(
_(node).must_equal Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Quoted.new(3)
)
@ -831,21 +831,21 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(-::Float::INFINITY..::Float::INFINITY)
node.must_equal Nodes::In.new(attribute, [])
_(node).must_equal Nodes::In.new(attribute, [])
end
it "can be constructed with a quoted infinite range" do
attribute = Attribute.new nil, nil
node = attribute.not_between(quoted_range(-::Float::INFINITY, ::Float::INFINITY, false))
node.must_equal Nodes::In.new(attribute, [])
_(node).must_equal Nodes::In.new(attribute, [])
end
it "can be constructed with a range ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.not_between(0..::Float::INFINITY)
node.must_equal Nodes::LessThan.new(
_(node).must_equal Nodes::LessThan.new(
attribute,
Nodes::Casted.new(0, attribute)
)
@ -856,7 +856,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(eval("..0")) # eval for backwards compatibility
node.must_equal Nodes::GreaterThan.new(
_(node).must_equal Nodes::GreaterThan.new(
attribute,
Nodes::Casted.new(0, attribute)
)
@ -868,7 +868,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(eval("0..")) # Use eval for compatibility with Ruby < 2.6 parser
node.must_equal Nodes::LessThan.new(
_(node).must_equal Nodes::LessThan.new(
attribute,
Nodes::Casted.new(0, attribute)
)
@ -879,7 +879,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(quoted_range(0, ::Float::INFINITY, false))
node.must_equal Nodes::LessThan.new(
_(node).must_equal Nodes::LessThan.new(
attribute,
Nodes::Quoted.new(0)
)
@ -889,7 +889,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_between(0...3)
node.must_equal Nodes::Grouping.new(
_(node).must_equal Nodes::Grouping.new(
Nodes::Or.new(
Nodes::LessThan.new(
attribute,
@ -913,7 +913,7 @@ module Arel
node = attribute.not_in(mgr)
node.must_equal Nodes::NotIn.new(attribute, mgr.ast)
_(node).must_equal Nodes::NotIn.new(attribute, mgr.ast)
end
it "can be constructed with a Union" do
@ -923,7 +923,7 @@ module Arel
union = mgr1.union(mgr2)
node = relation[:id].in(union)
node.to_sql.must_be_like %{
_(node.to_sql).must_be_like %{
"users"."id" IN (( SELECT "users"."id" FROM "users" UNION SELECT "users"."id" FROM "users" ))
}
end
@ -932,7 +932,7 @@ module Arel
attribute = Attribute.new nil, nil
node = attribute.not_in([1, 2, 3])
node.must_equal Nodes::NotIn.new(
_(node).must_equal Nodes::NotIn.new(
attribute,
[
Nodes::Casted.new(1, attribute),
@ -947,7 +947,7 @@ module Arel
random_object = Object.new
node = attribute.not_in(random_object)
node.must_equal Nodes::NotIn.new(
_(node).must_equal Nodes::NotIn.new(
attribute,
Nodes::Casted.new(random_object, attribute)
)
@ -957,7 +957,7 @@ module Arel
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_in([1, 2, 3])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" NOT IN (1, 2, 3)
}
end
@ -966,14 +966,14 @@ module Arel
describe "#not_in_any" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].not_in_any([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].not_in_any([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_in_any([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) OR "users"."id" NOT IN (3, 4))
}
end
@ -982,14 +982,14 @@ module Arel
describe "#not_in_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].not_in_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].not_in_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_in_all([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) AND "users"."id" NOT IN (3, 4))
}
end
@ -998,14 +998,14 @@ module Arel
describe "#eq_all" do
it "should create a Grouping node" do
relation = Table.new(:users)
relation[:id].eq_all([1, 2]).must_be_kind_of Nodes::Grouping
_(relation[:id].eq_all([1, 2])).must_be_kind_of Nodes::Grouping
end
it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq_all([1, 2])
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2)
}
end
@ -1014,14 +1014,14 @@ module Arel
describe "#asc" do
it "should create an Ascending node" do
relation = Table.new(:users)
relation[:id].asc.must_be_kind_of Nodes::Ascending
_(relation[:id].asc).must_be_kind_of Nodes::Ascending
end
it "should generate ASC in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.order relation[:id].asc
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" ORDER BY "users"."id" ASC
}
end
@ -1030,14 +1030,14 @@ module Arel
describe "#desc" do
it "should create a Descending node" do
relation = Table.new(:users)
relation[:id].desc.must_be_kind_of Nodes::Descending
_(relation[:id].desc).must_be_kind_of Nodes::Descending
end
it "should generate DESC in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.order relation[:id].desc
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" ORDER BY "users"."id" DESC
}
end
@ -1048,7 +1048,7 @@ module Arel
it "should produce sql" do
table = Table.new :users
condition = table["id"].eq 1
condition.to_sql.must_equal '"users"."id" = 1'
_(condition.to_sql).must_equal '"users"."id" = 1'
end
end
end
@ -1059,7 +1059,7 @@ module Arel
condition = table["id"].eq("1")
assert_not table.able_to_type_cast?
condition.to_sql.must_equal %("foo"."id" = '1')
_(condition.to_sql).must_equal %("foo"."id" = '1')
end
it "type casts when given an explicit caster" do
@ -1075,7 +1075,7 @@ module Arel
condition = table["id"].eq("1").and(table["other_id"].eq("2"))
assert table.able_to_type_cast?
condition.to_sql.must_equal %("foo"."id" = 1 AND "foo"."other_id" = '2')
_(condition.to_sql).must_equal %("foo"."id" = 1 AND "foo"."other_id" = '2')
end
it "does not type cast SqlLiteral nodes" do
@ -1087,7 +1087,7 @@ module Arel
condition = table["id"].eq(Arel.sql("(select 1)"))
assert table.able_to_type_cast?
condition.to_sql.must_equal %("foo"."id" = (select 1))
_(condition.to_sql).must_equal %("foo"."id" = (select 1))
end
end

View File

@ -8,35 +8,35 @@ module Arel
%i[* /].each do |math_operator|
it "average should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].average.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].average.public_send(math_operator, 2).to_sql).must_be_like %{
AVG("users"."id") #{math_operator} 2
}
end
it "count should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].count.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].count.public_send(math_operator, 2).to_sql).must_be_like %{
COUNT("users"."id") #{math_operator} 2
}
end
it "maximum should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].maximum.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].maximum.public_send(math_operator, 2).to_sql).must_be_like %{
MAX("users"."id") #{math_operator} 2
}
end
it "minimum should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].minimum.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].minimum.public_send(math_operator, 2).to_sql).must_be_like %{
MIN("users"."id") #{math_operator} 2
}
end
it "attribute node should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].public_send(math_operator, 2).to_sql).must_be_like %{
"users"."id" #{math_operator} 2
}
end
@ -45,35 +45,35 @@ module Arel
%i[+ - & | ^ << >>].each do |math_operator|
it "average should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].average.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].average.public_send(math_operator, 2).to_sql).must_be_like %{
(AVG("users"."id") #{math_operator} 2)
}
end
it "count should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].count.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].count.public_send(math_operator, 2).to_sql).must_be_like %{
(COUNT("users"."id") #{math_operator} 2)
}
end
it "maximum should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].maximum.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].maximum.public_send(math_operator, 2).to_sql).must_be_like %{
(MAX("users"."id") #{math_operator} 2)
}
end
it "minimum should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].minimum.public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].minimum.public_send(math_operator, 2).to_sql).must_be_like %{
(MIN("users"."id") #{math_operator} 2)
}
end
it "attribute node should be compatible with #{math_operator}" do
table = Arel::Table.new :users
(table[:id].public_send(math_operator, 2)).to_sql.must_be_like %{
_(table[:id].public_send(math_operator, 2).to_sql).must_be_like %{
("users"."id" #{math_operator} 2)
}
end

View File

@ -24,13 +24,13 @@ module Arel
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.from table
dm.to_sql.must_be_like %{ DELETE FROM "users" }
_(dm.to_sql).must_be_like %{ DELETE FROM "users" }
end
it "chains" do
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.from(table).must_equal dm
_(dm.from(table)).must_equal dm
end
end
@ -40,13 +40,13 @@ module Arel
dm = Arel::DeleteManager.new
dm.from table
dm.where table[:id].eq(10)
dm.to_sql.must_be_like %{ DELETE FROM "users" WHERE "users"."id" = 10}
_(dm.to_sql).must_be_like %{ DELETE FROM "users" WHERE "users"."id" = 10}
end
it "chains" do
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.where(table[:id].eq(10)).must_equal dm
_(dm.where(table[:id].eq(10))).must_equal dm
end
end
end

View File

@ -6,9 +6,9 @@ require "arel"
require_relative "support/fake_record"
class Object
Minitest::Expectation.class_eval do
def must_be_like(other)
gsub(/\s+/, " ").strip.must_equal other.gsub(/\s+/, " ").strip
self.class.new(target.gsub(/\s+/, " ").strip, ctx).must_equal other.gsub(/\s+/, " ").strip
end
end

View File

@ -23,7 +23,7 @@ module Arel
manager = Arel::InsertManager.new
manager.into Table.new(:users)
manager.values = manager.create_values([Arel.sql("*")])
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO \"users\" VALUES (*)
}
end
@ -42,7 +42,7 @@ module Arel
["3", Arel.sql("DEFAULT")],
])
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO \"users\" (\"id\", \"name\") VALUES ('1', 'david'), ('2', 'kir'), ('3', DEFAULT)
}
end
@ -59,7 +59,7 @@ module Arel
[Arel.sql("DEFAULT")],
])
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO \"users\" (\"name\") VALUES (*), (DEFAULT)
}
end
@ -77,7 +77,7 @@ module Arel
[Arel.sql("DEFAULT")],
])
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO \"users\" (\"name\") VALUES ('david'), ('kir'), (DEFAULT)
}
end
@ -87,7 +87,7 @@ module Arel
manager = Arel::InsertManager.new
manager.insert [[table[:bool], false]]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("bool") VALUES ('f')
}
end
@ -96,7 +96,7 @@ module Arel
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.insert [[table[:id], nil]]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("id") VALUES (NULL)
}
end
@ -109,7 +109,7 @@ module Arel
attribute = table[:created_at]
manager.insert [[attribute, time]]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("created_at") VALUES (#{Table.engine.connection.quote time})
}
end
@ -119,7 +119,7 @@ module Arel
manager = Arel::InsertManager.new
manager.into table
manager.insert [[table[:id], 1], [table[:name], "aaron"]]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron')
}
end
@ -128,7 +128,7 @@ module Arel
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.insert [[table[:id], 1], [table[:name], "aaron"]]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron')
}
end
@ -138,7 +138,7 @@ module Arel
manager = Arel::InsertManager.new
manager.insert [[table[:id], 1]]
manager.insert []
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("id") VALUES (1)
}
end
@ -154,14 +154,14 @@ module Arel
describe "into" do
it "takes a Table and chains" do
manager = Arel::InsertManager.new
manager.into(Table.new(:users)).must_equal manager
_(manager.into(Table.new(:users))).must_equal manager
end
it "converts to sql" do
table = Table.new :users
manager = Arel::InsertManager.new
manager.into table
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users"
}
end
@ -173,7 +173,7 @@ module Arel
manager = Arel::InsertManager.new
manager.into table
manager.columns << table[:id]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("id")
}
end
@ -186,7 +186,7 @@ module Arel
manager.into table
manager.values = Nodes::ValuesList.new([[1], [2]])
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" VALUES (1), (2)
}
end
@ -197,7 +197,7 @@ module Arel
manager.into table
manager.values = Arel.sql("DEFAULT VALUES")
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" DEFAULT VALUES
}
end
@ -212,7 +212,7 @@ module Arel
manager.values = Nodes::ValuesList.new([[1, "aaron"], [2, "david"]])
manager.columns << table[:id]
manager.columns << table[:name]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron'), (2, 'david')
}
end
@ -232,7 +232,7 @@ module Arel
manager.select select
manager.columns << table[:id]
manager.columns << table[:name]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
INSERT INTO "users" ("id", "name") (SELECT 1, "aaron")
}
end

View File

@ -6,16 +6,16 @@ module Arel
module Nodes
describe "BindParam" do
it "is equal to other bind params with the same value" do
BindParam.new(1).must_equal(BindParam.new(1))
BindParam.new("foo").must_equal(BindParam.new("foo"))
_(BindParam.new(1)).must_equal(BindParam.new(1))
_(BindParam.new("foo")).must_equal(BindParam.new("foo"))
end
it "is not equal to other nodes" do
BindParam.new(nil).wont_equal(Node.new)
_(BindParam.new(nil)).wont_equal(Node.new)
end
it "is not equal to bind params with different values" do
BindParam.new(1).wont_equal(BindParam.new(2))
_(BindParam.new(1)).wont_equal(BindParam.new(2))
end
end
end

View File

@ -6,7 +6,7 @@ class Arel::Nodes::CountTest < Arel::Spec
describe "as" do
it "should alias the count" do
table = Arel::Table.new :users
table[:id].count.as("foo").to_sql.must_be_like %{
_(table[:id].count.as("foo").to_sql).must_be_like %{
COUNT("users"."id") AS foo
}
end
@ -15,7 +15,7 @@ class Arel::Nodes::CountTest < Arel::Spec
describe "eq" do
it "should compare the count" do
table = Arel::Table.new :users
table[:id].count.eq(2).to_sql.must_be_like %{
_(table[:id].count.eq(2).to_sql).must_be_like %{
COUNT("users"."id") = 2
}
end

View File

@ -9,8 +9,8 @@ describe Arel::Nodes::DeleteStatement do
statement.wheres = %w[a b c]
dolly = statement.clone
dolly.wheres.must_equal statement.wheres
dolly.wheres.wont_be_same_as statement.wheres
_(dolly.wheres).must_equal statement.wheres
_(dolly.wheres).wont_be_same_as statement.wheres
end
end

View File

@ -11,7 +11,7 @@ module Arel
it "returns :==" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
left.operator.must_equal :==
_(left.operator).must_equal :==
end
end
@ -19,7 +19,7 @@ module Arel
it "should equal left" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
left.left.must_equal left.operand1
_(left.left).must_equal left.operand1
end
end
@ -27,7 +27,7 @@ module Arel
it "should equal right" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
left.right.must_equal left.operand2
_(left.right).must_equal left.operand2
end
end
@ -45,7 +45,7 @@ module Arel
attr = Table.new(:users)[:id]
test = attr.eq(10)
test.to_sql engine
engine.connection.quote_count.must_equal 3
_(engine.connection.quote_count).must_equal 3
end
end
end
@ -56,8 +56,8 @@ module Arel
left = attr.eq(10)
right = attr.eq(11)
node = left.or right
node.expr.left.must_equal left
node.expr.right.must_equal right
_(node.expr.left).must_equal left
_(node.expr.right).must_equal right
end
end
@ -67,8 +67,8 @@ module Arel
left = attr.eq(10)
right = attr.eq(11)
node = left.and right
node.left.must_equal left
node.right.must_equal right
_(node.left).must_equal left
_(node.right).must_equal right
end
end

View File

@ -5,7 +5,7 @@ require_relative "../helper"
class Arel::Nodes::ExtractTest < Arel::Spec
it "should extract field" do
table = Arel::Table.new :users
table[:timestamp].extract("date").to_sql.must_be_like %{
_(table[:timestamp].extract("date").to_sql).must_be_like %{
EXTRACT(DATE FROM "users"."timestamp")
}
end
@ -13,7 +13,7 @@ class Arel::Nodes::ExtractTest < Arel::Spec
describe "as" do
it "should alias the extract" do
table = Arel::Table.new :users
table[:timestamp].extract("date").as("foo").to_sql.must_be_like %{
_(table[:timestamp].extract("date").as("foo").to_sql).must_be_like %{
EXTRACT(DATE FROM "users"."timestamp") AS foo
}
end

View File

@ -7,7 +7,7 @@ module Arel
class GroupingTest < Arel::Spec
it "should create Equality nodes" do
grouping = Grouping.new(Nodes.build_quoted("foo"))
grouping.eq("foo").to_sql.must_be_like "('foo') = 'foo'"
_(grouping.eq("foo").to_sql).must_be_like "('foo') = 'foo'"
end
describe "equality" do

View File

@ -10,11 +10,11 @@ describe Arel::Nodes::InsertStatement do
statement.values = %w[x y z]
dolly = statement.clone
dolly.columns.must_equal statement.columns
dolly.values.must_equal statement.values
_(dolly.columns).must_equal statement.columns
_(dolly.values).must_equal statement.values
dolly.columns.wont_be_same_as statement.columns
dolly.values.wont_be_same_as statement.values
_(dolly.columns).wont_be_same_as statement.columns
_(dolly.values).wont_be_same_as statement.values
end
end

View File

@ -10,8 +10,8 @@ module Arel
attr = Table.new(:users)[:id]
expr = attr.eq(10)
node = expr.not
node.must_be_kind_of Not
node.expr.must_equal expr
_(node).must_be_kind_of Not
_(node.expr).must_equal expr
end
end

View File

@ -11,12 +11,12 @@ module Arel
left = attr.eq(10)
right = attr.eq(11)
node = left.or right
node.expr.left.must_equal left
node.expr.right.must_equal right
_(node.expr.left).must_equal left
_(node.expr.right).must_equal right
oror = node.or(right)
oror.expr.left.must_equal node
oror.expr.right.must_equal right
_(oror.expr.left).must_equal node
_(oror.expr.right).must_equal right
end
end

View File

@ -6,7 +6,7 @@ class Arel::Nodes::OverTest < Arel::Spec
describe "as" do
it "should alias the expression" do
table = Arel::Table.new :users
table[:id].count.over.as("foo").to_sql.must_be_like %{
_(table[:id].count.over.as("foo").to_sql).must_be_like %{
COUNT("users"."id") OVER () AS foo
}
end
@ -15,7 +15,7 @@ class Arel::Nodes::OverTest < Arel::Spec
describe "with literal" do
it "should reference the window definition by name" do
table = Arel::Table.new :users
table[:id].count.over("foo").to_sql.must_be_like %{
_(table[:id].count.over("foo").to_sql).must_be_like %{
COUNT("users"."id") OVER "foo"
}
end
@ -24,7 +24,7 @@ class Arel::Nodes::OverTest < Arel::Spec
describe "with SQL literal" do
it "should reference the window definition by name" do
table = Arel::Table.new :users
table[:id].count.over(Arel.sql("foo")).to_sql.must_be_like %{
_(table[:id].count.over(Arel.sql("foo")).to_sql).must_be_like %{
COUNT("users"."id") OVER foo
}
end
@ -33,7 +33,7 @@ class Arel::Nodes::OverTest < Arel::Spec
describe "with no expression" do
it "should use empty definition" do
table = Arel::Table.new :users
table[:id].count.over.to_sql.must_be_like %{
_(table[:id].count.over.to_sql).must_be_like %{
COUNT("users"."id") OVER ()
}
end
@ -43,7 +43,7 @@ class Arel::Nodes::OverTest < Arel::Spec
it "should use definition in sub-expression" do
table = Arel::Table.new :users
window = Arel::Nodes::Window.new.order(table["foo"])
table[:id].count.over(window).to_sql.must_be_like %{
_(table[:id].count.over(window).to_sql).must_be_like %{
COUNT("users"."id") OVER (ORDER BY \"users\".\"foo\")
}
end

View File

@ -8,8 +8,8 @@ describe Arel::Nodes::SelectStatement do
statement = Arel::Nodes::SelectStatement.new %w[a b c]
dolly = statement.clone
dolly.cores.must_equal statement.cores
dolly.cores.wont_be_same_as statement.cores
_(dolly.cores).must_equal statement.cores
_(dolly.cores).wont_be_same_as statement.cores
end
end

View File

@ -17,26 +17,26 @@ module Arel
describe "sql" do
it "makes a sql literal node" do
sql = Arel.sql "foo"
sql.must_be_kind_of Arel::Nodes::SqlLiteral
_(sql).must_be_kind_of Arel::Nodes::SqlLiteral
end
end
describe "count" do
it "makes a count node" do
node = SqlLiteral.new("*").count
compile(node).must_be_like %{ COUNT(*) }
_(compile(node)).must_be_like %{ COUNT(*) }
end
it "makes a distinct node" do
node = SqlLiteral.new("*").count true
compile(node).must_be_like %{ COUNT(DISTINCT *) }
_(compile(node)).must_be_like %{ COUNT(DISTINCT *) }
end
end
describe "equality" do
it "makes an equality node" do
node = SqlLiteral.new("foo").eq(1)
compile(node).must_be_like %{ foo = 1 }
_(compile(node)).must_be_like %{ foo = 1 }
end
it "is equal with equal contents" do
@ -53,14 +53,14 @@ module Arel
describe 'grouped "or" equality' do
it "makes a grouping node with an or node" do
node = SqlLiteral.new("foo").eq_any([1, 2])
compile(node).must_be_like %{ (foo = 1 OR foo = 2) }
_(compile(node)).must_be_like %{ (foo = 1 OR foo = 2) }
end
end
describe 'grouped "and" equality' do
it "makes a grouping node with an and node" do
node = SqlLiteral.new("foo").eq_all([1, 2])
compile(node).must_be_like %{ (foo = 1 AND foo = 2) }
_(compile(node)).must_be_like %{ (foo = 1 AND foo = 2) }
end
end

View File

@ -6,7 +6,7 @@ class Arel::Nodes::SumTest < Arel::Spec
describe "as" do
it "should alias the sum" do
table = Arel::Table.new :users
table[:id].sum.as("foo").to_sql.must_be_like %{
_(table[:id].sum.as("foo").to_sql).must_be_like %{
SUM("users"."id") AS foo
}
end
@ -27,7 +27,7 @@ class Arel::Nodes::SumTest < Arel::Spec
describe "order" do
it "should order the sum" do
table = Arel::Table.new :users
table[:id].sum.desc.to_sql.must_be_like %{
_(table[:id].sum.desc.to_sql).must_be_like %{
SUM("users"."id") DESC
}
end

View File

@ -10,11 +10,11 @@ describe Arel::Nodes::UpdateStatement do
statement.values = %w[x y z]
dolly = statement.clone
dolly.wheres.must_equal statement.wheres
dolly.wheres.wont_be_same_as statement.wheres
_(dolly.wheres).must_equal statement.wheres
_(dolly.wheres).wont_be_same_as statement.wheres
dolly.values.must_equal statement.values
dolly.values.wont_be_same_as statement.values
_(dolly.values).must_equal statement.values
_(dolly.values).wont_be_same_as statement.values
end
end

View File

@ -17,7 +17,7 @@ module Arel
manager = Arel::SelectManager.new
manager.project :id
manager.from table
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT id FROM "users"
}
end
@ -30,7 +30,7 @@ module Arel
manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order :foo
manager.to_sql.must_be_like %{ SELECT * FROM "users" ORDER BY foo }
_(manager.to_sql).must_be_like %{ SELECT * FROM "users" ORDER BY foo }
end
end
@ -40,7 +40,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.group :foo
manager.to_sql.must_be_like %{ SELECT FROM "users" GROUP BY foo }
_(manager.to_sql).must_be_like %{ SELECT FROM "users" GROUP BY foo }
end
end
@ -68,7 +68,7 @@ module Arel
manager = Arel::SelectManager.new
manager.project Arel.sql("name")
manager.from as
manager.to_sql.must_be_like "SELECT name FROM (SELECT * FROM zomg) foo"
_(manager.to_sql).must_be_like "SELECT name FROM (SELECT * FROM zomg) foo"
end
end
@ -80,7 +80,7 @@ module Arel
manager.from table
manager.from "users"
manager.project table["id"]
manager.to_sql.must_be_like 'SELECT "users"."id" FROM users'
_(manager.to_sql).must_be_like 'SELECT "users"."id" FROM users'
end
it "should support any ast" do
@ -95,7 +95,7 @@ module Arel
as = manager2.as Arel.sql("omg")
manager1.from(as)
manager1.to_sql.must_be_like %{
_(manager1.to_sql).must_be_like %{
SELECT lol FROM (SELECT * FROM "users") omg
}
end
@ -106,7 +106,7 @@ module Arel
table = Table.new :users
mgr = table.from
mgr.having Arel.sql("foo")
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" HAVING foo }
end
it "can have multiple items specified separately" do
@ -114,14 +114,14 @@ module Arel
mgr = table.from
mgr.having Arel.sql("foo")
mgr.having Arel.sql("bar")
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
end
it "can receive any node" do
table = Table.new :users
mgr = table.from
mgr.having Arel::Nodes::And.new([Arel.sql("foo"), Arel.sql("bar")])
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
end
end
@ -131,7 +131,7 @@ module Arel
right = table.alias
mgr = table.from
mgr.join(right).on("omg")
mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg }
end
it "converts to sqlliterals with multiple items" do
@ -139,7 +139,7 @@ module Arel
right = table.alias
mgr = table.from
mgr.join(right).on("omg", "123")
mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg AND 123 }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg AND 123 }
end
end
end
@ -150,7 +150,7 @@ module Arel
mgr = table.from
m2 = mgr.clone
m2.project "foo"
mgr.to_sql.wont_equal m2.to_sql
_(mgr.to_sql).wont_equal m2.to_sql
end
it "makes updates to the correct copy" do
@ -159,8 +159,8 @@ module Arel
m2 = mgr.clone
m3 = m2.clone
m2.project "foo"
mgr.to_sql.wont_equal m2.to_sql
m3.to_sql.must_equal mgr.to_sql
_(mgr.to_sql).wont_equal m2.to_sql
_(m3.to_sql).must_equal mgr.to_sql
end
end
@ -169,7 +169,7 @@ module Arel
table = Table.new :users, as: "foo"
mgr = table.from
mgr.skip 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" "foo" OFFSET 10 }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" "foo" OFFSET 10 }
end
end
@ -178,13 +178,13 @@ module Arel
table = Table.new :users
mgr = table.from
mgr.skip 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
it "should chain" do
table = Table.new :users
mgr = table.from
mgr.skip(10).to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
_(mgr.skip(10).to_sql).must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
end
@ -193,17 +193,17 @@ module Arel
table = Table.new :users
mgr = table.from
mgr.offset = 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
it "should remove an offset" do
table = Table.new :users
mgr = table.from
mgr.offset = 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" OFFSET 10 }
mgr.offset = nil
mgr.to_sql.must_be_like %{ SELECT FROM "users" }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" }
end
it "should return the offset" do
@ -221,7 +221,7 @@ module Arel
manager.project Nodes::SqlLiteral.new "*"
m2 = Arel::SelectManager.new
m2.project manager.exists
m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) }
_(m2.to_sql).must_be_like %{ SELECT EXISTS (#{manager.to_sql}) }
end
it "can be aliased" do
@ -230,7 +230,7 @@ module Arel
manager.project Nodes::SqlLiteral.new "*"
m2 = Arel::SelectManager.new
m2.project manager.exists.as("foo")
m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) AS foo }
_(m2.to_sql).must_be_like %{ SELECT EXISTS (#{manager.to_sql}) AS foo }
end
end
@ -252,7 +252,7 @@ module Arel
node = @m1.union @m2
# maybe FIXME: decide when wrapper parens are needed
node.to_sql.must_be_like %{
_(node.to_sql).must_be_like %{
( SELECT * FROM "users" WHERE "users"."age" < 18 UNION SELECT * FROM "users" WHERE "users"."age" > 99 )
}
end
@ -260,7 +260,7 @@ module Arel
it "should union all" do
node = @m1.union :all, @m2
node.to_sql.must_be_like %{
_(node.to_sql).must_be_like %{
( SELECT * FROM "users" WHERE "users"."age" < 18 UNION ALL SELECT * FROM "users" WHERE "users"."age" > 99 )
}
end
@ -284,7 +284,7 @@ module Arel
node = @m1.intersect @m2
# maybe FIXME: decide when wrapper parens are needed
node.to_sql.must_be_like %{
_(node.to_sql).must_be_like %{
( SELECT * FROM "users" WHERE "users"."age" > 18 INTERSECT SELECT * FROM "users" WHERE "users"."age" < 99 )
}
end
@ -308,7 +308,7 @@ module Arel
node = @m1.except @m2
# maybe FIXME: decide when wrapper parens are needed
node.to_sql.must_be_like %{
_(node.to_sql).must_be_like %{
( SELECT * FROM "users" WHERE "users"."age" BETWEEN 18 AND 60 EXCEPT SELECT * FROM "users" WHERE "users"."age" BETWEEN 40 AND 99 )
}
end
@ -325,7 +325,7 @@ module Arel
select_manager = comments.project(Arel.star).with(users_as)
.where(comments[:author_id].in(users_top.project(users_top[:id])))
select_manager.to_sql.must_be_like %{
_(select_manager.to_sql).must_be_like %{
WITH "users_top" AS (SELECT "users"."id" FROM "users" WHERE "users"."karma" > 100) SELECT * FROM "comments" WHERE "comments"."author_id" IN (SELECT "users_top"."id" FROM "users_top")
}
end
@ -352,7 +352,7 @@ module Arel
manager.with(:recursive, as_statement).from(replies).project(Arel.star)
sql = manager.to_sql
sql.must_be_like %{
_(sql).must_be_like %{
WITH RECURSIVE "replies" AS (
SELECT "comments"."id", "comments"."parent_id" FROM "comments" WHERE "comments"."id" = 42
UNION
@ -375,7 +375,7 @@ module Arel
it "should return limit" do
manager = Arel::SelectManager.new
manager.take 10
manager.taken.must_equal 10
_(manager.taken).must_equal 10
end
end
@ -384,7 +384,7 @@ module Arel
it "adds a lock node" do
table = Table.new :users
mgr = table.from
mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" FOR UPDATE }
_(mgr.lock.to_sql).must_be_like %{ SELECT FROM "users" FOR UPDATE }
end
end
@ -394,7 +394,7 @@ module Arel
manager = Arel::SelectManager.new
order = table[:id]
manager.order table[:id]
manager.orders.must_equal [order]
_(manager.orders).must_equal [order]
end
end
@ -405,7 +405,7 @@ module Arel
manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order table[:id]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT * FROM "users" ORDER BY "users"."id"
}
end
@ -417,7 +417,7 @@ module Arel
manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order table[:id], table[:name]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT * FROM "users" ORDER BY "users"."id", "users"."name"
}
end
@ -425,7 +425,7 @@ module Arel
it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.order(table[:id]).must_equal manager
_(manager.order(table[:id])).must_equal manager
end
it "has order attributes" do
@ -434,7 +434,7 @@ module Arel
manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order table[:id].desc
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT * FROM "users" ORDER BY "users"."id" DESC
}
end
@ -449,7 +449,7 @@ module Arel
manager.from left
manager.join(right).on(predicate, predicate)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id" AND
@ -469,7 +469,7 @@ module Arel
predicate,
left[:name].eq(right[:name])
)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id" AND
@ -539,7 +539,7 @@ module Arel
manager.from left
manager.join(right).on(predicate)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -554,7 +554,7 @@ module Arel
manager.from left
manager.join(right, Nodes::OuterJoin).on(predicate)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users"
LEFT OUTER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -569,7 +569,7 @@ module Arel
manager.from left
manager.join(right, Nodes::FullOuterJoin).on(predicate)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users"
FULL OUTER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -584,7 +584,7 @@ module Arel
manager.from left
manager.join(right, Nodes::RightOuterJoin).on(predicate)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users"
RIGHT OUTER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -593,7 +593,7 @@ module Arel
it "noops on nil" do
manager = Arel::SelectManager.new
manager.join(nil).must_equal manager
_(manager.join(nil)).must_equal manager
end
it "raises EmptyJoinError on empty" do
@ -616,7 +616,7 @@ module Arel
manager.from left
manager.outer_join(right).on(predicate)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users"
LEFT OUTER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -625,7 +625,7 @@ module Arel
it "noops on nil" do
manager = Arel::SelectManager.new
manager.outer_join(nil).must_equal manager
_(manager.outer_join(nil)).must_equal manager
end
end
@ -660,7 +660,7 @@ module Arel
).as("counts")
joins = users.join(counts).on(counts[:user_id].eq(10))
joins.to_sql.must_be_like %{
_(joins.to_sql).must_be_like %{
SELECT FROM "users" INNER JOIN (SELECT "comments"."user_id" AS user_id, COUNT("comments"."user_id") AS count FROM "comments" GROUP BY "comments"."user_id") counts ON counts."user_id" = 10
}
end
@ -672,9 +672,9 @@ module Arel
mgr = left.join(right)
mgr.project Nodes::SqlLiteral.new("*")
mgr.on(predicate).must_equal mgr
_(mgr.on(predicate)).must_equal mgr
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT * FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -694,7 +694,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.group table[:id]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" GROUP BY "users"."id"
}
end
@ -702,7 +702,7 @@ module Arel
it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.group(table[:id]).must_equal manager
_(manager.group(table[:id])).must_equal manager
end
it "takes multiple args" do
@ -710,7 +710,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.group table[:id], table[:name]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" GROUP BY "users"."id", "users"."name"
}
end
@ -721,7 +721,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.group "foo"
manager.to_sql.must_be_like %{ SELECT FROM "users" GROUP BY foo }
_(manager.to_sql).must_be_like %{ SELECT FROM "users" GROUP BY foo }
end
end
@ -731,7 +731,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window")
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS ()
}
end
@ -741,7 +741,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").order(table["foo"].asc)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ORDER BY "users"."foo" ASC)
}
end
@ -751,7 +751,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").order(table["foo"].asc, table["bar"].desc)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ORDER BY "users"."foo" ASC, "users"."bar" DESC)
}
end
@ -761,7 +761,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").partition(table["bar"])
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar")
}
end
@ -771,7 +771,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").partition(table["foo"]).order(table["foo"].asc)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."foo"
ORDER BY "users"."foo" ASC)
}
@ -782,7 +782,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").partition(table["bar"], table["baz"])
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar", "users"."baz")
}
end
@ -792,7 +792,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").rows(Arel::Nodes::Preceding.new)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS UNBOUNDED PRECEDING)
}
end
@ -802,7 +802,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").rows(Arel::Nodes::Preceding.new(5))
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS 5 PRECEDING)
}
end
@ -812,7 +812,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").rows(Arel::Nodes::Following.new)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS UNBOUNDED FOLLOWING)
}
end
@ -822,7 +822,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").rows(Arel::Nodes::Following.new(5))
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS 5 FOLLOWING)
}
end
@ -832,7 +832,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").rows(Arel::Nodes::CurrentRow.new)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS CURRENT ROW)
}
end
@ -849,7 +849,7 @@ module Arel
Arel::Nodes::Preceding.new,
Arel::Nodes::CurrentRow.new
])))
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
}
end
@ -859,7 +859,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").range(Arel::Nodes::Preceding.new)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE UNBOUNDED PRECEDING)
}
end
@ -869,7 +869,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").range(Arel::Nodes::Preceding.new(5))
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE 5 PRECEDING)
}
end
@ -879,7 +879,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").range(Arel::Nodes::Following.new)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE UNBOUNDED FOLLOWING)
}
end
@ -889,7 +889,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").range(Arel::Nodes::Following.new(5))
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE 5 FOLLOWING)
}
end
@ -899,7 +899,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.window("a_window").range(Arel::Nodes::CurrentRow.new)
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE CURRENT ROW)
}
end
@ -916,7 +916,7 @@ module Arel
Arel::Nodes::Preceding.new,
Arel::Nodes::CurrentRow.new
])))
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
}
end
@ -929,7 +929,7 @@ module Arel
manager.from table
stmt = manager.compile_delete
stmt.to_sql.must_be_like %{ DELETE FROM "users" }
_(stmt.to_sql).must_be_like %{ DELETE FROM "users" }
end
it "copies where" do
@ -939,7 +939,7 @@ module Arel
manager.where table[:id].eq 10
stmt = manager.compile_delete
stmt.to_sql.must_be_like %{
_(stmt.to_sql).must_be_like %{
DELETE FROM "users" WHERE "users"."id" = 10
}
end
@ -951,7 +951,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from table
manager.where table[:id].eq 10
manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 }
_(manager.where_sql).must_be_like %{ WHERE "users"."id" = 10 }
end
it "joins wheres with AND" do
@ -960,7 +960,7 @@ module Arel
manager.from table
manager.where table[:id].eq 10
manager.where table[:id].eq 11
manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."id" = 11}
_(manager.where_sql).must_be_like %{ WHERE "users"."id" = 10 AND "users"."id" = 11}
end
it "handles database specific statements" do
@ -971,7 +971,7 @@ module Arel
manager.from table
manager.where table[:id].eq 10
manager.where table[:name].matches "foo%"
manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."name" ILIKE 'foo%' }
_(manager.where_sql).must_be_like %{ WHERE "users"."id" = 10 AND "users"."name" ILIKE 'foo%' }
Table.engine.connection.visitor = old_visitor
end
@ -979,7 +979,7 @@ module Arel
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
manager.where_sql.must_be_nil
_(manager.where_sql).must_be_nil
end
end
@ -990,7 +990,7 @@ module Arel
manager.from table
stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{
_(stmt.to_sql).must_be_like %{
UPDATE "users" SET "id" = 1
}
end
@ -1001,7 +1001,7 @@ module Arel
manager.from table
stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar }
_(stmt.to_sql).must_be_like %{ UPDATE "users" SET foo = bar }
end
it "copies limits" do
@ -1012,7 +1012,7 @@ module Arel
stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id"))
stmt.key = table["id"]
stmt.to_sql.must_be_like %{
_(stmt.to_sql).must_be_like %{
UPDATE "users" SET foo = bar
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" LIMIT 1)
}
@ -1026,7 +1026,7 @@ module Arel
stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id"))
stmt.key = table["id"]
stmt.to_sql.must_be_like %{
_(stmt.to_sql).must_be_like %{
UPDATE "users" SET foo = bar
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" ORDER BY foo)
}
@ -1039,7 +1039,7 @@ module Arel
manager.from table
stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{
_(stmt.to_sql).must_be_like %{
UPDATE "users" SET "id" = 1 WHERE "users"."id" = 10
}
end
@ -1052,7 +1052,7 @@ module Arel
manager.from table
stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{
_(stmt.to_sql).must_be_like %{
UPDATE "users" SET "id" = 1 WHERE "users"."id" IN (SELECT "users"."id" FROM "users" WHERE "users"."foo" = 10 LIMIT 42)
}
end
@ -1062,20 +1062,20 @@ module Arel
it "takes sql literals" do
manager = Arel::SelectManager.new
manager.project Nodes::SqlLiteral.new "*"
manager.to_sql.must_be_like %{ SELECT * }
_(manager.to_sql).must_be_like %{ SELECT * }
end
it "takes multiple args" do
manager = Arel::SelectManager.new
manager.project Nodes::SqlLiteral.new("foo"),
Nodes::SqlLiteral.new("bar")
manager.to_sql.must_be_like %{ SELECT foo, bar }
_(manager.to_sql).must_be_like %{ SELECT foo, bar }
end
it "takes strings" do
manager = Arel::SelectManager.new
manager.project "*"
manager.to_sql.must_be_like %{ SELECT * }
_(manager.to_sql).must_be_like %{ SELECT * }
end
end
@ -1083,7 +1083,7 @@ module Arel
it "reads projections" do
manager = Arel::SelectManager.new
manager.project Arel.sql("foo"), Arel.sql("bar")
manager.projections.must_equal [Arel.sql("foo"), Arel.sql("bar")]
_(manager.projections).must_equal [Arel.sql("foo"), Arel.sql("bar")]
end
end
@ -1092,7 +1092,7 @@ module Arel
manager = Arel::SelectManager.new
manager.project Arel.sql("foo")
manager.projections = [Arel.sql("bar")]
manager.to_sql.must_be_like %{ SELECT bar }
_(manager.to_sql).must_be_like %{ SELECT bar }
end
end
@ -1104,7 +1104,7 @@ module Arel
manager.where(table["id"].eq(1))
manager.take 1
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT "users"."id"
FROM "users"
WHERE "users"."id" = 1
@ -1114,7 +1114,7 @@ module Arel
it "chains" do
manager = Arel::SelectManager.new
manager.take(1).must_equal manager
_(manager.take(1)).must_equal manager
end
it "removes LIMIT when nil is passed" do
@ -1133,7 +1133,7 @@ module Arel
manager = Arel::SelectManager.new
manager.from(table).project(table["id"])
manager.where(table["id"].eq(1))
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT "users"."id"
FROM "users"
WHERE "users"."id" = 1
@ -1144,7 +1144,7 @@ module Arel
table = Table.new :users
manager = Arel::SelectManager.new
manager.from(table)
manager.project(table["id"]).where(table["id"].eq 1).must_equal manager
_(manager.project(table["id"]).where(table["id"].eq 1)).must_equal manager
end
end
@ -1155,21 +1155,21 @@ module Arel
manager.from table
manager.project table["id"]
manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"'
_(manager.to_sql).must_be_like 'SELECT "users"."id" FROM "users"'
end
it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from(table).project(table["id"]).must_equal manager
manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"'
_(manager.from(table).project(table["id"])).must_equal manager
_(manager.to_sql).must_be_like 'SELECT "users"."id" FROM "users"'
end
end
describe "source" do
it "returns the join source of the select core" do
manager = Arel::SelectManager.new
manager.source.must_equal manager.ast.cores.last.source
_(manager.source).must_equal manager.ast.cores.last.source
end
end
@ -1178,16 +1178,16 @@ module Arel
manager = Arel::SelectManager.new
manager.distinct
manager.ast.cores.last.set_quantifier.class.must_equal Arel::Nodes::Distinct
_(manager.ast.cores.last.set_quantifier.class).must_equal Arel::Nodes::Distinct
manager.distinct(false)
manager.ast.cores.last.set_quantifier.must_be_nil
_(manager.ast.cores.last.set_quantifier).must_be_nil
end
it "chains" do
manager = Arel::SelectManager.new
manager.distinct.must_equal manager
manager.distinct(false).must_equal manager
_(manager.distinct).must_equal manager
_(manager.distinct(false)).must_equal manager
end
end
@ -1197,25 +1197,25 @@ module Arel
table = Table.new :users
manager.distinct_on(table["id"])
manager.ast.cores.last.set_quantifier.must_equal Arel::Nodes::DistinctOn.new(table["id"])
_(manager.ast.cores.last.set_quantifier).must_equal Arel::Nodes::DistinctOn.new(table["id"])
manager.distinct_on(false)
manager.ast.cores.last.set_quantifier.must_be_nil
_(manager.ast.cores.last.set_quantifier).must_be_nil
end
it "chains" do
manager = Arel::SelectManager.new
table = Table.new :users
manager.distinct_on(table["id"]).must_equal manager
manager.distinct_on(false).must_equal manager
_(manager.distinct_on(table["id"])).must_equal manager
_(manager.distinct_on(false)).must_equal manager
end
end
describe "comment" do
it "chains" do
manager = Arel::SelectManager.new
manager.comment("selecting").must_equal manager
_(manager.comment("selecting")).must_equal manager
end
it "appends a comment to the generated query" do
@ -1224,12 +1224,12 @@ module Arel
manager.from(table).project(table["id"])
manager.comment("selecting")
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" /* selecting */
}
manager.comment("selecting", "with", "comment")
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT "users"."id" FROM "users" /* selecting */ /* with */ /* comment */
}
end

View File

@ -52,14 +52,14 @@ module Arel
describe "skip" do
it "should add an offset" do
sm = @relation.skip 2
sm.to_sql.must_be_like "SELECT FROM \"users\" OFFSET 2"
_(sm.to_sql).must_be_like "SELECT FROM \"users\" OFFSET 2"
end
end
describe "having" do
it "adds a having clause" do
mgr = @relation.having @relation[:id].eq(10)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT FROM "users" HAVING "users"."id" = 10
}
end
@ -70,7 +70,7 @@ module Arel
it "noops on nil" do
mgr = @relation.join nil
mgr.to_sql.must_be_like %{ SELECT FROM "users" }
_(mgr.to_sql).must_be_like %{ SELECT FROM "users" }
end
it "raises EmptyJoinError on empty" do
@ -84,7 +84,7 @@ module Arel
predicate = @relation[:id].eq(right[:id])
mgr = @relation.join(right, Nodes::OuterJoin).on(predicate)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT FROM "users"
LEFT OUTER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -98,7 +98,7 @@ module Arel
predicate = @relation[:id].eq(right[:id])
mgr = @relation.outer_join(right).on(predicate)
mgr.to_sql.must_be_like %{
_(mgr.to_sql).must_be_like %{
SELECT FROM "users"
LEFT OUTER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@ -110,7 +110,7 @@ module Arel
describe "group" do
it "should create a group" do
manager = @relation.group @relation[:id]
manager.to_sql.must_be_like %{
_(manager.to_sql).must_be_like %{
SELECT FROM "users" GROUP BY "users"."id"
}
end
@ -119,27 +119,27 @@ module Arel
describe "alias" do
it "should create a node that proxies to a table" do
node = @relation.alias
node.name.must_equal "users_2"
node[:id].relation.must_equal node
_(node.name).must_equal "users_2"
_(node[:id].relation).must_equal node
end
end
describe "new" do
it "should accept a hash" do
rel = Table.new :users, as: "foo"
rel.table_alias.must_equal "foo"
_(rel.table_alias).must_equal "foo"
end
it "ignores as if it equals name" do
rel = Table.new :users, as: "users"
rel.table_alias.must_be_nil
_(rel.table_alias).must_be_nil
end
end
describe "order" do
it "should take an order" do
manager = @relation.order "foo"
manager.to_sql.must_be_like %{ SELECT FROM "users" ORDER BY foo }
_(manager.to_sql).must_be_like %{ SELECT FROM "users" ORDER BY foo }
end
end
@ -147,19 +147,19 @@ module Arel
it "should add a limit" do
manager = @relation.take 1
manager.project Nodes::SqlLiteral.new "*"
manager.to_sql.must_be_like %{ SELECT * FROM "users" LIMIT 1 }
_(manager.to_sql).must_be_like %{ SELECT * FROM "users" LIMIT 1 }
end
end
describe "project" do
it "can project" do
manager = @relation.project Nodes::SqlLiteral.new "*"
manager.to_sql.must_be_like %{ SELECT * FROM "users" }
_(manager.to_sql).must_be_like %{ SELECT * FROM "users" }
end
it "takes multiple parameters" do
manager = @relation.project Nodes::SqlLiteral.new("*"), Nodes::SqlLiteral.new("*")
manager.to_sql.must_be_like %{ SELECT *, * FROM "users" }
_(manager.to_sql).must_be_like %{ SELECT *, * FROM "users" }
end
end
@ -167,8 +167,8 @@ module Arel
it "returns a tree manager" do
manager = @relation.where @relation[:id].eq 1
manager.project @relation[:id]
manager.must_be_kind_of TreeManager
manager.to_sql.must_be_like %{
_(manager).must_be_kind_of TreeManager
_(manager.to_sql).must_be_like %{
SELECT "users"."id"
FROM "users"
WHERE "users"."id" = 1
@ -177,18 +177,18 @@ module Arel
end
it "should have a name" do
@relation.name.must_equal "users"
_(@relation.name).must_equal "users"
end
it "should have a table name" do
@relation.table_name.must_equal "users"
_(@relation.table_name).must_equal "users"
end
describe "[]" do
describe "when given a Symbol" do
it "manufactures an attribute if the symbol names an attribute within the relation" do
column = @relation[:id]
column.name.must_equal :id
_(column.name).must_equal :id
end
end
end

View File

@ -15,7 +15,7 @@ module Arel
um = Arel::UpdateManager.new
um.table table
um.set [[table[:name], Arel::Nodes::BindParam.new(1)]]
um.to_sql.must_be_like %{ UPDATE "users" SET "name" = ? }
_(um.to_sql).must_be_like %{ UPDATE "users" SET "name" = ? }
end
it "handles limit properly" do
@ -34,7 +34,7 @@ module Arel
um = Arel::UpdateManager.new
um.table table
um.set [[table[:name], nil]]
um.to_sql.must_be_like %{ UPDATE "users" SET "name" = NULL }
_(um.to_sql).must_be_like %{ UPDATE "users" SET "name" = NULL }
end
it "takes a string" do
@ -42,7 +42,7 @@ module Arel
um = Arel::UpdateManager.new
um.table table
um.set Nodes::SqlLiteral.new "foo = bar"
um.to_sql.must_be_like %{ UPDATE "users" SET foo = bar }
_(um.to_sql).must_be_like %{ UPDATE "users" SET foo = bar }
end
it "takes a list of lists" do
@ -50,7 +50,7 @@ module Arel
um = Arel::UpdateManager.new
um.table table
um.set [[table[:id], 1], [table[:name], "hello"]]
um.to_sql.must_be_like %{
_(um.to_sql).must_be_like %{
UPDATE "users" SET "id" = 1, "name" = 'hello'
}
end
@ -58,7 +58,7 @@ module Arel
it "chains" do
table = Table.new(:users)
um = Arel::UpdateManager.new
um.set([[table[:id], 1], [table[:name], "hello"]]).must_equal um
_(um.set([[table[:id], 1], [table[:name], "hello"]])).must_equal um
end
end
@ -66,12 +66,12 @@ module Arel
it "generates an update statement" do
um = Arel::UpdateManager.new
um.table Table.new(:users)
um.to_sql.must_be_like %{ UPDATE "users" }
_(um.to_sql).must_be_like %{ UPDATE "users" }
end
it "chains" do
um = Arel::UpdateManager.new
um.table(Table.new(:users)).must_equal um
_(um.table(Table.new(:users))).must_equal um
end
it "generates an update statement with joins" do
@ -84,7 +84,7 @@ module Arel
)
um.table join_source
um.to_sql.must_be_like %{ UPDATE "users" INNER JOIN "posts" }
_(um.to_sql).must_be_like %{ UPDATE "users" INNER JOIN "posts" }
end
end
@ -94,7 +94,7 @@ module Arel
um = Arel::UpdateManager.new
um.table table
um.where table[:id].eq(1)
um.to_sql.must_be_like %{
_(um.to_sql).must_be_like %{
UPDATE "users" WHERE "users"."id" = 1
}
end
@ -103,7 +103,7 @@ module Arel
table = Table.new :users
um = Arel::UpdateManager.new
um.table table
um.where(table[:id].eq(1)).must_equal um
_(um.where(table[:id].eq(1))).must_equal um
end
end
@ -115,11 +115,11 @@ module Arel
end
it "can be set" do
@um.ast.key.must_equal @table[:foo]
_(@um.ast.key).must_equal @table[:foo]
end
it "can be accessed" do
@um.key.must_equal @table[:foo]
_(@um.key).must_equal @table[:foo]
end
end
end

View File

@ -17,7 +17,7 @@ module Arel
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(1)
sql = compile(stmt)
sql.must_be_like "SELECT FETCH FIRST 1 ROWS ONLY"
_(sql).must_be_like "SELECT FETCH FIRST 1 ROWS ONLY"
end
it "uses FETCH FIRST n ROWS in updates with a limit" do
@ -27,20 +27,20 @@ module Arel
stmt.limit = Nodes::Limit.new(Nodes.build_quoted(1))
stmt.key = table[:id]
sql = compile(stmt)
sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT \"users\".\"id\" FROM \"users\" FETCH FIRST 1 ROWS ONLY)"
_(sql).must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT \"users\".\"id\" FROM \"users\" FETCH FIRST 1 ROWS ONLY)"
end
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."name", 'Aaron Patterson', 0, 1) = 0
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."first_name", "users"."last_name", 0, 1) = 0
}
end
@ -49,14 +49,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."first_name", "users"."last_name", 0, 1) = 1
}
end
@ -65,7 +65,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
end

View File

@ -17,7 +17,7 @@ module Arel
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(1)
sql = compile(stmt)
sql.must_be_like "SELECT FIRST 1"
_(sql).must_be_like "SELECT FIRST 1"
end
it "uses FIRST n in updates with a limit" do
@ -27,14 +27,14 @@ module Arel
stmt.limit = Nodes::Limit.new(Nodes.build_quoted(1))
stmt.key = table[:id]
sql = compile(stmt)
sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT FIRST 1 \"users\".\"id\" FROM \"users\")"
_(sql).must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT FIRST 1 \"users\".\"id\" FROM \"users\")"
end
it "uses SKIP n to jump results" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(10)
sql = compile(stmt)
sql.must_be_like "SELECT SKIP 10"
_(sql).must_be_like "SELECT SKIP 10"
end
it "uses SKIP before FIRST" do
@ -42,7 +42,7 @@ module Arel
stmt.limit = Nodes::Limit.new(1)
stmt.offset = Nodes::Offset.new(1)
sql = compile(stmt)
sql.must_be_like "SELECT SKIP 1 FIRST 1"
_(sql).must_be_like "SELECT SKIP 1 FIRST 1"
end
it "uses INNER JOIN to perform joins" do
@ -52,20 +52,20 @@ module Arel
stmt = Nodes::SelectStatement.new([core])
sql = compile(stmt)
sql.must_be_like 'SELECT FROM "posts" INNER JOIN "comments"'
_(sql).must_be_like 'SELECT FROM "posts" INNER JOIN "comments"'
end
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
CASE WHEN "users"."name" = 'Aaron Patterson' OR ("users"."name" IS NULL AND 'Aaron Patterson' IS NULL) THEN 0 ELSE 1 END = 0
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
CASE WHEN "users"."first_name" = "users"."last_name" OR ("users"."first_name" IS NULL AND "users"."last_name" IS NULL) THEN 0 ELSE 1 END = 0
}
end
@ -74,14 +74,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
CASE WHEN "users"."first_name" = "users"."last_name" OR ("users"."first_name" IS NULL AND "users"."last_name" IS NULL) THEN 0 ELSE 1 END = 1
}
end
@ -90,7 +90,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
end

View File

@ -17,7 +17,7 @@ module Arel
it "should not modify query if no offset or limit" do
stmt = Nodes::SelectStatement.new
sql = compile(stmt)
sql.must_be_like "SELECT"
_(sql).must_be_like "SELECT"
end
it "should go over table PK if no .order() or .group()" do
@ -25,7 +25,7 @@ module Arel
stmt.cores.first.from = @table
stmt.limit = Nodes::Limit.new(10)
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY \"users\".\"id\") as _row_num FROM \"users\") as _t WHERE _row_num BETWEEN 1 AND 10"
_(sql).must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY \"users\".\"id\") as _row_num FROM \"users\") as _t WHERE _row_num BETWEEN 1 AND 10"
end
it "caches the PK lookup for order" do
@ -53,7 +53,7 @@ module Arel
stmt.limit = Nodes::Limit.new(10)
sql = compile(stmt)
sql.must_be_like "DELETE TOP (10) FROM \"users\""
_(sql).must_be_like "DELETE TOP (10) FROM \"users\""
end
it "should go over query ORDER BY if .order()" do
@ -61,7 +61,7 @@ module Arel
stmt.limit = Nodes::Limit.new(10)
stmt.orders << Nodes::SqlLiteral.new("order_by")
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY order_by) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10"
_(sql).must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY order_by) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10"
end
it "should go over query GROUP BY if no .order() and there is .group()" do
@ -69,7 +69,7 @@ module Arel
stmt.cores.first.groups << Nodes::SqlLiteral.new("group_by")
stmt.limit = Nodes::Limit.new(10)
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY group_by) as _row_num GROUP BY group_by) as _t WHERE _row_num BETWEEN 1 AND 10"
_(sql).must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY group_by) as _row_num GROUP BY group_by) as _t WHERE _row_num BETWEEN 1 AND 10"
end
it "should use BETWEEN if both .limit() and .offset" do
@ -77,14 +77,14 @@ module Arel
stmt.limit = Nodes::Limit.new(10)
stmt.offset = Nodes::Offset.new(20)
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 21 AND 30"
_(sql).must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 21 AND 30"
end
it "should use >= if only .offset" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(20)
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num >= 21"
_(sql).must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num >= 21"
end
it "should generate subquery for .count" do
@ -92,20 +92,20 @@ module Arel
stmt.limit = Nodes::Limit.new(10)
stmt.cores.first.projections << Nodes::Count.new("*")
sql = compile(stmt)
sql.must_be_like "SELECT COUNT(1) as count_id FROM (SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10) AS subquery"
_(sql).must_be_like "SELECT COUNT(1) as count_id FROM (SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10) AS subquery"
end
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
EXISTS (VALUES ("users"."name") INTERSECT VALUES ('Aaron Patterson'))
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
EXISTS (VALUES ("users"."first_name") INTERSECT VALUES ("users"."last_name"))
}
end
@ -114,14 +114,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
NOT EXISTS (VALUES ("users"."first_name") INTERSECT VALUES ("users"."last_name"))
}
end
@ -130,7 +130,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
end

View File

@ -20,7 +20,7 @@ module Arel
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(1)
sql = compile(stmt)
sql.must_be_like "SELECT FROM DUAL LIMIT 18446744073709551615 OFFSET 1"
_(sql).must_be_like "SELECT FROM DUAL LIMIT 18446744073709551615 OFFSET 1"
end
it "should escape LIMIT" do
@ -33,18 +33,18 @@ module Arel
it "uses DUAL for empty from" do
stmt = Nodes::SelectStatement.new
sql = compile(stmt)
sql.must_be_like "SELECT FROM DUAL"
_(sql).must_be_like "SELECT FROM DUAL"
end
describe "locking" do
it "defaults to FOR UPDATE when locking" do
node = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
compile(node).must_be_like "FOR UPDATE"
_(compile(node)).must_be_like "FOR UPDATE"
end
it "allows a custom string to be used as a lock" do
node = Nodes::Lock.new(Arel.sql("LOCK IN SHARE MODE"))
compile(node).must_be_like "LOCK IN SHARE MODE"
_(compile(node)).must_be_like "LOCK IN SHARE MODE"
end
end
@ -52,7 +52,7 @@ module Arel
it "concats columns" do
@table = Table.new(:users)
query = @table[:name].concat(@table[:name])
compile(query).must_be_like %{
_(compile(query)).must_be_like %{
CONCAT("users"."name", "users"."name")
}
end
@ -60,7 +60,7 @@ module Arel
it "concats a string" do
@table = Table.new(:users)
query = @table[:name].concat(Nodes.build_quoted("abc"))
compile(query).must_be_like %{
_(compile(query)).must_be_like %{
CONCAT("users"."name", 'abc')
}
end
@ -69,14 +69,14 @@ module Arel
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."name" <=> 'Aaron Patterson'
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."first_name" <=> "users"."last_name"
}
end
@ -85,14 +85,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" <=> NULL }
_(sql).must_be_like %{ "users"."name" <=> NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
NOT "users"."first_name" <=> "users"."last_name"
}
end
@ -101,7 +101,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ NOT "users"."name" <=> NULL }
_(sql).must_be_like %{ NOT "users"."name" <=> NULL }
end
end
@ -113,8 +113,8 @@ module Arel
it "should know how to visit" do
node = @table[:name].matches_regexp("foo.*")
node.must_be_kind_of Nodes::Regexp
compile(node).must_be_like %{
_(node).must_be_kind_of Nodes::Regexp
_(compile(node)).must_be_like %{
"users"."name" REGEXP 'foo.*'
}
end
@ -122,7 +122,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].matches_regexp("foo.*"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" REGEXP 'foo.*')
}
end
@ -136,8 +136,8 @@ module Arel
it "should know how to visit" do
node = @table[:name].does_not_match_regexp("foo.*")
node.must_be_kind_of Nodes::NotRegexp
compile(node).must_be_like %{
_(node).must_be_kind_of Nodes::NotRegexp
_(compile(node)).must_be_like %{
"users"."name" NOT REGEXP 'foo.*'
}
end
@ -145,7 +145,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].does_not_match_regexp("foo.*"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT REGEXP 'foo.*')
}
end

View File

@ -18,7 +18,7 @@ module Arel
left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10")
right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20")
sql = compile Nodes::Except.new(left, right)
sql.must_be_like %{
_(sql).must_be_like %{
( SELECT * FROM users WHERE age > 10 MINUS SELECT * FROM users WHERE age > 20 )
}
end
@ -28,7 +28,7 @@ module Arel
stmt.offset = Nodes::Offset.new(1)
stmt.limit = Nodes::Limit.new(10)
sql = compile(stmt)
sql.must_be_like "SELECT OFFSET 1 ROWS FETCH FIRST 10 ROWS ONLY"
_(sql).must_be_like "SELECT OFFSET 1 ROWS FETCH FIRST 10 ROWS ONLY"
end
describe "locking" do
@ -43,7 +43,7 @@ module Arel
it "defaults to FOR UPDATE when locking" do
node = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
compile(node).must_be_like "FOR UPDATE"
_(compile(node)).must_be_like "FOR UPDATE"
end
end
@ -51,7 +51,7 @@ module Arel
it "increments each bind param" do
query = @table[:name].eq(Arel::Nodes::BindParam.new(1))
.and(@table[:id].eq(Arel::Nodes::BindParam.new(1)))
compile(query).must_be_like %{
_(compile(query)).must_be_like %{
"users"."name" = :a1 AND "users"."id" = :a2
}
end
@ -60,14 +60,14 @@ module Arel
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."name", 'Aaron Patterson', 0, 1) = 0
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."first_name", "users"."last_name", 0, 1) = 0
}
end
@ -76,14 +76,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."first_name", "users"."last_name", 0, 1) = 1
}
end
@ -92,7 +92,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
end

View File

@ -21,7 +21,7 @@ module Arel
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
stmt.orders << Nodes::SqlLiteral.new("foo")
sql = compile(stmt)
sql.must_be_like %{
_(sql).must_be_like %{
SELECT #{select} ORDER BY alias_0__
}
end
@ -35,7 +35,7 @@ module Arel
sql = compile(stmt)
sql2 = compile(stmt)
sql.must_equal sql2
_(sql).must_equal sql2
end
it "splits orders with commas" do
@ -45,7 +45,7 @@ module Arel
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
stmt.orders << Nodes::SqlLiteral.new("foo, bar")
sql = compile(stmt)
sql.must_be_like %{
_(sql).must_be_like %{
SELECT #{select} ORDER BY alias_0__, alias_1__
}
end
@ -57,7 +57,7 @@ module Arel
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
stmt.orders << Nodes::SqlLiteral.new("NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)")
sql = compile(stmt)
sql.must_be_like %{
_(sql).must_be_like %{
SELECT #{select} ORDER BY alias_0__ DESC, alias_1__
}
end
@ -68,7 +68,7 @@ module Arel
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{ SELECT WHERE ROWNUM <= 10 }
_(sql).must_be_like %{ SELECT WHERE ROWNUM <= 10 }
end
it "is idempotent" do
@ -77,7 +77,7 @@ module Arel
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql2 = compile stmt
sql.must_equal sql2
_(sql).must_equal sql2
end
it "creates a subquery when there is order_by" do
@ -85,7 +85,7 @@ module Arel
stmt.orders << Nodes::SqlLiteral.new("foo")
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{
_(sql).must_be_like %{
SELECT * FROM (SELECT ORDER BY foo ) WHERE ROWNUM <= 10
}
end
@ -95,7 +95,7 @@ module Arel
stmt.cores.first.groups << Nodes::SqlLiteral.new("foo")
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{
_(sql).must_be_like %{
SELECT * FROM (SELECT GROUP BY foo ) WHERE ROWNUM <= 10
}
end
@ -106,7 +106,7 @@ module Arel
stmt.cores.first.projections << Nodes::SqlLiteral.new("id")
stmt.limit = Arel::Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{
_(sql).must_be_like %{
SELECT * FROM (SELECT DISTINCT id ) WHERE ROWNUM <= 10
}
end
@ -116,7 +116,7 @@ module Arel
stmt.limit = Nodes::Limit.new(10)
stmt.offset = Nodes::Offset.new(10)
sql = compile stmt
sql.must_be_like %{
_(sql).must_be_like %{
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM (SELECT ) raw_sql_
@ -131,7 +131,7 @@ module Arel
stmt.limit = Nodes::Limit.new(Nodes::BindParam.new(1))
stmt.offset = Nodes::Offset.new(Nodes::BindParam.new(1))
sql = compile stmt
sql.must_be_like %{
_(sql).must_be_like %{
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM (SELECT ) raw_sql_
@ -147,7 +147,7 @@ module Arel
stmt.offset = Nodes::Offset.new(10)
sql = compile stmt
sql2 = compile stmt
sql.must_equal sql2
_(sql).must_equal sql2
end
end
@ -156,7 +156,7 @@ module Arel
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(10)
sql = compile stmt
sql.must_be_like %{
_(sql).must_be_like %{
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM (SELECT) raw_sql_
@ -171,7 +171,7 @@ module Arel
left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10")
right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20")
sql = compile Nodes::Except.new(left, right)
sql.must_be_like %{
_(sql).must_be_like %{
( SELECT * FROM users WHERE age > 10 MINUS SELECT * FROM users WHERE age > 20 )
}
end
@ -179,7 +179,7 @@ module Arel
describe "locking" do
it "defaults to FOR UPDATE when locking" do
node = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
compile(node).must_be_like "FOR UPDATE"
_(compile(node)).must_be_like "FOR UPDATE"
end
end
@ -187,7 +187,7 @@ module Arel
it "increments each bind param" do
query = @table[:name].eq(Arel::Nodes::BindParam.new(1))
.and(@table[:id].eq(Arel::Nodes::BindParam.new(1)))
compile(query).must_be_like %{
_(compile(query)).must_be_like %{
"users"."name" = :a1 AND "users"."id" = :a2
}
end
@ -196,14 +196,14 @@ module Arel
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."name", 'Aaron Patterson', 0, 1) = 0
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."first_name", "users"."last_name", 0, 1) = 0
}
end
@ -212,14 +212,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
DECODE("users"."first_name", "users"."last_name", 0, 1) = 1
}
end
@ -228,7 +228,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
end

View File

@ -17,14 +17,14 @@ module Arel
describe "locking" do
it "defaults to FOR UPDATE" do
compile(Nodes::Lock.new(Arel.sql("FOR UPDATE"))).must_be_like %{
_(compile(Nodes::Lock.new(Arel.sql("FOR UPDATE")))).must_be_like %{
FOR UPDATE
}
end
it "allows a custom string to be used as a lock" do
node = Nodes::Lock.new(Arel.sql("FOR SHARE"))
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
FOR SHARE
}
end
@ -54,14 +54,14 @@ module Arel
it "encloses LATERAL queries in parens" do
subquery = @table.project(:id).where(@table[:name].matches("foo%"))
compile(subquery.lateral).must_be_like %{
_(compile(subquery.lateral)).must_be_like %{
LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%')
}
end
it "produces LATERAL queries with alias" do
subquery = @table.project(:id).where(@table[:name].matches("foo%"))
compile(subquery.lateral("bar")).must_be_like %{
_(compile(subquery.lateral("bar"))).must_be_like %{
LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') bar
}
end
@ -69,24 +69,24 @@ module Arel
describe "Nodes::Matches" do
it "should know how to visit" do
node = @table[:name].matches("foo%")
node.must_be_kind_of Nodes::Matches
node.case_sensitive.must_equal(false)
compile(node).must_be_like %{
_(node).must_be_kind_of Nodes::Matches
_(node.case_sensitive).must_equal(false)
_(compile(node)).must_be_like %{
"users"."name" ILIKE 'foo%'
}
end
it "should know how to visit case sensitive" do
node = @table[:name].matches("foo%", nil, true)
node.case_sensitive.must_equal(true)
compile(node).must_be_like %{
_(node.case_sensitive).must_equal(true)
_(compile(node)).must_be_like %{
"users"."name" LIKE 'foo%'
}
end
it "can handle ESCAPE" do
node = @table[:name].matches("foo!%", "!")
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."name" ILIKE 'foo!%' ESCAPE '!'
}
end
@ -94,7 +94,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].matches("foo%"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%')
}
end
@ -103,24 +103,24 @@ module Arel
describe "Nodes::DoesNotMatch" do
it "should know how to visit" do
node = @table[:name].does_not_match("foo%")
node.must_be_kind_of Nodes::DoesNotMatch
node.case_sensitive.must_equal(false)
compile(node).must_be_like %{
_(node).must_be_kind_of Nodes::DoesNotMatch
_(node.case_sensitive).must_equal(false)
_(compile(node)).must_be_like %{
"users"."name" NOT ILIKE 'foo%'
}
end
it "should know how to visit case sensitive" do
node = @table[:name].does_not_match("foo%", nil, true)
node.case_sensitive.must_equal(true)
compile(node).must_be_like %{
_(node.case_sensitive).must_equal(true)
_(compile(node)).must_be_like %{
"users"."name" NOT LIKE 'foo%'
}
end
it "can handle ESCAPE" do
node = @table[:name].does_not_match("foo!%", "!")
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."name" NOT ILIKE 'foo!%' ESCAPE '!'
}
end
@ -128,7 +128,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].does_not_match("foo%"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT ILIKE 'foo%')
}
end
@ -137,18 +137,18 @@ module Arel
describe "Nodes::Regexp" do
it "should know how to visit" do
node = @table[:name].matches_regexp("foo.*")
node.must_be_kind_of Nodes::Regexp
node.case_sensitive.must_equal(true)
compile(node).must_be_like %{
_(node).must_be_kind_of Nodes::Regexp
_(node.case_sensitive).must_equal(true)
_(compile(node)).must_be_like %{
"users"."name" ~ 'foo.*'
}
end
it "can handle case insensitive" do
node = @table[:name].matches_regexp("foo.*", false)
node.must_be_kind_of Nodes::Regexp
node.case_sensitive.must_equal(false)
compile(node).must_be_like %{
_(node).must_be_kind_of Nodes::Regexp
_(node.case_sensitive).must_equal(false)
_(compile(node)).must_be_like %{
"users"."name" ~* 'foo.*'
}
end
@ -156,7 +156,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].matches_regexp("foo.*"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ~ 'foo.*')
}
end
@ -165,17 +165,17 @@ module Arel
describe "Nodes::NotRegexp" do
it "should know how to visit" do
node = @table[:name].does_not_match_regexp("foo.*")
node.must_be_kind_of Nodes::NotRegexp
node.case_sensitive.must_equal(true)
compile(node).must_be_like %{
_(node).must_be_kind_of Nodes::NotRegexp
_(node.case_sensitive).must_equal(true)
_(compile(node)).must_be_like %{
"users"."name" !~ 'foo.*'
}
end
it "can handle case insensitive" do
node = @table[:name].does_not_match_regexp("foo.*", false)
node.case_sensitive.must_equal(false)
compile(node).must_be_like %{
_(node.case_sensitive).must_equal(false)
_(compile(node)).must_be_like %{
"users"."name" !~* 'foo.*'
}
end
@ -183,7 +183,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].does_not_match_regexp("foo.*"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" !~ 'foo.*')
}
end
@ -193,7 +193,7 @@ module Arel
it "increments each bind param" do
query = @table[:name].eq(Arel::Nodes::BindParam.new(1))
.and(@table[:id].eq(Arel::Nodes::BindParam.new(1)))
compile(query).must_be_like %{
_(compile(query)).must_be_like %{
"users"."name" = $1 AND "users"."id" = $2
}
end
@ -202,7 +202,7 @@ module Arel
describe "Nodes::Cube" do
it "should know how to visit with array arguments" do
node = Arel::Nodes::Cube.new([@table[:name], @table[:bool]])
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CUBE( "users"."name", "users"."bool" )
}
end
@ -210,7 +210,7 @@ module Arel
it "should know how to visit with CubeDimension Argument" do
dimensions = Arel::Nodes::GroupingElement.new([@table[:name], @table[:bool]])
node = Arel::Nodes::Cube.new(dimensions)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CUBE( "users"."name", "users"."bool" )
}
end
@ -219,7 +219,7 @@ module Arel
dim1 = Arel::Nodes::GroupingElement.new(@table[:name])
dim2 = Arel::Nodes::GroupingElement.new([@table[:bool], @table[:created_at]])
node = Arel::Nodes::Cube.new([dim1, dim2])
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CUBE( ( "users"."name" ), ( "users"."bool", "users"."created_at" ) )
}
end
@ -228,7 +228,7 @@ module Arel
describe "Nodes::GroupingSet" do
it "should know how to visit with array arguments" do
node = Arel::Nodes::GroupingSet.new([@table[:name], @table[:bool]])
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
GROUPING SETS( "users"."name", "users"."bool" )
}
end
@ -236,7 +236,7 @@ module Arel
it "should know how to visit with CubeDimension Argument" do
group = Arel::Nodes::GroupingElement.new([@table[:name], @table[:bool]])
node = Arel::Nodes::GroupingSet.new(group)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
GROUPING SETS( "users"."name", "users"."bool" )
}
end
@ -245,7 +245,7 @@ module Arel
group1 = Arel::Nodes::GroupingElement.new(@table[:name])
group2 = Arel::Nodes::GroupingElement.new([@table[:bool], @table[:created_at]])
node = Arel::Nodes::GroupingSet.new([group1, group2])
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
GROUPING SETS( ( "users"."name" ), ( "users"."bool", "users"."created_at" ) )
}
end
@ -254,7 +254,7 @@ module Arel
describe "Nodes::RollUp" do
it "should know how to visit with array arguments" do
node = Arel::Nodes::RollUp.new([@table[:name], @table[:bool]])
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
ROLLUP( "users"."name", "users"."bool" )
}
end
@ -262,7 +262,7 @@ module Arel
it "should know how to visit with CubeDimension Argument" do
group = Arel::Nodes::GroupingElement.new([@table[:name], @table[:bool]])
node = Arel::Nodes::RollUp.new(group)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
ROLLUP( "users"."name", "users"."bool" )
}
end
@ -271,7 +271,7 @@ module Arel
group1 = Arel::Nodes::GroupingElement.new(@table[:name])
group2 = Arel::Nodes::GroupingElement.new([@table[:bool], @table[:created_at]])
node = Arel::Nodes::RollUp.new([group1, group2])
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
ROLLUP( ( "users"."name" ), ( "users"."bool", "users"."created_at" ) )
}
end
@ -280,14 +280,14 @@ module Arel
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."name" IS NOT DISTINCT FROM 'Aaron Patterson'
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."first_name" IS NOT DISTINCT FROM "users"."last_name"
}
end
@ -296,14 +296,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT DISTINCT FROM NULL }
_(sql).must_be_like %{ "users"."name" IS NOT DISTINCT FROM NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."first_name" IS DISTINCT FROM "users"."last_name"
}
end
@ -312,7 +312,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS DISTINCT FROM NULL }
_(sql).must_be_like %{ "users"."name" IS DISTINCT FROM NULL }
end
end
end

View File

@ -17,7 +17,7 @@ module Arel
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(1)
sql = @visitor.accept(stmt, Collectors::SQLString.new).value
sql.must_be_like "SELECT LIMIT -1 OFFSET 1"
_(sql).must_be_like "SELECT LIMIT -1 OFFSET 1"
end
it "does not support locking" do
@ -35,14 +35,14 @@ module Arel
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."name" IS 'Aaron Patterson'
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."first_name" IS "users"."last_name"
}
end
@ -51,14 +51,14 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."first_name" IS NOT "users"."last_name"
}
end
@ -67,7 +67,7 @@ module Arel
@table = Table.new(:users)
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
end

View File

@ -20,14 +20,14 @@ module Arel
it "works with BindParams" do
node = Nodes::BindParam.new(1)
sql = compile node
sql.must_be_like "?"
_(sql).must_be_like "?"
end
it "does not quote BindParams used as part of a ValuesList" do
bp = Nodes::BindParam.new(1)
values = Nodes::ValuesList.new([[bp]])
sql = compile values
sql.must_be_like "VALUES (?)"
_(sql).must_be_like "VALUES (?)"
end
it "can define a dispatch method" do
@ -49,7 +49,7 @@ module Arel
it "should not quote sql literals" do
node = @table[Arel.star]
sql = compile node
sql.must_be_like '"users".*'
_(sql).must_be_like '"users".*'
end
it "should visit named functions" do
@ -60,13 +60,13 @@ module Arel
it "should chain predications on named functions" do
function = Nodes::NamedFunction.new("omg", [Arel.star])
sql = compile(function.eq(2))
sql.must_be_like %{ omg(*) = 2 }
_(sql).must_be_like %{ omg(*) = 2 }
end
it "should handle nil with named functions" do
function = Nodes::NamedFunction.new("omg", [Arel.star])
sql = compile(function.eq(nil))
sql.must_be_like %{ omg(*) IS NULL }
_(sql).must_be_like %{ omg(*) IS NULL }
end
it "should visit built-in functions" do
@ -116,7 +116,7 @@ module Arel
describe "Nodes::Equality" do
it "should escape strings" do
test = Table.new(:users)[:name].eq "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"users"."name" = 'Aaron Patterson'
}
end
@ -125,19 +125,19 @@ module Arel
table = Table.new(:users)
val = Nodes.build_quoted(false, table[:active])
sql = compile Nodes::Equality.new(val, val)
sql.must_be_like %{ 'f' = 'f' }
_(sql).must_be_like %{ 'f' = 'f' }
end
it "should handle nil" do
sql = compile Nodes::Equality.new(@table[:name], nil)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::Grouping" do
it "wraps nested groupings in brackets only once" do
sql = compile Nodes::Grouping.new(Nodes::Grouping.new(Nodes.build_quoted("foo")))
sql.must_equal "('foo')"
_(sql).must_equal "('foo')"
end
end
@ -145,27 +145,27 @@ module Arel
it "should handle false" do
val = Nodes.build_quoted(false, @table[:active])
sql = compile Nodes::NotEqual.new(@table[:active], val)
sql.must_be_like %{ "users"."active" != 'f' }
_(sql).must_be_like %{ "users"."active" != 'f' }
end
it "should handle nil" do
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::NotEqual.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
describe "Nodes::IsNotDistinctFrom" do
it "should construct a valid generic SQL statement" do
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
CASE WHEN "users"."name" = 'Aaron Patterson' OR ("users"."name" IS NULL AND 'Aaron Patterson' IS NULL) THEN 0 ELSE 1 END = 0
}
end
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_not_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
CASE WHEN "users"."first_name" = "users"."last_name" OR ("users"."first_name" IS NULL AND "users"."last_name" IS NULL) THEN 0 ELSE 1 END = 0
}
end
@ -173,14 +173,14 @@ module Arel
it "should handle nil" do
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsNotDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NULL }
_(sql).must_be_like %{ "users"."name" IS NULL }
end
end
describe "Nodes::IsDistinctFrom" do
it "should handle column names on both sides" do
test = Table.new(:users)[:first_name].is_distinct_from Table.new(:users)[:last_name]
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
CASE WHEN "users"."first_name" = "users"."last_name" OR ("users"."first_name" IS NULL AND "users"."last_name" IS NULL) THEN 0 ELSE 1 END = 1
}
end
@ -188,7 +188,7 @@ module Arel
it "should handle nil" do
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::IsDistinctFrom.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
_(sql).must_be_like %{ "users"."name" IS NOT NULL }
end
end
@ -199,12 +199,12 @@ module Arel
].each do |obj|
val = Nodes.build_quoted(obj, @table[:active])
sql = compile Nodes::NotEqual.new(@table[:name], val)
sql.must_be_like %{ "users"."name" != ':\\'(' }
_(sql).must_be_like %{ "users"."name" != ':\\'(' }
end
end
it "should visit_Class" do
compile(Nodes.build_quoted(DateTime)).must_equal "'DateTime'"
_(compile(Nodes.build_quoted(DateTime))).must_equal "'DateTime'"
end
it "should escape LIMIT" do
@ -232,30 +232,30 @@ module Arel
test = table[:created_at].eq dt
sql = compile test
sql.must_be_like %{"users"."created_at" = '#{dt.strftime("%Y-%m-%d %H:%M:%S")}'}
_(sql).must_be_like %{"users"."created_at" = '#{dt.strftime("%Y-%m-%d %H:%M:%S")}'}
end
it "should visit_Float" do
test = Table.new(:products)[:price].eq 2.14
sql = compile test
sql.must_be_like %{"products"."price" = 2.14}
_(sql).must_be_like %{"products"."price" = 2.14}
end
it "should visit_Not" do
sql = compile Nodes::Not.new(Arel.sql("foo"))
sql.must_be_like "NOT (foo)"
_(sql).must_be_like "NOT (foo)"
end
it "should apply Not to the whole expression" do
node = Nodes::And.new [@attr.eq(10), @attr.eq(11)]
sql = compile Nodes::Not.new(node)
sql.must_be_like %{NOT ("users"."id" = 10 AND "users"."id" = 11)}
_(sql).must_be_like %{NOT ("users"."id" = 10 AND "users"."id" = 11)}
end
it "should visit_As" do
as = Nodes::As.new(Arel.sql("foo"), Arel.sql("bar"))
sql = compile as
sql.must_be_like "foo AS bar"
_(sql).must_be_like "foo AS bar"
end
it "should visit_Integer" do
@ -280,11 +280,11 @@ module Arel
test = table[:created_at].eq dt
sql = compile test
sql.must_be_like %{"users"."created_at" = '#{dt.strftime("%Y-%m-%d")}'}
_(sql).must_be_like %{"users"."created_at" = '#{dt.strftime("%Y-%m-%d")}'}
end
it "should visit_NilClass" do
compile(Nodes.build_quoted(nil)).must_be_like "NULL"
_(compile(Nodes.build_quoted(nil))).must_be_like "NULL"
end
it "unsupported input should raise UnsupportedVisitError" do
@ -294,19 +294,19 @@ module Arel
it "should visit_Arel_SelectManager, which is a subquery" do
mgr = Table.new(:foo).project(:bar)
compile(mgr).must_be_like '(SELECT bar FROM "foo")'
_(compile(mgr)).must_be_like '(SELECT bar FROM "foo")'
end
it "should visit_Arel_Nodes_And" do
node = Nodes::And.new [@attr.eq(10), @attr.eq(11)]
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" = 10 AND "users"."id" = 11
}
end
it "should visit_Arel_Nodes_Or" do
node = Nodes::Or.new @attr.eq(10), @attr.eq(11)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" = 10 OR "users"."id" = 11
}
end
@ -317,7 +317,7 @@ module Arel
Nodes::UnqualifiedColumn.new(column),
Nodes::UnqualifiedColumn.new(column)
)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"id" = "id"
}
end
@ -329,20 +329,20 @@ module Arel
it "should visit_TrueClass" do
test = Table.new(:users)[:bool].eq(true)
compile(test).must_be_like %{ "users"."bool" = 't' }
_(compile(test)).must_be_like %{ "users"."bool" = 't' }
end
describe "Nodes::Matches" do
it "should know how to visit" do
node = @table[:name].matches("foo%")
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."name" LIKE 'foo%'
}
end
it "can handle ESCAPE" do
node = @table[:name].matches("foo!%", "!")
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."name" LIKE 'foo!%' ESCAPE '!'
}
end
@ -350,7 +350,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].matches("foo%"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" LIKE 'foo%')
}
end
@ -359,14 +359,14 @@ module Arel
describe "Nodes::DoesNotMatch" do
it "should know how to visit" do
node = @table[:name].does_not_match("foo%")
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."name" NOT LIKE 'foo%'
}
end
it "can handle ESCAPE" do
node = @table[:name].does_not_match("foo!%", "!")
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."name" NOT LIKE 'foo!%' ESCAPE '!'
}
end
@ -374,7 +374,7 @@ module Arel
it "can handle subqueries" do
subquery = @table.project(:id).where(@table[:name].does_not_match("foo%"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT LIKE 'foo%')
}
end
@ -383,7 +383,7 @@ module Arel
describe "Nodes::Ordering" do
it "should know how to visit" do
node = @attr.desc
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" DESC
}
end
@ -392,57 +392,57 @@ module Arel
describe "Nodes::In" do
it "should know how to visit" do
node = @attr.in [1, 2, 3]
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (1, 2, 3)
}
node = @attr.in [1, 2, 3, 4, 5]
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
("users"."id" IN (1, 2, 3) OR "users"."id" IN (4, 5))
}
end
it "should return 1=0 when empty right which is always false" do
node = @attr.in []
compile(node).must_equal "1=0"
_(compile(node)).must_equal "1=0"
end
it "can handle two dot ranges" do
node = @attr.between 1..3
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" BETWEEN 1 AND 3
}
end
it "can handle three dot ranges" do
node = @attr.between 1...3
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" >= 1 AND "users"."id" < 3
}
end
it "can handle ranges bounded by infinity" do
node = @attr.between 1..Float::INFINITY
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" >= 1
}
node = @attr.between(-Float::INFINITY..3)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" <= 3
}
node = @attr.between(-Float::INFINITY...3)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" < 3
}
node = @attr.between(-Float::INFINITY..Float::INFINITY)
compile(node).must_be_like %{1=1}
_(compile(node)).must_be_like %{1=1}
end
it "can handle subqueries" do
table = Table.new(:users)
subquery = table.project(:id).where(table[:name].eq("Aaron"))
node = @attr.in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
}
end
@ -451,53 +451,53 @@ module Arel
describe "Nodes::InfixOperation" do
it "should handle Multiplication" do
node = Arel::Attributes::Decimal.new(Table.new(:products), :price) * Arel::Attributes::Decimal.new(Table.new(:currency_rates), :rate)
compile(node).must_equal %("products"."price" * "currency_rates"."rate")
_(compile(node)).must_equal %("products"."price" * "currency_rates"."rate")
end
it "should handle Division" do
node = Arel::Attributes::Decimal.new(Table.new(:products), :price) / 5
compile(node).must_equal %("products"."price" / 5)
_(compile(node)).must_equal %("products"."price" / 5)
end
it "should handle Addition" do
node = Arel::Attributes::Decimal.new(Table.new(:products), :price) + 6
compile(node).must_equal %(("products"."price" + 6))
_(compile(node)).must_equal %(("products"."price" + 6))
end
it "should handle Subtraction" do
node = Arel::Attributes::Decimal.new(Table.new(:products), :price) - 7
compile(node).must_equal %(("products"."price" - 7))
_(compile(node)).must_equal %(("products"."price" - 7))
end
it "should handle Concatenation" do
table = Table.new(:users)
node = table[:name].concat(table[:name])
compile(node).must_equal %("users"."name" || "users"."name")
_(compile(node)).must_equal %("users"."name" || "users"."name")
end
it "should handle BitwiseAnd" do
node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) & 16
compile(node).must_equal %(("products"."bitmap" & 16))
_(compile(node)).must_equal %(("products"."bitmap" & 16))
end
it "should handle BitwiseOr" do
node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) | 16
compile(node).must_equal %(("products"."bitmap" | 16))
_(compile(node)).must_equal %(("products"."bitmap" | 16))
end
it "should handle BitwiseXor" do
node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) ^ 16
compile(node).must_equal %(("products"."bitmap" ^ 16))
_(compile(node)).must_equal %(("products"."bitmap" ^ 16))
end
it "should handle BitwiseShiftLeft" do
node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) << 4
compile(node).must_equal %(("products"."bitmap" << 4))
_(compile(node)).must_equal %(("products"."bitmap" << 4))
end
it "should handle BitwiseShiftRight" do
node = Arel::Attributes::Integer.new(Table.new(:products), :bitmap) >> 4
compile(node).must_equal %(("products"."bitmap" >> 4))
_(compile(node)).must_equal %(("products"."bitmap" >> 4))
end
it "should handle arbitrary operators" do
@ -506,19 +506,19 @@ module Arel
Arel::Attributes::String.new(Table.new(:products), :name),
Arel::Attributes::String.new(Table.new(:products), :name)
)
compile(node).must_equal %("products"."name" && "products"."name")
_(compile(node)).must_equal %("products"."name" && "products"."name")
end
end
describe "Nodes::UnaryOperation" do
it "should handle BitwiseNot" do
node = ~ Arel::Attributes::Integer.new(Table.new(:products), :bitmap)
compile(node).must_equal %( ~ "products"."bitmap")
_(compile(node)).must_equal %( ~ "products"."bitmap")
end
it "should handle arbitrary operators" do
node = Arel::Nodes::UnaryOperation.new("!", Arel::Attributes::String.new(Table.new(:products), :active))
compile(node).must_equal %( ! "products"."active")
_(compile(node)).must_equal %( ! "products"."active")
end
end
@ -547,57 +547,57 @@ module Arel
describe "Nodes::NotIn" do
it "should know how to visit" do
node = @attr.not_in [1, 2, 3]
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" NOT IN (1, 2, 3)
}
node = @attr.not_in [1, 2, 3, 4, 5]
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" NOT IN (1, 2, 3) AND "users"."id" NOT IN (4, 5)
}
end
it "should return 1=1 when empty right which is always true" do
node = @attr.not_in []
compile(node).must_equal "1=1"
_(compile(node)).must_equal "1=1"
end
it "can handle two dot ranges" do
node = @attr.not_between 1..3
compile(node).must_equal(
_(compile(node)).must_equal(
%{("users"."id" < 1 OR "users"."id" > 3)}
)
end
it "can handle three dot ranges" do
node = @attr.not_between 1...3
compile(node).must_equal(
_(compile(node)).must_equal(
%{("users"."id" < 1 OR "users"."id" >= 3)}
)
end
it "can handle ranges bounded by infinity" do
node = @attr.not_between 1..Float::INFINITY
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" < 1
}
node = @attr.not_between(-Float::INFINITY..3)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" > 3
}
node = @attr.not_between(-Float::INFINITY...3)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" >= 3
}
node = @attr.not_between(-Float::INFINITY..Float::INFINITY)
compile(node).must_be_like %{1=0}
_(compile(node)).must_be_like %{1=0}
end
it "can handle subqueries" do
table = Table.new(:users)
subquery = table.project(:id).where(table[:name].eq("Aaron"))
node = @attr.not_in subquery
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
"users"."id" NOT IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
}
end
@ -606,14 +606,14 @@ module Arel
describe "Constants" do
it "should handle true" do
test = Table.new(:users).create_true
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
TRUE
}
end
it "should handle false" do
test = Table.new(:users).create_false
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
FALSE
}
end
@ -622,7 +622,7 @@ module Arel
describe "TableAlias" do
it "should use the underlying table for checking columns" do
test = Table.new(:users).alias("zomgusers")[:id].eq "3"
compile(test).must_be_like %{
_(compile(test)).must_be_like %{
"zomgusers"."id" = '3'
}
end
@ -665,7 +665,7 @@ module Arel
.when("foo").then(1)
.else(0)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CASE "users"."name" WHEN 'foo' THEN 1 ELSE 0 END
}
end
@ -675,7 +675,7 @@ module Arel
.when(@table[:name].in(%w(foo bar))).then(1)
.else(0)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CASE WHEN "users"."name" IN ('foo', 'bar') THEN 1 ELSE 0 END
}
end
@ -684,7 +684,7 @@ module Arel
node = Arel::Nodes::Case.new(@table[:name])
.when("foo").then(1)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CASE "users"."name" WHEN 'foo' THEN 1 END
}
end
@ -695,7 +695,7 @@ module Arel
.when("bar").then(2)
.else(0)
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CASE "users"."name" WHEN 'foo' THEN 1 WHEN 'bar' THEN 2 ELSE 0 END
}
end
@ -705,7 +705,7 @@ module Arel
{ foo: 1, bar: 0 }.reduce(node) { |_node, pair| _node.when(*pair) }
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CASE "users"."name" WHEN 'foo' THEN 1 WHEN 'bar' THEN 0 END
}
end
@ -713,7 +713,7 @@ module Arel
it "can be chained as a predicate" do
node = @table[:name].when("foo").then("bar").else("baz")
compile(node).must_be_like %{
_(compile(node)).must_be_like %{
CASE "users"."name" WHEN 'foo' THEN 'bar' ELSE 'baz' END
}
end