diff options
-rw-r--r-- | Rakefile | 1 | ||||
-rw-r--r-- | doc/CONVENTIONS (renamed from CONVENTIONS) | 0 | ||||
-rw-r--r-- | doc/TODO (renamed from TODO) | 23 | ||||
-rw-r--r-- | lib/active_relation/predicates.rb | 20 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/selection.rb | 3 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/relation_spec.rb | 2 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/selection_spec.rb | 10 |
8 files changed, 28 insertions, 33 deletions
@@ -1,5 +1,4 @@ require 'rubygems' -require 'spec' require 'spec/rake/spectask' Spec::Rake::SpecTask.new do |t| diff --git a/CONVENTIONS b/doc/CONVENTIONS index 0d7c1b4ef0..0d7c1b4ef0 100644 --- a/CONVENTIONS +++ b/doc/CONVENTIONS @@ -1,27 +1,28 @@ todo: +- re-evaluate bind -- does bind belong inside the relation / predicate classes or in the factory methods? +- - mock out database +- #bind in Attribute and Expression should be doing a descend? +- try to make aggegration testing in join spec to be a bit more unit-like +- finish pending tests +- test relation, table reset +- standardize quoting + - use strings everywhere, not symbols ? +- "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. - + - need adapters for this form: {:conditions=>["approved = ?", false]} {:conditions=>{:approved=>false}} {:conditions=>{"topics.approved"=>false}} {:conditions=>{:address=>#<Address:0x3489b3c @street="Funny Street", @country="Loony Land", @city="Scary Town">, "customers.name"=>"David1"}} -- re-evaluate bind -- does bind belong inside the relation / predicate classes or in the factory methods? -- #bind in Attribute and Expression should be doing a descend? -- try to make aggration testing in join spec to be a bit more unit-like -- finish pending tests -- test relation, table reset - cache expiry on write - rewrite of querycache test in light of this -- standardize quoting - - use strings everywhere, not symbols ? -- "unit" test sql strategies - - use real world examples, so they should be like a tutorial. - rename the tion (Selection) classes so that words that don't end in tion don't seem inconsistent -- mock out database done: . Relation <=> Relation -> InnerJoinOperation diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb index 22fbcd9f0b..e17a9f82fe 100644 --- a/lib/active_relation/predicates.rb +++ b/lib/active_relation/predicates.rb @@ -46,27 +46,19 @@ module ActiveRelation end class GreaterThanOrEqualTo < Binary - def predicate_sql - '>=' - end + def predicate_sql; '>=' end end class GreaterThan < Binary - def predicate_sql - '>' - end + def predicate_sql; '>' end end class LessThanOrEqualTo < Binary - def predicate_sql - '<=' - end + def predicate_sql; '<=' end end class LessThan < Binary - def predicate_sql - '<' - end + def predicate_sql; '<' end end class Match < Binary @@ -74,8 +66,6 @@ module ActiveRelation end class In < Binary - def predicate_sql - operand2.inclusion_predicate_sql - end + def predicate_sql; operand2.inclusion_predicate_sql 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 db61fce3de..f7e47c2e50 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -38,7 +38,7 @@ module ActiveRelation end def select(*predicates) - Selection.new(self, *predicates.collect {|p| p.bind(self)}) + Selection.new(self, *predicates) end def project(*attributes) diff --git a/lib/active_relation/relations/selection.rb b/lib/active_relation/relations/selection.rb index fe28908cc2..032de63d04 100644 --- a/lib/active_relation/relations/selection.rb +++ b/lib/active_relation/relations/selection.rb @@ -3,8 +3,9 @@ module ActiveRelation attr_reader :predicate def initialize(relation, *predicates) - @predicate = predicates.shift + predicate = predicates.shift @relation = predicates.empty?? relation : Selection.new(relation, *predicates) + @predicate = predicate.bind(@relation) end def ==(other) diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb index d434a1e317..7bb85d7270 100644 --- a/spec/active_relation/unit/relations/relation_spec.rb +++ b/spec/active_relation/unit/relations/relation_spec.rb @@ -91,7 +91,7 @@ module ActiveRelation end it "accepts arbitrary strings" do - @relation.select("arbitrary").should == Selection.new(@relation, Value.new("arbitrary", @relation)) + @relation.select("arbitrary").should == Selection.new(@relation, "arbitrary") end end diff --git a/spec/active_relation/unit/relations/selection_spec.rb b/spec/active_relation/unit/relations/selection_spec.rb index 001c38c370..1919d3007e 100644 --- a/spec/active_relation/unit/relations/selection_spec.rb +++ b/spec/active_relation/unit/relations/selection_spec.rb @@ -26,9 +26,13 @@ module ActiveRelation end describe '#descend' do + before do + @selection = Selection.new(@relation, @predicate) + end + it "distributes a block over the relation and predicates" do - Selection.new(@relation, @predicate).descend(&:qualify). \ - should == Selection.new(@relation.descend(&:qualify), @predicate.descend(&:qualify)) + @selection.descend(&:qualify). \ + should == Selection.new(@selection.relation.descend(&:qualify), @selection.predicate.qualify) end end @@ -45,7 +49,7 @@ module ActiveRelation describe 'when given a string' do before do - @string = "asdf".bind(@relation) + @string = "asdf" end it "passes the string through to the where clause" do |