aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/arel/nodes/equality_test.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2018-04-25 08:18:02 +0930
committerGitHub <noreply@github.com>2018-04-25 08:18:02 +0930
commit989b1cb4a326632a686d61df42695b27e4ef6b2e (patch)
tree026a41714b44dba185f084f8f21bb81eb01db681 /activerecord/test/cases/arel/nodes/equality_test.rb
parent7e815415edbe42f1df64d786a8f923a171778d64 (diff)
parent354f1c28e81d9846fb9e5346fcca50cf303c12c1 (diff)
downloadrails-989b1cb4a326632a686d61df42695b27e4ef6b2e.tar.gz
rails-989b1cb4a326632a686d61df42695b27e4ef6b2e.tar.bz2
rails-989b1cb4a326632a686d61df42695b27e4ef6b2e.zip
Merge pull request #32097 from matthewd/arel
Merge Arel
Diffstat (limited to 'activerecord/test/cases/arel/nodes/equality_test.rb')
-rw-r--r--activerecord/test/cases/arel/nodes/equality_test.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/activerecord/test/cases/arel/nodes/equality_test.rb b/activerecord/test/cases/arel/nodes/equality_test.rb
new file mode 100644
index 0000000000..e173720e86
--- /dev/null
+++ b/activerecord/test/cases/arel/nodes/equality_test.rb
@@ -0,0 +1,86 @@
+# frozen_string_literal: true
+
+require_relative "../helper"
+
+module Arel
+ module Nodes
+ describe "equality" do
+ # FIXME: backwards compat
+ describe "backwards compat" do
+ describe "operator" do
+ it "returns :==" do
+ attr = Table.new(:users)[:id]
+ left = attr.eq(10)
+ left.operator.must_equal :==
+ end
+ end
+
+ describe "operand1" do
+ it "should equal left" do
+ attr = Table.new(:users)[:id]
+ left = attr.eq(10)
+ left.left.must_equal left.operand1
+ end
+ end
+
+ describe "operand2" do
+ it "should equal right" do
+ attr = Table.new(:users)[:id]
+ left = attr.eq(10)
+ left.right.must_equal left.operand2
+ end
+ end
+
+ describe "to_sql" do
+ it "takes an engine" do
+ engine = FakeRecord::Base.new
+ engine.connection.extend Module.new {
+ attr_accessor :quote_count
+ def quote(*args) @quote_count += 1; super; end
+ def quote_column_name(*args) @quote_count += 1; super; end
+ def quote_table_name(*args) @quote_count += 1; super; end
+ }
+ engine.connection.quote_count = 0
+
+ attr = Table.new(:users)[:id]
+ test = attr.eq(10)
+ test.to_sql engine
+ engine.connection.quote_count.must_equal 3
+ end
+ end
+ end
+
+ describe "or" do
+ it "makes an OR node" do
+ attr = Table.new(:users)[:id]
+ left = attr.eq(10)
+ right = attr.eq(11)
+ node = left.or right
+ node.expr.left.must_equal left
+ node.expr.right.must_equal right
+ end
+ end
+
+ describe "and" do
+ it "makes and AND node" do
+ attr = Table.new(:users)[:id]
+ left = attr.eq(10)
+ right = attr.eq(11)
+ node = left.and right
+ node.left.must_equal left
+ node.right.must_equal right
+ end
+ end
+
+ it "is equal with equal ivars" do
+ array = [Equality.new("foo", "bar"), Equality.new("foo", "bar")]
+ assert_equal 1, array.uniq.size
+ end
+
+ it "is not equal with different ivars" do
+ array = [Equality.new("foo", "bar"), Equality.new("foo", "baz")]
+ assert_equal 2, array.uniq.size
+ end
+ end
+ end
+end