aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/arel/visitors/postgres_test.rb
diff options
context:
space:
mode:
authorDmytro Shteflyuk <kpumuk@kpumuk.info>2018-11-15 14:49:55 -0500
committerRafael França <rafaelmfranca@gmail.com>2018-11-15 14:49:55 -0500
commitb5302d5a820b078b6488104dd695a679e5a49623 (patch)
treea8f393036fd1b72c33d9ed448f6ada379b2dd429 /activerecord/test/cases/arel/visitors/postgres_test.rb
parentd1c76dd4b0d308db432afb56c7dafcbefbf4ee3a (diff)
downloadrails-b5302d5a820b078b6488104dd695a679e5a49623.tar.gz
rails-b5302d5a820b078b6488104dd695a679e5a49623.tar.bz2
rails-b5302d5a820b078b6488104dd695a679e5a49623.zip
Arel: Implemented DB-aware NULL-safe comparison (#34451)
* Arel: Implemented DB-aware NULL-safe comparison * Fixed where clause inversion for NULL-safe comparison * Renaming "null_safe_eq" to "is_not_distinct_from", "null_safe_not_eq" to "is_distinct_from" [Dmytro Shteflyuk + Rafael Mendonça França]
Diffstat (limited to 'activerecord/test/cases/arel/visitors/postgres_test.rb')
-rw-r--r--activerecord/test/cases/arel/visitors/postgres_test.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/activerecord/test/cases/arel/visitors/postgres_test.rb b/activerecord/test/cases/arel/visitors/postgres_test.rb
index f7f2c76b6f..0f9efb20b4 100644
--- a/activerecord/test/cases/arel/visitors/postgres_test.rb
+++ b/activerecord/test/cases/arel/visitors/postgres_test.rb
@@ -276,6 +276,45 @@ module Arel
}
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 %{
+ "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 %{
+ "users"."first_name" IS NOT DISTINCT FROM "users"."last_name"
+ }
+ end
+
+ it "should handle nil" do
+ @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 }
+ 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 %{
+ "users"."first_name" IS DISTINCT FROM "users"."last_name"
+ }
+ end
+
+ it "should handle nil" do
+ @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 }
+ end
+ end
end
end
end