-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimize_spec.rb
49 lines (36 loc) · 1.57 KB
/
optimize_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# encoding: utf-8
require 'spec_helper'
describe Algebra::Summarization, '#optimize' do
subject { object.optimize }
let(:header) { [[:id, Integer], [:name, String], [:age, Integer]] }
let(:body) { LazyEnumerable.new([[1, 'Dan Kubb', 35], [2, 'Jane Doe', 24]]) }
let(:relation) { Relation.new(header, body) }
let(:operand) { relation }
let(:summarize_per) { relation.project([:id]) }
let(:summarizers) { { Attribute.coerce(:count) => ->(acc, tuple) { acc.to_i + 1 } } }
let(:object) { described_class.new(operand, summarize_per, summarizers) }
context 'when the operand is empty' do
let(:operand) { relation.restrict { false } }
it { should eql(summarize_per.extend { |r| r.add(:count, nil) }) }
it 'returns an equivalent relation to the unoptimized operation' do
should == object
end
it 'does not execute body#each' do
body.should_not_receive(:each)
subject
end
it_should_behave_like 'an optimize method'
end
context 'when the summarize_per is empty' do
let(:summarize_per) { relation.project([:id]).restrict { false } }
it { should eql(Relation.new(object.header)) }
it 'returns an equivalent relation to the unoptimized operation' do
should == object
end
it 'does not execute body#each' do
body.should_not_receive(:each)
subject
end
it_should_behave_like 'an optimize method'
end
end