aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/algebra/predicates.rb10
-rw-r--r--lib/arel/engines/memory/predicates.rb2
-rw-r--r--lib/arel/engines/sql/predicates.rb2
-rw-r--r--spec/algebra/unit/predicates/inequality_spec.rb26
-rw-r--r--spec/algebra/unit/predicates/predicate_spec.rb22
5 files changed, 52 insertions, 10 deletions
diff --git a/lib/arel/algebra/predicates.rb b/lib/arel/algebra/predicates.rb
index e98e152dbd..1b9667ac13 100644
--- a/lib/arel/algebra/predicates.rb
+++ b/lib/arel/algebra/predicates.rb
@@ -109,7 +109,7 @@ module Arel
class Equality < Binary
def ==(other)
- Equality === other and
+ self.class === other and
((operand1 == other.operand1 and operand2 == other.operand2) or
(operand1 == other.operand2 and operand2 == other.operand1))
end
@@ -119,13 +119,7 @@ module Arel
end
end
- class Inequality < Binary
- def ==(other)
- Equality === other and
- ((operand1 == other.operand1 and operand2 == other.operand2) or
- (operand1 == other.operand2 and operand2 == other.operand1))
- end
-
+ class Inequality < Equality
def complement
Equality.new(operand1, operand2)
end
diff --git a/lib/arel/engines/memory/predicates.rb b/lib/arel/engines/memory/predicates.rb
index cca6739424..e36afa38c2 100644
--- a/lib/arel/engines/memory/predicates.rb
+++ b/lib/arel/engines/memory/predicates.rb
@@ -52,7 +52,7 @@ module Arel
def operator; :== end
end
- class Inequality < Binary
+ class Inequality < Equality
def eval(row)
operand1.eval(row) != operand2.eval(row)
end
diff --git a/lib/arel/engines/sql/predicates.rb b/lib/arel/engines/sql/predicates.rb
index 93d2a2f619..21d8f840c9 100644
--- a/lib/arel/engines/sql/predicates.rb
+++ b/lib/arel/engines/sql/predicates.rb
@@ -52,7 +52,7 @@ module Arel
end
end
- class Inequality < Binary
+ class Inequality < Equality
def predicate_sql
operand2.inequality_predicate_sql
end
diff --git a/spec/algebra/unit/predicates/inequality_spec.rb b/spec/algebra/unit/predicates/inequality_spec.rb
new file mode 100644
index 0000000000..557494e2cd
--- /dev/null
+++ b/spec/algebra/unit/predicates/inequality_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+module Arel
+ module Predicates
+ describe Inequality do
+ before do
+ relation1 = Arel::Table.new(:users)
+ relation2 = Arel::Table.new(:photos)
+ left = relation1[:id]
+ right = relation2[:user_id]
+ @a = Inequality.new(left, right)
+ @b = Inequality.new(right, left)
+ end
+
+ describe '==' do
+ it "is equal to itself" do
+ @a.should == @a
+ end
+
+ it "should not care abount children order" do
+ @a.should == @b
+ end
+ end
+ end
+ end
+end
diff --git a/spec/algebra/unit/predicates/predicate_spec.rb b/spec/algebra/unit/predicates/predicate_spec.rb
new file mode 100644
index 0000000000..6acc047cbb
--- /dev/null
+++ b/spec/algebra/unit/predicates/predicate_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+module Arel
+ module Predicates
+ describe Polyadic do
+ before do
+ @relation1 = Arel::Table.new(:users)
+ @relation2 = Arel::Table.new(:photos)
+ @a = @relation1[:id]
+ @b = @relation2[:user_id]
+ end
+
+ describe '==' do
+ left = Polyadic.new @a, @b
+ right = Polyadic.new @b, @a
+
+ left.should != right
+ left.should == right
+ end
+ end
+ end
+end