diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-11 18:32:47 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-11 18:32:47 -0700 |
commit | a0dc6900330b7ec78785a80fe8b72595384635a0 (patch) | |
tree | 2f73c8433cecf638fd53c33e09803b1012b61759 | |
parent | ae0fe8f6c8c41b5abf8ced6a99b19dacdf8f57eb (diff) | |
download | rails-a0dc6900330b7ec78785a80fe8b72595384635a0.tar.gz rails-a0dc6900330b7ec78785a80fe8b72595384635a0.tar.bz2 rails-a0dc6900330b7ec78785a80fe8b72595384635a0.zip |
fixed bug with take/skip
-rw-r--r-- | lib/active_relation/relations/compound.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 8 | ||||
-rw-r--r-- | lib/active_relation/relations/skip.rb | 10 | ||||
-rw-r--r-- | lib/active_relation/relations/take.rb | 10 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/relation_spec.rb | 12 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/skip_spec.rb | 10 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/take_spec.rb | 10 |
7 files changed, 38 insertions, 26 deletions
diff --git a/lib/active_relation/relations/compound.rb b/lib/active_relation/relations/compound.rb index c5af453e4b..aa3274cbd3 100644 --- a/lib/active_relation/relations/compound.rb +++ b/lib/active_relation/relations/compound.rb @@ -4,8 +4,8 @@ module ActiveRelation hash_on :relation - delegate :joins, :selects, :orders, :groupings, :table_sql, :inserts, :take, - :skip, :name, :alias, :aggregation?, :alias?, :prefix_for, :column_for, + delegate :joins, :selects, :orders, :groupings, :table_sql, :inserts, :taken, + :skipped, :name, :alias, :aggregation?, :alias?, :prefix_for, :column_for, :engine, :to => :relation diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index b26fac4e85..29c6fbbed0 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -120,8 +120,8 @@ module ActiveRelation ("WHERE #{selects.collect { |s| s.to_sql(Sql::WhereClause.new(engine)) }.join("\n\tAND ")}" unless selects.blank? ), ("ORDER BY #{orders.collect { |o| o.to_sql(Sql::OrderClause.new(engine)) }.join(', ')}" unless orders.blank? ), ("GROUP BY #{groupings.collect(&:to_sql)}" unless groupings.blank? ), - ("LIMIT #{take}" unless take.blank? ), - ("OFFSET #{skip}" unless skip.blank? ) + ("LIMIT #{taken}" unless taken.blank? ), + ("OFFSET #{skipped}" unless skipped.blank? ) ].compact.join("\n"), self.alias end alias_method :to_s, :to_sql @@ -159,8 +159,8 @@ module ActiveRelation def inserts; [] end def groupings; [] end def joins; nil end - def take; nil end - def skip; nil end + def taken; nil end + def skipped; nil end def alias; nil end end end
\ No newline at end of file diff --git a/lib/active_relation/relations/skip.rb b/lib/active_relation/relations/skip.rb index f963ee6468..7fd5e1603a 100644 --- a/lib/active_relation/relations/skip.rb +++ b/lib/active_relation/relations/skip.rb @@ -1,18 +1,18 @@ module ActiveRelation class Skip < Compound - attr_reader :skip + attr_reader :skipped - def initialize(relation, skip) - @relation, @skip = relation, skip + def initialize(relation, skipped) + @relation, @skipped = relation, skipped end def ==(other) relation == other.relation and - skip == other.skip + skipped == other.skipped end def descend(&block) - Skip.new(relation.descend(&block), skip) + Skip.new(relation.descend(&block), skipped) end end end
\ No newline at end of file diff --git a/lib/active_relation/relations/take.rb b/lib/active_relation/relations/take.rb index 9f98207798..efeff11bf2 100644 --- a/lib/active_relation/relations/take.rb +++ b/lib/active_relation/relations/take.rb @@ -1,18 +1,18 @@ module ActiveRelation class Take < Compound - attr_reader :take + attr_reader :taken - def initialize(relation, take) - @relation, @take = relation, take + def initialize(relation, taken) + @relation, @taken = relation, taken end def ==(other) relation == other.relation and - take == other.take + taken == other.taken end def descend(&block) - Take.new(relation.descend(&block), take) + Take.new(relation.descend(&block), taken) end end end
\ No newline at end of file diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb index d10ae490de..2a04276aeb 100644 --- a/spec/active_relation/unit/relations/relation_spec.rb +++ b/spec/active_relation/unit/relations/relation_spec.rb @@ -106,6 +106,18 @@ module ActiveRelation end end + describe '#take' do + it "manufactures a take relation" do + @relation.take(5).should == Take.new(@relation, 5) + end + end + + describe '#skip' do + it "manufactures a skip relation" do + @relation.skip(4).should == Skip.new(@relation, 4) + end + end + describe '#call' do it 'executes a select_all on the connection' do mock(connection = Object.new).select_all(@relation.to_sql) diff --git a/spec/active_relation/unit/relations/skip_spec.rb b/spec/active_relation/unit/relations/skip_spec.rb index 77f2b8db27..d50ef715ee 100644 --- a/spec/active_relation/unit/relations/skip_spec.rb +++ b/spec/active_relation/unit/relations/skip_spec.rb @@ -4,27 +4,27 @@ module ActiveRelation describe Skip do before do @relation = Table.new(:users) - @skip = 4 + @skipped = 4 end describe '#qualify' do it "descends" do - Skip.new(@relation, @skip).qualify.should == Skip.new(@relation, @skip).descend(&:qualify) + 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, @skip).descend(&:qualify).should == Skip.new(@relation.descend(&:qualify), @skip) + 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, @skip).to_s.should be_like(" + Skip.new(@relation, @skipped).to_s.should be_like(" SELECT `users`.`id`, `users`.`name` FROM `users` - OFFSET #{@skip} + OFFSET #{@skipped} ") end end diff --git a/spec/active_relation/unit/relations/take_spec.rb b/spec/active_relation/unit/relations/take_spec.rb index 6523ff85f9..beaa9e2f8c 100644 --- a/spec/active_relation/unit/relations/take_spec.rb +++ b/spec/active_relation/unit/relations/take_spec.rb @@ -4,27 +4,27 @@ module ActiveRelation describe Take do before do @relation = Table.new(:users) - @take = 4 + @takene = 4 end describe '#qualify' do it "descends" do - Take.new(@relation, @take).qualify.should == Take.new(@relation, @take).descend(&:qualify) + 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, @take).descend(&:qualify).should == Take.new(@relation.descend(&:qualify), @take) + 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, @take).to_s.should be_like(" + Take.new(@relation, @takene).to_s.should be_like(" SELECT `users`.`id`, `users`.`name` FROM `users` - LIMIT #{@take} + LIMIT #{@takene} ") end end |