Sha256: 371125be07ab4de87d0daf1908e6b67fdfaf5719358cfc70a30563b83616c3a4

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Algebra::Extension, '#insert' do
  subject { object.insert(other) }

  let(:object)         { described_class.new(operand, extensions)        }
  let(:operand)        { Relation.new(header, LazyEnumerable.new([[1]])) }
  let(:extensions)     { { extension_attr => 1 }                         }
  let(:extension_attr) { Attribute::Integer.new(:test)                   }
  let(:header)         { [[:id, Integer]]                                }

  context 'when other relation has matching extensions' do
    let(:other) do
      Relation.new(header, LazyEnumerable.new([[2]])).extend do |context|
        context.add(:test, 1)
      end
    end

    it { should be_instance_of(described_class) }

    its(:operand) { should be_kind_of(Relation) }

    its(:header) { should == [[:id, Integer], [:test, Integer]] }

    it 'inserts the tuples' do
      should == [[1, 1], [2, 1]]
    end
  end

  context 'when other relation does not have the same extensions' do
    let(:other) do
      Relation.new(header, LazyEnumerable.new([[2]])).extend do |context|
        context.add(:test, 2)
      end
    end

    specify { expect { subject }.to raise_error(ExtensionMismatchError, 'other relation must have matching extensions to be inserted') }
  end

  context 'when other relation is not an extension' do
    let(:other) { Relation.new(header, LazyEnumerable.new([[2]])) }

    specify { expect { subject }.to raise_error(ExtensionMismatchError, 'other relation must have matching extensions to be inserted') }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-0.2.0 spec/unit/axiom/algebra/extension/insert_spec.rb
axiom-0.1.1 spec/unit/axiom/algebra/extension/insert_spec.rb