aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-12 15:56:07 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-12 15:56:07 -0700
commit6de1f350ce117129e46353f12f90a138ca3d3ead (patch)
tree4d25ac9d653ea76a10f682cd0e8e3e7270a569a2
parenta0dc6900330b7ec78785a80fe8b72595384635a0 (diff)
downloadrails-6de1f350ce117129e46353f12f90a138ca3d3ead.tar.gz
rails-6de1f350ce117129e46353f12f90a138ca3d3ead.tar.bz2
rails-6de1f350ce117129e46353f12f90a138ca3d3ead.zip
- string passthrough for joins
- blank checks
-rw-r--r--doc/CONVENTIONS2
-rw-r--r--doc/TODO7
-rw-r--r--lib/active_relation/primitives/value.rb4
-rw-r--r--lib/active_relation/relations/order.rb12
-rw-r--r--lib/active_relation/relations/relation.rb12
-rw-r--r--lib/active_relation/relations/skip.rb5
-rw-r--r--lib/active_relation/relations/take.rb5
-rw-r--r--spec/active_relation/unit/primitives/expression_spec.rb2
-rw-r--r--spec/active_relation/unit/primitives/value_spec.rb1
9 files changed, 29 insertions, 21 deletions
diff --git a/doc/CONVENTIONS b/doc/CONVENTIONS
index 0d7c1b4ef0..c415a527e1 100644
--- a/doc/CONVENTIONS
+++ b/doc/CONVENTIONS
@@ -11,7 +11,7 @@ This file should ultimately be replaced by a series of tests, something like a l
- 'obtains' is preferred to 'returns true'
- 'manufactures'
- in tests
- - when manufacturing expected values (right-hand-side of should), avoid convenience methods -- construct it by initializing the object directly (Foo.new(...)). This ensures equality expectations in tests is rigorous.
+ - when manufacturing expected values (right-hand-side of should), avoid convenience methods -- construct it by initializing the object directly (Foo.new(...)). This ensures equality expectations in tests are rigorous.
- the SUT should be manufactured inline inside the test, not in a before
- dependencies for the SUT should be manufactured using convenience methods (or whatever is most terse).
- group conceptually related methods in a class within an inline module; immediately include that module. \ No newline at end of file
diff --git a/doc/TODO b/doc/TODO
index 889f7fccb6..7890daa503 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,4 +1,6 @@
todo:
+- test Value, in particular bind.
+- test blank checks in relation.rb
- mock out database
- finish pending tests
- test relation, table reset
@@ -7,9 +9,6 @@ todo:
- "unit" test sql strategies
- use real world examples, so they should be like a tutorial.
-- string passthrough:
- :joins=>"INNER JOIN posts ON comments.post_id = posts.id"
- - shit this one is hard at the moment.
- cache expiry on write
- rewrite of querycache test in light of this
@@ -59,6 +58,8 @@ done:
- relation inclusion when given an array (1,2,3,4) should quote the elements using the appropriate quoting formatter taken from the attribute
- descend on array, along with bind written in terms of it
- re-evaluate bind -- does bind belong inside the relation / predicate classes or in the factory methods?
+- string passthrough:
+ :joins=>"INNER JOIN posts ON comments.post_id = posts.id"
icebox:
- #bind in Attribute and Expression should be doing a descend?
diff --git a/lib/active_relation/primitives/value.rb b/lib/active_relation/primitives/value.rb
index 6f251d442b..3fbe907324 100644
--- a/lib/active_relation/primitives/value.rb
+++ b/lib/active_relation/primitives/value.rb
@@ -23,5 +23,9 @@ module ActiveRelation
def qualify
self
end
+
+ def bind(relation)
+ Value.new(value, relation)
+ end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/order.rb b/lib/active_relation/relations/order.rb
index 95b73c5e90..d71ff09c41 100644
--- a/lib/active_relation/relations/order.rb
+++ b/lib/active_relation/relations/order.rb
@@ -1,25 +1,25 @@
module ActiveRelation
class Order < Compound
- attr_reader :order
+ attr_reader :ordering
def initialize(relation, *orders)
- order = orders.pop
+ ordering = orders.pop
@relation = orders.empty?? relation : Order.new(relation, *orders)
- @order = order.bind(@relation)
+ @ordering = ordering.bind(@relation)
end
def ==(other)
self.class == other.class and
relation == other.relation and
- orders == other.orders
+ ordering == other.ordering
end
def descend(&block)
- Order.new(relation.descend(&block), *orders.collect(&block))
+ Order.new(relation.descend(&block), yield(ordering))
end
def orders
- relation.orders + [order]
+ relation.orders + [ordering]
end
end
end \ No newline at end of file
diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb
index 29c6fbbed0..f5f2809724 100644
--- a/lib/active_relation/relations/relation.rb
+++ b/lib/active_relation/relations/relation.rb
@@ -41,27 +41,27 @@ module ActiveRelation
end
def select(*predicates)
- Selection.new(self, *predicates)
+ predicates.all?(&:blank?) ? self : Selection.new(self, *predicates)
end
def project(*attributes)
- Projection.new(self, *attributes)
+ attributes.all?(&:blank?) ? self : Projection.new(self, *attributes)
end
def as(aliaz)
- Alias.new(self, aliaz)
+ aliaz.blank?? self : Alias.new(self, aliaz)
end
def order(*attributes)
- Order.new(self, *attributes)
+ attributes.all?(&:blank?) ? self : Order.new(self, *attributes)
end
def take(taken)
- Take.new(self, taken)
+ taken.blank?? self : Take.new(self, taken)
end
def skip(skipped)
- Skip.new(self, skipped)
+ skipped.blank?? self : Skip.new(self, skipped)
end
def rename(attribute, aliaz)
diff --git a/lib/active_relation/relations/skip.rb b/lib/active_relation/relations/skip.rb
index 7fd5e1603a..3133a3af41 100644
--- a/lib/active_relation/relations/skip.rb
+++ b/lib/active_relation/relations/skip.rb
@@ -7,8 +7,9 @@ module ActiveRelation
end
def ==(other)
- relation == other.relation and
- skipped == other.skipped
+ self.class == other.class and
+ relation == other.relation and
+ skipped == other.skipped
end
def descend(&block)
diff --git a/lib/active_relation/relations/take.rb b/lib/active_relation/relations/take.rb
index efeff11bf2..02d507753d 100644
--- a/lib/active_relation/relations/take.rb
+++ b/lib/active_relation/relations/take.rb
@@ -7,8 +7,9 @@ module ActiveRelation
end
def ==(other)
- relation == other.relation and
- taken == other.taken
+ self.class == other.class and
+ relation == other.relation and
+ taken == other.taken
end
def descend(&block)
diff --git a/spec/active_relation/unit/primitives/expression_spec.rb b/spec/active_relation/unit/primitives/expression_spec.rb
index dda35157b0..c15b073ba3 100644
--- a/spec/active_relation/unit/primitives/expression_spec.rb
+++ b/spec/active_relation/unit/primitives/expression_spec.rb
@@ -14,7 +14,7 @@ module ActiveRelation
describe '#bind' do
it "manufactures an attribute with a rebound relation and self as the ancestor" do
- derived_relation = @relation.select(@relation[:id] == 1)
+ derived_relation = @relation.select(@relation[:id].eq(1))
@expression.bind(derived_relation).should == Expression.new(@attribute.bind(derived_relation), "COUNT", nil, @expression)
end
diff --git a/spec/active_relation/unit/primitives/value_spec.rb b/spec/active_relation/unit/primitives/value_spec.rb
new file mode 100644
index 0000000000..f87f5c14cb
--- /dev/null
+++ b/spec/active_relation/unit/primitives/value_spec.rb
@@ -0,0 +1 @@
+# TODO \ No newline at end of file