Permalink
Browse files

Summarize over TABLE_DEE when nothing specified to summarize with

* Minor spec and doc cleanup
  • Loading branch information...
1 parent b27a754 commit 899465a46320048d5153299903f40499fe01e80f @dkubb dkubb committed Jun 15, 2011
View
@@ -1,3 +1,3 @@
---
threshold: 68
-total_score: 754
+total_score: 738
@@ -155,14 +155,19 @@ module Methods
# Return a summarized relation
#
+ # @example with no arguments
+ # summarization = relation.summarize do |context|
+ # context.add(:count, context[:id].count)
+ # end
+ #
# @example with a relation
# summarization = relation.summarize(relation.project([ :name ])) do |context|
- # context.add(:count, context[:name].count)
+ # context.add(:count, context[:id].count)
# end
#
# @example with a header
# summarization = relation.summarize([ :name ]) do |context|
- # context.add(:count, context[:name].count)
+ # context.add(:count, context[:id].count)
# end
#
# @param [Relation, Header, #to_ary] summarize_with
@@ -176,7 +181,7 @@ module Methods
# @return [Summarization]
#
# @api public
- def summarize(summarize_with)
+ def summarize(summarize_with = TABLE_DEE)
summarize_per = coerce_to_relation(summarize_with)
context = Evaluator::Context.new(header - summarize_per.header) { |context| yield context }
Summarization.new(self, summarize_per, context.functions)
@@ -10,7 +10,17 @@
let(:block) { lambda { |r| r.add(*summarizers) } }
let(:object) { described_class.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ].each) }
- context 'when summarizing per a relation' do
+ context 'with no arguments' do
+ subject { object.summarize(&block) }
+
+ it { should be_kind_of(Algebra::Summarization) }
+
+ its(:operand) { should equal(object) }
+
+ its(:summarize_per) { should equal(TABLE_DEE) }
+ end
+
+ context 'with a relation' do
let(:summarize_with) { object.project([]) }
it { should be_kind_of(Algebra::Summarization) }
@@ -20,8 +30,8 @@
its(:summarize_per) { should equal(summarize_with) }
end
- context 'when summarizing by a header' do
- let(:summarize_with) { [] }
+ context 'with a header' do
+ let(:summarize_with) { object.project([]).header }
it { should be_kind_of(Algebra::Summarization) }
@@ -30,7 +40,7 @@
its(:summarize_per) { should == object.project(summarize_with) }
end
- context 'when using a summarized-on attribute in the context' do
+ context 'with a header containing an attribute used in the context block' do
let(:summarize_with) { object.project([ :id ]) }
let(:block) { lambda { |r| r.add(:count, r.id.count) } }

0 comments on commit 899465a

Please sign in to comment.