aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/predicates.rb9
-rw-r--r--lib/arel/primitives/attribute.rb10
-rw-r--r--lib/arel/primitives/expression.rb10
-rw-r--r--lib/arel/primitives/value.rb4
-rw-r--r--lib/arel/relations/aggregation.rb4
-rw-r--r--lib/arel/relations/deletion.rb4
-rw-r--r--lib/arel/relations/grouping.rb6
-rw-r--r--lib/arel/relations/insertion.rb2
-rw-r--r--lib/arel/relations/join.rb25
-rw-r--r--lib/arel/relations/nil.rb2
-rw-r--r--lib/arel/relations/order.rb6
-rw-r--r--lib/arel/relations/projection.rb6
-rw-r--r--lib/arel/relations/selection.rb6
-rw-r--r--lib/arel/relations/skip.rb6
-rw-r--r--lib/arel/relations/table.rb4
-rw-r--r--lib/arel/relations/take.rb6
-rw-r--r--lib/arel/relations/update.rb6
-rw-r--r--spec/arel/unit/predicates/binary_spec.rb12
-rw-r--r--spec/arel/unit/relations/join_spec.rb17
-rw-r--r--spec/arel/unit/relations/projection_spec.rb15
20 files changed, 59 insertions, 101 deletions
diff --git a/lib/arel/predicates.rb b/lib/arel/predicates.rb
index b375f37ff4..f21376d4c9 100644
--- a/lib/arel/predicates.rb
+++ b/lib/arel/predicates.rb
@@ -1,8 +1,5 @@
module Arel
class Predicate
- def ==(other)
- self.class == other.class
- end
end
class Binary < Predicate
@@ -13,7 +10,9 @@ module Arel
end
def ==(other)
- super and @operand1 == other.operand1 and @operand2 == other.operand2
+ self.class === other and
+ @operand1 == other.operand1 and
+ @operand2 == other.operand2
end
def bind(relation)
@@ -28,7 +27,7 @@ module Arel
class Equality < Binary
def ==(other)
- Equality == other.class and
+ Equality === other and
((operand1 == other.operand1 and operand2 == other.operand2) or
(operand1 == other.operand2 and operand2 == other.operand1))
end
diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb
index 011b751a1d..ca1d31ffcf 100644
--- a/lib/arel/primitives/attribute.rb
+++ b/lib/arel/primitives/attribute.rb
@@ -30,11 +30,11 @@ module Arel
end
def ==(other)
- Attribute == other.class and
- name == other.name and
- @alias == other.alias and
- ancestor == other.ancestor and
- relation == other.relation
+ Attribute === other and
+ name == other.name and
+ @alias == other.alias and
+ ancestor == other.ancestor and
+ relation == other.relation
end
def original_relation
diff --git a/lib/arel/primitives/expression.rb b/lib/arel/primitives/expression.rb
index 696e3521be..9afafcce2f 100644
--- a/lib/arel/primitives/expression.rb
+++ b/lib/arel/primitives/expression.rb
@@ -17,11 +17,11 @@ module Arel
end
def ==(other)
- Expression == other.class and
- attribute == other.attribute and
- function_sql == other.function_sql and
- ancestor == other.ancestor and
- @alias == other.alias
+ Expression === other and
+ attribute == other.attribute and
+ function_sql == other.function_sql and
+ ancestor == other.ancestor and
+ @alias == other.alias
end
module Transformations
diff --git a/lib/arel/primitives/value.rb b/lib/arel/primitives/value.rb
index b4bddd0b0c..4509f13d17 100644
--- a/lib/arel/primitives/value.rb
+++ b/lib/arel/primitives/value.rb
@@ -17,8 +17,8 @@ module Arel
end
def ==(other)
- Value == other.class and
- value == other.value
+ Value === other and
+ value == other.value
end
def bind(relation)
diff --git a/lib/arel/relations/aggregation.rb b/lib/arel/relations/aggregation.rb
index a6f40be786..9a34ea5d89 100644
--- a/lib/arel/relations/aggregation.rb
+++ b/lib/arel/relations/aggregation.rb
@@ -19,8 +19,8 @@ module Arel
end
def ==(other)
- Aggregation == other.class and
- self.relation == other.relation
+ Aggregation === other and
+ self.relation == other.relation
end
end
diff --git a/lib/arel/relations/deletion.rb b/lib/arel/relations/deletion.rb
index 8c9d873a02..cd58771846 100644
--- a/lib/arel/relations/deletion.rb
+++ b/lib/arel/relations/deletion.rb
@@ -18,8 +18,8 @@ module Arel
end
def ==(other)
- Deletion == other.class and
- relation == other.relation
+ Deletion === other and
+ relation == other.relation
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/grouping.rb b/lib/arel/relations/grouping.rb
index 39b5942bcc..6d11299051 100644
--- a/lib/arel/relations/grouping.rb
+++ b/lib/arel/relations/grouping.rb
@@ -7,9 +7,9 @@ module Arel
end
def ==(other)
- Grouping == other.class and
- relation == other.relation and
- groupings == other.groupings
+ Grouping === other and
+ relation == other.relation and
+ groupings == other.groupings
end
def aggregation?
diff --git a/lib/arel/relations/insertion.rb b/lib/arel/relations/insertion.rb
index cc7fcb4fb0..16eb9b7555 100644
--- a/lib/arel/relations/insertion.rb
+++ b/lib/arel/relations/insertion.rb
@@ -20,7 +20,7 @@ module Arel
end
def ==(other)
- Insertion == other.class and
+ Insertion === other and
relation == other.relation and
record == other.record
end
diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb
index 9cc9f95c81..81a157dc10 100644
--- a/lib/arel/relations/join.rb
+++ b/lib/arel/relations/join.rb
@@ -13,13 +13,15 @@ module Arel
end
def joins(environment, formatter = Sql::TableReference.new(environment))
- this_join = [
- join_sql,
- relation2.externalize.table_sql(formatter),
- ("ON" unless predicates.blank?),
- (ons + relation2.externalize.selects).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ')
- ].compact.join(" ")
- [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ")
+ @joins ||= begin
+ this_join = [
+ join_sql,
+ relation2.externalize.table_sql(formatter),
+ ("ON" unless predicates.blank?),
+ (ons + relation2.externalize.selects).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ')
+ ].compact.join(" ")
+ [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ")
+ end
end
def attributes
@@ -45,11 +47,10 @@ module Arel
end
def ==(other)
- Join == other.class and
- predicates == other.predicates and (
- (relation1 == other.relation1 and relation2 == other.relation2) or
- (relation2 == other.relation1 and relation1 == other.relation2)
- )
+ Join === other and
+ predicates == other.predicates and
+ relation1 == other.relation1 and
+ relation2 == other.relation2
end
end
diff --git a/lib/arel/relations/nil.rb b/lib/arel/relations/nil.rb
index c34fe71473..2dcfb47233 100644
--- a/lib/arel/relations/nil.rb
+++ b/lib/arel/relations/nil.rb
@@ -4,7 +4,7 @@ module Arel
def name; '' end
def ==(other)
- Nil == other.class
+ Nil === other
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/order.rb b/lib/arel/relations/order.rb
index 31032e871c..ebb4dc0668 100644
--- a/lib/arel/relations/order.rb
+++ b/lib/arel/relations/order.rb
@@ -11,9 +11,9 @@ module Arel
end
def ==(other)
- Order == other.class and
- relation == other.relation and
- orderings == other.orderings
+ Order === other and
+ relation == other.relation and
+ orderings == other.orderings
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/projection.rb b/lib/arel/relations/projection.rb
index 7eea63d808..d74f111271 100644
--- a/lib/arel/relations/projection.rb
+++ b/lib/arel/relations/projection.rb
@@ -15,9 +15,9 @@ module Arel
end
def ==(other)
- Projection == other.class and
- relation == other.relation and
- projections == other.projections
+ Projection === other and
+ relation == other.relation and
+ projections == other.projections
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/selection.rb b/lib/arel/relations/selection.rb
index 0c5956d2fc..fc4e94621a 100644
--- a/lib/arel/relations/selection.rb
+++ b/lib/arel/relations/selection.rb
@@ -13,9 +13,9 @@ module Arel
end
def ==(other)
- Selection == other.class and
- relation == other.relation and
- predicate == other.predicate
+ Selection === other and
+ relation == other.relation and
+ predicate == other.predicate
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/skip.rb b/lib/arel/relations/skip.rb
index 4686e03177..01ac4c7204 100644
--- a/lib/arel/relations/skip.rb
+++ b/lib/arel/relations/skip.rb
@@ -7,9 +7,9 @@ module Arel
end
def ==(other)
- Skip == other.class and
- relation == other.relation and
- skipped == other.skipped
+ Skip === other and
+ relation == other.relation and
+ skipped == other.skipped
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/table.rb b/lib/arel/relations/table.rb
index 06625dd52a..087028fb55 100644
--- a/lib/arel/relations/table.rb
+++ b/lib/arel/relations/table.rb
@@ -29,8 +29,8 @@ module Arel
end
def ==(other)
- Table == other.class and
- name == other.name
+ Table === other and
+ name == other.name
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/take.rb b/lib/arel/relations/take.rb
index 80aa62a878..0a49891aee 100644
--- a/lib/arel/relations/take.rb
+++ b/lib/arel/relations/take.rb
@@ -7,9 +7,9 @@ module Arel
end
def ==(other)
- Take == other.class and
- relation == other.relation and
- taken == other.taken
+ Take === other and
+ relation == other.relation and
+ taken == other.taken
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/update.rb b/lib/arel/relations/update.rb
index 486ad2ab12..8306a83aac 100644
--- a/lib/arel/relations/update.rb
+++ b/lib/arel/relations/update.rb
@@ -22,9 +22,9 @@ module Arel
end
def ==(other)
- Update == other.class and
- relation == other.relation and
- assignments == other.assignments
+ Update === other and
+ relation == other.relation and
+ assignments == other.assignments
end
end
end \ No newline at end of file
diff --git a/spec/arel/unit/predicates/binary_spec.rb b/spec/arel/unit/predicates/binary_spec.rb
index 57b1f3a534..5dee4833d4 100644
--- a/spec/arel/unit/predicates/binary_spec.rb
+++ b/spec/arel/unit/predicates/binary_spec.rb
@@ -44,18 +44,6 @@ module Arel
end
end
end
-
- describe '==' do
- it "obtains if attribute1 and attribute2 are identical" do
- Binary.new(@attribute1, @attribute2).should == Binary.new(@attribute1, @attribute2)
- Binary.new(@attribute1, @attribute2).should_not == Binary.new(@attribute1, @attribute1)
- end
-
- it "obtains if the concrete type of the predicates are identical" do
- Binary.new(@attribute1, @attribute2).should == Binary.new(@attribute1, @attribute2)
- Binary.new(@attribute1, @attribute2).should_not == ConcreteBinary.new(@attribute1, @attribute2)
- end
- end
describe '#bind' do
before do
diff --git a/spec/arel/unit/relations/join_spec.rb b/spec/arel/unit/relations/join_spec.rb
index d128dd0560..1698bf9647 100644
--- a/spec/arel/unit/relations/join_spec.rb
+++ b/spec/arel/unit/relations/join_spec.rb
@@ -7,23 +7,6 @@ module Arel
@relation2 = Table.new(:photos)
@predicate = @relation1[:id].eq(@relation2[:user_id])
end
-
- describe '==' do
- before do
- @another_predicate = @relation1[:id].eq(1)
- @another_relation = Table.new(:cameras)
- end
-
- it 'obtains if the two relations and the predicate are identical' do
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == Join.new("INNER JOIN", @relation1, @relation2, @predicate)
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).should_not == Join.new("INNER JOIN", @relation1, @another_relation, @predicate)
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).should_not == Join.new("INNER JOIN", @relation1, @relation2, @another_predicate)
- end
-
- it 'is commutative on the relations' do
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == Join.new("INNER JOIN", @relation2, @relation1, @predicate)
- end
- end
describe 'hashing' do
it 'implements hash equality' do
diff --git a/spec/arel/unit/relations/projection_spec.rb b/spec/arel/unit/relations/projection_spec.rb
index cede58354b..3c6a092db5 100644
--- a/spec/arel/unit/relations/projection_spec.rb
+++ b/spec/arel/unit/relations/projection_spec.rb
@@ -13,20 +13,7 @@ module Arel
end
it "manufactures attributes associated with the projection relation" do
- # @projection.attributes.should == [@attribute].collect { |a| a.bind(@projection) }
- end
- end
-
- describe '==' do
- before do
- @another_relation = Table.new(:photos)
- @another_attribute = @relation[:name]
- end
-
- it "obtains if the relations and attributes are identical" do
- Projection.new(@relation, @attribute).should == Projection.new(@relation, @attribute)
- Projection.new(@relation, @attribute).should_not == Projection.new(@another_relation, @attribute)
- Projection.new(@relation, @attribute).should_not == Projection.new(@relation, @another_attribute)
+ @projection.attributes.should == [@attribute].collect { |a| a.bind(@projection) }
end
end