Sha256: 3f5835341657cd49fadf520b1a7aa26a8909d0ef926125046d5a8db7c512ed53

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Algebra::Summarization, '#optimize' do
  subject { object.optimize }

  let(:header)        { [ [ :id, Integer ], [ :name, String ], [ :age, Integer ] ]           }
  let(:body)          { [ [ 1, 'Dan Kubb', 35 ], [ 2, 'Jane Doe', 24 ] ].each                }
  let(:relation)      { Relation.new(header, body)                                           }
  let(:operand)       { relation                                                             }
  let(:summarize_per) { relation.project([ :id ])                                            }
  let(:summarizers)   { { Attribute.coerce(:count) => lambda { |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::Empty.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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-optimizer-0.0.7 spec/integration/veritas/algebra/summarization/optimize_spec.rb
veritas-optimizer-0.0.6 spec/integration/veritas/algebra/summarization/optimize_spec.rb
veritas-optimizer-0.0.5 spec/integration/veritas/algebra/summarization/optimize_spec.rb
veritas-optimizer-0.0.4 spec/integration/veritas/algebra/summarization/optimize_spec.rb