aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-12 16:43:48 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-12 16:43:48 -0700
commit1b8f72746b38ce1e08b5fab48f3251eb09f2cba0 (patch)
tree3782ef3e88474bb6d79ba3e25b08b235fca78040
parent6de1f350ce117129e46353f12f90a138ca3d3ead (diff)
downloadrails-1b8f72746b38ce1e08b5fab48f3251eb09f2cba0.tar.gz
rails-1b8f72746b38ce1e08b5fab48f3251eb09f2cba0.tar.bz2
rails-1b8f72746b38ce1e08b5fab48f3251eb09f2cba0.zip
- removed #qualify and #descend helper
- qualify seems no longer neccessary since everything is fully qualified - finished pending specs
-rw-r--r--lib/active_relation/extensions/hash.rb8
-rw-r--r--lib/active_relation/predicates.rb10
-rw-r--r--lib/active_relation/primitives/attribute.rb4
-rw-r--r--lib/active_relation/primitives/value.rb4
-rw-r--r--lib/active_relation/relations/aggregation.rb4
-rw-r--r--lib/active_relation/relations/alias.rb4
-rw-r--r--lib/active_relation/relations/compound.rb4
-rw-r--r--lib/active_relation/relations/join.rb8
-rw-r--r--lib/active_relation/relations/order.rb4
-rw-r--r--lib/active_relation/relations/projection.rb4
-rw-r--r--lib/active_relation/relations/rename.rb4
-rw-r--r--lib/active_relation/relations/selection.rb4
-rw-r--r--lib/active_relation/relations/skip.rb4
-rw-r--r--lib/active_relation/relations/table.rb8
-rw-r--r--lib/active_relation/relations/take.rb4
-rw-r--r--spec/active_relation/unit/predicates/binary_spec.rb14
-rw-r--r--spec/active_relation/unit/primitives/attribute_spec.rb33
-rw-r--r--spec/active_relation/unit/relations/join_spec.rb14
-rw-r--r--spec/active_relation/unit/relations/order_spec.rb14
-rw-r--r--spec/active_relation/unit/relations/projection_spec.rb14
-rw-r--r--spec/active_relation/unit/relations/relation_spec.rb9
-rw-r--r--spec/active_relation/unit/relations/rename_spec.rb14
-rw-r--r--spec/active_relation/unit/relations/selection_spec.rb20
-rw-r--r--spec/active_relation/unit/relations/skip_spec.rb12
-rw-r--r--spec/active_relation/unit/relations/table_spec.rb11
-rw-r--r--spec/active_relation/unit/relations/take_spec.rb18
26 files changed, 28 insertions, 223 deletions
diff --git a/lib/active_relation/extensions/hash.rb b/lib/active_relation/extensions/hash.rb
index a33ace5738..7472b5aa73 100644
--- a/lib/active_relation/extensions/hash.rb
+++ b/lib/active_relation/extensions/hash.rb
@@ -1,11 +1,7 @@
class Hash
def bind(relation)
- descend { |x| x.bind(relation) }
- end
-
- def descend(&block)
- inject({}) do |descendent, (key, value)|
- descendent.merge(yield(key) => yield(value))
+ inject({}) do |bound, (key, value)|
+ bound.merge(key.bind(relation) => value.bind(relation))
end
end
end \ No newline at end of file
diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb
index dc4610b052..2cab1721d0 100644
--- a/lib/active_relation/predicates.rb
+++ b/lib/active_relation/predicates.rb
@@ -17,20 +17,12 @@ module ActiveRelation
end
def bind(relation)
- descend { |x| x.bind(relation) }
+ self.class.new(operand1.bind(relation), operand2.bind(relation))
end
- def qualify
- descend(&:qualify)
- end
-
def to_sql(formatter = nil)
"#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}"
end
-
- def descend
- self.class.new(yield(operand1), yield(operand2))
- end
end
class Equality < Binary
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb
index 9685d2ab4a..d815656794 100644
--- a/lib/active_relation/primitives/attribute.rb
+++ b/lib/active_relation/primitives/attribute.rb
@@ -20,10 +20,6 @@ module ActiveRelation
relation == new_relation ? self : Attribute.new(new_relation, name, :alias => @alias, :ancestor => self)
end
- def qualify
- self.as(qualified_name)
- end
-
def to_attribute
self
end
diff --git a/lib/active_relation/primitives/value.rb b/lib/active_relation/primitives/value.rb
index 3fbe907324..9042aea067 100644
--- a/lib/active_relation/primitives/value.rb
+++ b/lib/active_relation/primitives/value.rb
@@ -20,10 +20,6 @@ module ActiveRelation
value == other.value
end
- def qualify
- self
- end
-
def bind(relation)
Value.new(value, relation)
end
diff --git a/lib/active_relation/relations/aggregation.rb b/lib/active_relation/relations/aggregation.rb
index 38f1f2dda8..62432408e1 100644
--- a/lib/active_relation/relations/aggregation.rb
+++ b/lib/active_relation/relations/aggregation.rb
@@ -20,9 +20,5 @@ module ActiveRelation
def aggregation?
true
end
-
- def descend(&block)
- Aggregation.new(relation.descend(&block), :expressions => expressions.collect(&block), :groupings => groupings.collect(&block))
- end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/alias.rb b/lib/active_relation/relations/alias.rb
index f24b1d743c..cf410c6462 100644
--- a/lib/active_relation/relations/alias.rb
+++ b/lib/active_relation/relations/alias.rb
@@ -9,10 +9,6 @@ module ActiveRelation
def alias?
true
end
-
- def descend(&block)
- Alias.new(relation.descend(&block), @alias)
- end
def ==(other)
self.class == other.class and
diff --git a/lib/active_relation/relations/compound.rb b/lib/active_relation/relations/compound.rb
index aa3274cbd3..7c84482115 100644
--- a/lib/active_relation/relations/compound.rb
+++ b/lib/active_relation/relations/compound.rb
@@ -12,9 +12,5 @@ module ActiveRelation
def attributes
relation.attributes.collect { |a| a.bind(self) }
end
-
- def qualify
- descend(&:qualify)
- end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb
index c5ce47b555..dbcb520b92 100644
--- a/lib/active_relation/relations/join.rb
+++ b/lib/active_relation/relations/join.rb
@@ -18,10 +18,6 @@ module ActiveRelation
)
end
- def qualify
- descend(&:qualify)
- end
-
def attributes
(externalize(relation1).attributes +
externalize(relation2).attributes).collect { |a| a.bind(self) }
@@ -31,10 +27,6 @@ module ActiveRelation
externalize(relation1).prefix_for(attribute) or
externalize(relation2).prefix_for(attribute)
end
-
- def descend(&block)
- Join.new(join_sql, relation1.descend(&block), relation2.descend(&block), *predicates.collect(&block))
- end
def joins
this_join = [
diff --git a/lib/active_relation/relations/order.rb b/lib/active_relation/relations/order.rb
index d71ff09c41..b5495fad67 100644
--- a/lib/active_relation/relations/order.rb
+++ b/lib/active_relation/relations/order.rb
@@ -13,10 +13,6 @@ module ActiveRelation
relation == other.relation and
ordering == other.ordering
end
-
- def descend(&block)
- Order.new(relation.descend(&block), yield(ordering))
- end
def orders
relation.orders + [ordering]
diff --git a/lib/active_relation/relations/projection.rb b/lib/active_relation/relations/projection.rb
index c478ae145f..c1495c1742 100644
--- a/lib/active_relation/relations/projection.rb
+++ b/lib/active_relation/relations/projection.rb
@@ -15,9 +15,5 @@ module ActiveRelation
relation == other.relation and
projections == other.projections
end
-
- def descend(&block)
- Projection.new(relation.descend(&block), *projections.collect(&block))
- end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb
index ac5484bfff..9ab07707a0 100644
--- a/lib/active_relation/relations/rename.rb
+++ b/lib/active_relation/relations/rename.rb
@@ -18,10 +18,6 @@ module ActiveRelation
relation.attributes.collect(&method(:christen))
end
- def descend(&block)
- Rename.new(relation.descend(&block), yield(attribute) => pseudonym)
- end
-
private
def christen(attribute)
(attribute =~ self.attribute ? attribute.as(pseudonym) : attribute).bind(self) rescue nil
diff --git a/lib/active_relation/relations/selection.rb b/lib/active_relation/relations/selection.rb
index 032de63d04..fb90405b01 100644
--- a/lib/active_relation/relations/selection.rb
+++ b/lib/active_relation/relations/selection.rb
@@ -14,10 +14,6 @@ module ActiveRelation
predicate == other.predicate
end
- def descend(&block)
- Selection.new(relation.descend(&block), yield(predicate))
- end
-
def selects
relation.selects + [predicate]
end
diff --git a/lib/active_relation/relations/skip.rb b/lib/active_relation/relations/skip.rb
index 3133a3af41..5973dff8b9 100644
--- a/lib/active_relation/relations/skip.rb
+++ b/lib/active_relation/relations/skip.rb
@@ -11,9 +11,5 @@ module ActiveRelation
relation == other.relation and
skipped == other.skipped
end
-
- def descend(&block)
- Skip.new(relation.descend(&block), skipped)
- end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/table.rb b/lib/active_relation/relations/table.rb
index 5ad27c1fcf..e645f71030 100644
--- a/lib/active_relation/relations/table.rb
+++ b/lib/active_relation/relations/table.rb
@@ -15,10 +15,6 @@ module ActiveRelation
end
end
- def qualify
- Rename.new self, qualifications
- end
-
def prefix_for(attribute)
self[attribute] and name
end
@@ -36,10 +32,6 @@ module ActiveRelation
@columns ||= engine.columns(name, "#{name} Columns")
end
- def descend
- yield self
- end
-
def reset
@attributes = @columns = nil
end
diff --git a/lib/active_relation/relations/take.rb b/lib/active_relation/relations/take.rb
index 02d507753d..d9d439b3f5 100644
--- a/lib/active_relation/relations/take.rb
+++ b/lib/active_relation/relations/take.rb
@@ -11,9 +11,5 @@ module ActiveRelation
relation == other.relation and
taken == other.taken
end
-
- def descend(&block)
- Take.new(relation.descend(&block), taken)
- end
end
end \ No newline at end of file
diff --git a/spec/active_relation/unit/predicates/binary_spec.rb b/spec/active_relation/unit/predicates/binary_spec.rb
index 5dd5e5599a..56c568b078 100644
--- a/spec/active_relation/unit/predicates/binary_spec.rb
+++ b/spec/active_relation/unit/predicates/binary_spec.rb
@@ -57,20 +57,6 @@ module ActiveRelation
end
end
- describe '#qualify' do
- it "descends" do
- ConcreteBinary.new(@attribute1, @attribute2).qualify \
- .should == ConcreteBinary.new(@attribute1, @attribute2).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- it "distributes a block over the predicates and attributes" do
- ConcreteBinary.new(@attribute1, @attribute2).descend(&:qualify). \
- should == ConcreteBinary.new(@attribute1.qualify, @attribute2.qualify)
- end
- end
-
describe '#bind' do
before do
@another_relation = Table.new(:photos)
diff --git a/spec/active_relation/unit/primitives/attribute_spec.rb b/spec/active_relation/unit/primitives/attribute_spec.rb
index fbbcbaef37..08ed6d3621 100644
--- a/spec/active_relation/unit/primitives/attribute_spec.rb
+++ b/spec/active_relation/unit/primitives/attribute_spec.rb
@@ -21,16 +21,10 @@ module ActiveRelation
end
it "returns self if the substituting to the same relation" do
- @attribute.should == @attribute
+ @attribute.bind(@relation).should == @attribute
end
end
- describe '#qualify' do
- it "manufactures an attribute aliased with that attribute's qualified name" do
- @attribute.qualify.should == Attribute.new(@attribute.relation, @attribute.name, :alias => @attribute.qualified_name, :ancestor => @attribute)
- end
- end
-
describe '#to_attribute' do
it "returns self" do
@attribute.to_attribute.should == @attribute
@@ -40,16 +34,13 @@ module ActiveRelation
describe '#column' do
it "returns the corresponding column in the relation" do
- pending "damn mock based tests are too easy"
- stub(@relation).column_for(@attribute) { 'bruisers' }
- @attribute.column.should == 'bruisers'
+ @attribute.column.should == @relation.column_for(@attribute)
end
end
describe '#qualified_name' do
it "manufactures an attribute name prefixed with the relation's name" do
- stub(@relation).prefix_for(anything) { 'bruisers' }
- Attribute.new(@relation, :id).qualified_name.should == 'bruisers.id'
+ @attribute.qualified_name.should == "#{@relation.prefix_for(@attribute)}.id"
end
end
@@ -80,13 +71,21 @@ module ActiveRelation
end
describe '#to_sql' do
- it "" do
- pending "this test is not sufficiently resilient"
+ describe 'for a simple attribute' do
+ it "manufactures sql with an alias" do
+ @attribute.to_sql.should be_like("`users`.`id`")
+ end
end
- it "manufactures sql with an alias" do
- stub(@relation).prefix_for(anything) { 'bruisers' }
- Attribute.new(@relation, :name, :alias => :alias).to_sql.should be_like("`bruisers`.`name`")
+ describe 'for an attribute in a join relation where the source relation is aliased' do
+ before do
+ another_relation = Table.new(:photos)
+ @join_with_alias = @relation.as(:alias).join(another_relation).on(@relation[:id].eq(another_relation[:user_id]))
+ end
+
+ it "manufactures sql with an alias" do
+ @join_with_alias[@attribute].to_sql.should be_like("`alias`.`id`")
+ end
end
end
diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb
index 423e513be4..73dd67bec8 100644
--- a/spec/active_relation/unit/relations/join_spec.rb
+++ b/spec/active_relation/unit/relations/join_spec.rb
@@ -32,20 +32,6 @@ module ActiveRelation
end
end
- describe '#qualify' do
- it 'descends' do
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).qualify. \
- should == Join.new("INNER JOIN", @relation1, @relation2, @predicate).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- it 'distributes over the relations and predicates' do
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).qualify. \
- should == Join.new("INNER JOIN", @relation1.qualify, @relation2.qualify, @predicate.qualify)
- end
- end
-
describe '#prefix_for' do
describe 'when the joined relations are simple' do
it "returns the name of the relation containing the attribute" do
diff --git a/spec/active_relation/unit/relations/order_spec.rb b/spec/active_relation/unit/relations/order_spec.rb
index db322fe00b..e8a2f4c227 100644
--- a/spec/active_relation/unit/relations/order_spec.rb
+++ b/spec/active_relation/unit/relations/order_spec.rb
@@ -18,20 +18,6 @@ module ActiveRelation
end
end
- describe '#qualify' do
- it "descends" do
- Order.new(@relation, @attribute).qualify. \
- should == Order.new(@relation, @attribute).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- it "distributes a block over the relation and attributes" do
- Order.new(@relation, @attribute).descend(&:qualify). \
- should == Order.new(@relation.descend(&:qualify), @attribute.qualify)
- end
- end
-
describe '#to_sql' do
describe "when given an attribute" do
it "manufactures sql with an order clause populated by the attribute" do
diff --git a/spec/active_relation/unit/relations/projection_spec.rb b/spec/active_relation/unit/relations/projection_spec.rb
index f58564840b..529998a8d4 100644
--- a/spec/active_relation/unit/relations/projection_spec.rb
+++ b/spec/active_relation/unit/relations/projection_spec.rb
@@ -30,20 +30,6 @@ module ActiveRelation
end
end
- describe '#qualify' do
- it "descends" do
- Projection.new(@relation, @attribute).qualify. \
- should == Projection.new(@relation, @attribute).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- it "distributes a block over the relation and attributes" do
- Projection.new(@relation, @attribute).descend(&:qualify). \
- should == Projection.new(@relation.descend(&:qualify), @attribute.qualify)
- end
- end
-
describe '#to_sql' do
describe 'when given an attribute' do
it "manufactures sql with a limited select clause" do
diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb
index 2a04276aeb..fa66352c91 100644
--- a/spec/active_relation/unit/relations/relation_spec.rb
+++ b/spec/active_relation/unit/relations/relation_spec.rb
@@ -174,12 +174,9 @@ module ActiveRelation
end
describe Relation::Enumerable do
- it "is enumerable" do
- pending "I don't like this mock-based test"
- data = [1,2,3]
- mock.instance_of(Session).read(anything) { data }
- @relation.collect.should == data
- @relation.first.should == data.first
+ it "implements enumerable" do
+ @relation.collect.should == @relation.session.read(@relation)
+ @relation.first.should == @relation.session.read(@relation).first
end
end
end
diff --git a/spec/active_relation/unit/relations/rename_spec.rb b/spec/active_relation/unit/relations/rename_spec.rb
index 9a63c4fc80..192c819848 100644
--- a/spec/active_relation/unit/relations/rename_spec.rb
+++ b/spec/active_relation/unit/relations/rename_spec.rb
@@ -38,20 +38,6 @@ module ActiveRelation
end
end
- describe '#qualify' do
- it "descends" do
- Rename.new(@relation, @relation[:id] => :schmid).qualify. \
- should == Rename.new(@relation, @relation[:id] => :schmid).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- it "distributes a block over the relation and renames" do
- Rename.new(@relation, @relation[:id] => :schmid).descend(&:qualify). \
- should == Rename.new(@relation.descend(&:qualify), @relation[:id].qualify => :schmid)
- end
- end
-
describe '#to_sql' do
it 'manufactures sql renaming the attribute' do
Rename.new(@relation, @relation[:id] => :schmid).to_sql.should be_like("
diff --git a/spec/active_relation/unit/relations/selection_spec.rb b/spec/active_relation/unit/relations/selection_spec.rb
index 20833de58d..d87e075f98 100644
--- a/spec/active_relation/unit/relations/selection_spec.rb
+++ b/spec/active_relation/unit/relations/selection_spec.rb
@@ -17,25 +17,7 @@ module ActiveRelation
should == Selection.new(Selection.new(@relation, @another_predicate), @predicate)
end
end
-
- describe '#qualify' do
- it "descends" do
- Selection.new(@relation, @predicate).qualify. \
- should == Selection.new(@relation, @predicate).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- before do
- @selection = Selection.new(@relation, @predicate)
- end
-
- it "distributes a block over the relation and predicates" do
- @selection.descend(&:qualify). \
- should == Selection.new(@selection.relation.descend(&:qualify), @selection.predicate.qualify)
- end
- end
-
+
describe '#to_sql' do
describe 'when given a predicate' do
it "manufactures sql with where clause conditions" do
diff --git a/spec/active_relation/unit/relations/skip_spec.rb b/spec/active_relation/unit/relations/skip_spec.rb
index d50ef715ee..219bfdd80e 100644
--- a/spec/active_relation/unit/relations/skip_spec.rb
+++ b/spec/active_relation/unit/relations/skip_spec.rb
@@ -7,18 +7,6 @@ module ActiveRelation
@skipped = 4
end
- describe '#qualify' do
- it "descends" do
- Skip.new(@relation, @skipped).qualify.should == Skip.new(@relation, @skipped).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- it "distributes a block over the relation" do
- Skip.new(@relation, @skipped).descend(&:qualify).should == Skip.new(@relation.descend(&:qualify), @skipped)
- end
- end
-
describe '#to_sql' do
it "manufactures sql with limit and offset" do
Skip.new(@relation, @skipped).to_s.should be_like("
diff --git a/spec/active_relation/unit/relations/table_spec.rb b/spec/active_relation/unit/relations/table_spec.rb
index 6286ea9de1..2751d9cb63 100644
--- a/spec/active_relation/unit/relations/table_spec.rb
+++ b/spec/active_relation/unit/relations/table_spec.rb
@@ -46,8 +46,8 @@ module ActiveRelation
end
describe '#column_for' do
- it "" do
- @relation[:id].column.should == @relation.columns.detect { |c| c.name == 'id' }
+ it "returns the column corresponding to the attribute" do
+ @relation.column_for(@relation[:id]).should == @relation.columns.detect { |c| c.name == 'id' }
end
end
@@ -68,19 +68,12 @@ module ActiveRelation
describe '#reset' do
it "reloads columns from the database" do
- pending
lambda { stub(@relation.engine).columns { [] } }.should_not change { @relation.attributes }
lambda { @relation.reset }.should change { @relation.attributes }
end
end
end
- describe '#qualify' do
- it 'manufactures a rename relation with all attribute names qualified' do
- @relation.qualify.should == Rename.new(@relation, @relation[:name] => 'users.name', @relation[:id] => 'users.id')
- end
- end
-
describe 'hashing' do
it "implements hash equality" do
Table.new(:users).should hash_the_same_as(Table.new(:users))
diff --git a/spec/active_relation/unit/relations/take_spec.rb b/spec/active_relation/unit/relations/take_spec.rb
index beaa9e2f8c..8c13732258 100644
--- a/spec/active_relation/unit/relations/take_spec.rb
+++ b/spec/active_relation/unit/relations/take_spec.rb
@@ -4,27 +4,15 @@ module ActiveRelation
describe Take do
before do
@relation = Table.new(:users)
- @takene = 4
+ @taken = 4
end
- describe '#qualify' do
- it "descends" do
- Take.new(@relation, @takene).qualify.should == Take.new(@relation, @takene).descend(&:qualify)
- end
- end
-
- describe '#descend' do
- it "distributes a block over the relation" do
- Take.new(@relation, @takene).descend(&:qualify).should == Take.new(@relation.descend(&:qualify), @takene)
- end
- end
-
describe '#to_sql' do
it "manufactures sql with limit and offset" do
- Take.new(@relation, @takene).to_s.should be_like("
+ Take.new(@relation, @taken).to_s.should be_like("
SELECT `users`.`id`, `users`.`name`
FROM `users`
- LIMIT #{@takene}
+ LIMIT #{@taken}
")
end
end