Sha256: 80790f3647c42728115ce99c4fca86ad51491f3cfad8e2a38dea51371d966039

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation::Operation::Order, '#delete' do
  subject { object.delete(other) }

  let(:object)     { described_class.new(relation, directions)                                }
  let(:relation)   { Relation.new([ attribute ], LazyEnumerable.new([ [ 1 ], [ 2 ], [ 3 ] ])) }
  let(:attribute)  { Attribute::Integer.new(:id)                                              }
  let(:directions) { [ attribute.desc ]                                                       }

  context 'when other relation has matching directions' do
    let(:other)      { other_base.sort_by(directions)                             }
    let(:other_base) { Relation.new([ attribute ], LazyEnumerable.new([ [ 2 ] ])) }

    it { should be_instance_of(described_class) }

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

    it 'passes expected relations into the deletion' do
      subject = self.subject.operand
      subject.left.should equal(relation)
      subject.right.should equal(other_base)
    end

    its(:directions) { should == directions }

    it 'deletes the tuples' do
      should == [ [ 3 ], [ 1 ] ]
    end
  end

  context 'when other relation does not have the same directions' do
    let(:other) { Relation.new([ attribute ], LazyEnumerable.new([ [ 2 ] ])).sort_by([ attribute ]) }

    specify { expect { subject }.to raise_error(OrderMismatchError, 'other relation must have matching directions to be deleted') }
  end

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

    specify { expect { subject }.to raise_error(OrderMismatchError, 'other relation must have matching directions to be deleted') }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axiom-0.1.0 spec/unit/axiom/relation/operation/order/delete_spec.rb