From 9dea5afdb76a43f1683c4e50b8a1af113eb95ed0 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Wed, 11 Nov 2009 11:53:53 -0800 Subject: [PATCH] Added specs to ensure Unioned Collections work with aggregate functions * This corresponds with fixes made in dm-core that allow these specs to pass. [#1121 state:resolved] --- dm-aggregates/spec/public/collection_spec.rb | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/dm-aggregates/spec/public/collection_spec.rb b/dm-aggregates/spec/public/collection_spec.rb index 9b298280..58dd1804 100644 --- a/dm-aggregates/spec/public/collection_spec.rb +++ b/dm-aggregates/spec/public/collection_spec.rb @@ -54,5 +54,53 @@ end end end + + describe 'with collections created with Set operations' do + before do + @collection = @dragons.all(:name => 'George') | @dragons.all(:name => 'Puff') + end + + describe '#size' do + subject { @collection.size } + + it { should == 2 } + end + + describe '#count' do + subject { @collection.count } + + it { should == 2 } + end + + describe '#min' do + subject { @collection.min(:toes_on_claw) } + + it { should == 3 } + end + + describe '#max' do + subject { @collection.max(:toes_on_claw) } + + it { should == 4 } + end + + describe '#avg' do + subject { @collection.avg(:toes_on_claw) } + + it { should == 3.5 } + end + + describe '#sum' do + subject { @collection.sum(:toes_on_claw) } + + it { should == 7 } + end + + describe '#aggregate' do + subject { @collection.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum)} + + it { should == [ 2, 2, 3, 4, 3.5, 7 ] } + end + end end end