Sha256: 0051395c2c8b82ccbe60a087c106d26e0312246b6e7e761432900fc0060eac33

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation::Operation::Limit, '.new' do
  subject { object.new(relation, limit) }

  let(:original_relation) { Relation.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ] ]) }
  let(:object)            { described_class                                      }

  context 'with an ordered relation' do
    let(:relation) { original_relation.order { |r| r[:id] } }
    let(:limit)    { 1                                      }

    it { should be_kind_of(object) }
  end

  context 'with an ordered relation having an empty header' do
    let(:relation) { original_relation.order { |r| r[:id] }.project([]) }
    let(:limit)    { 1                                                  }

    it { should be_kind_of(object) }
  end

  context 'without an ordered relation' do
    let(:relation) { original_relation }
    let(:limit)    { 1                 }

    specify { expect { subject }.to raise_error(OrderedRelationRequiredError, 'can only limit an ordered operand') }
  end

  context 'with an limit less than 0' do
    let(:relation) { original_relation.order { |r| r[:id] } }
    let(:limit)    { -1                                     }

    specify { expect { subject }.to raise_error(InvalidLimitError, 'limit must be greater than or equal to 0, but was -1') }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.4 spec/unit/veritas/relation/operation/limit/class_methods/new_spec.rb