diff options
Diffstat (limited to 'spec/active_relation/unit')
4 files changed, 59 insertions, 16 deletions
diff --git a/spec/active_relation/unit/relations/grouping_spec.rb b/spec/active_relation/unit/relations/grouping_spec.rb new file mode 100644 index 0000000000..4b5badbb8b --- /dev/null +++ b/spec/active_relation/unit/relations/grouping_spec.rb @@ -0,0 +1,33 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') + +module ActiveRelation + describe Grouping do + before do + @relation = Table.new(:users) + @attribute = @relation[:id] + end + + describe '#to_sql' do + describe 'when given a predicate' do + it "manufactures sql with where clause conditions" do + Grouping.new(@relation, @attribute).to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name` + FROM `users` + GROUP BY `users`.`id` + ") + end + end + + describe 'when given a string' do + it "passes the string through to the where clause" do + pending 'it should not quote asdf' + Grouping.new(@relation, 'asdf').to_sql.should be_like(" + SELECT `users`.`id`, `users`.`name` + FROM `users` + GROUP BY asdf + ") + end + end + end + end +end
\ No newline at end of file diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb index 22b0a9f237..c1a13cee6e 100644 --- a/spec/active_relation/unit/relations/join_spec.rb +++ b/spec/active_relation/unit/relations/join_spec.rb @@ -97,8 +97,8 @@ module ActiveRelation describe 'when joining aggregated relations' do before do @aggregation = @relation2 \ - .aggregate(@relation2[:user_id], @relation2[:id].count.as(:cnt)) \ .group(@relation2[:user_id]) \ + .project(@relation2[:user_id], @relation2[:id].count.as(:cnt)) \ .as('photo_count') end diff --git a/spec/active_relation/unit/relations/projection_spec.rb b/spec/active_relation/unit/relations/projection_spec.rb index 529998a8d4..5936cbc45f 100644 --- a/spec/active_relation/unit/relations/projection_spec.rb +++ b/spec/active_relation/unit/relations/projection_spec.rb @@ -53,16 +53,29 @@ module ActiveRelation end describe 'when given a string' do - before do - @string = "asdf" - end - it "passes the string through to the select clause" do - Projection.new(@relation, @string).to_sql.should be_like(" + Projection.new(@relation, 'asdf').to_sql.should be_like(" SELECT asdf FROM `users` ") end end end + + describe Projection::Externalizable do + describe '#aggregation?' do + describe 'when the projections are attributes' do + it 'returns false' do + Projection.new(@relation, @attribute).should_not be_aggregation + end + end + + describe 'when the projections include an aggregation' do + it "obtains" do + Projection.new(@relation, @attribute.sum).should be_aggregation + end + end + end + + 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 2b62c8db5e..c40974e136 100644 --- a/spec/active_relation/unit/relations/relation_spec.rb +++ b/spec/active_relation/unit/relations/relation_spec.rb @@ -154,18 +154,15 @@ module ActiveRelation end end - describe '#aggregate' do - before do - @expression1 = @attribute1.sum - @expression2 = @attribute2.sum + describe '#group' do + it 'manufactures a group relation' do + @relation.group(@attribute1, @attribute2).should == Grouping.new(@relation, @attribute1, @attribute2) end - it 'manufactures a group relation' do - @relation.aggregate(@expression1, @expression2).group(@attribute1, @attribute2). \ - should == Aggregation.new(@relation, - :expressions => [@expression1, @expression2], - :groupings => [@attribute1, @attribute2] - ) + describe 'when given blank groupings' do + it 'returns self' do + @relation.group.should == @relation + end end end |