Sha256: 50ef5b9d104dc3ff51caa1306d7327f66dcea536954e52fc70c1982249d6eb3d

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

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

  context 'with an ordered relation' do
    let(:relation) { original_relation.sort_by { |r| r.id } }
    let(:offset)   { 1                                      }

    it { should be_instance_of(object) }
  end

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

    it { should be_instance_of(object) }
  end

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

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

  context 'with an offset less than 0' do
    let(:relation) { original_relation.sort_by { |r| r.id } }
    let(:offset)   { -1                                     }

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

  context 'with a nil offset' do
    let(:relation) { original_relation.sort_by { |r| r.id } }
    let(:offset)   { nil                                    }

    specify { expect { subject }.to raise_error(InvalidOffsetError, 'offset must be greater than or equal to 0, but was nil') }
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
axiom-0.1.0 spec/unit/axiom/relation/operation/offset/class_methods/new_spec.rb
veritas-0.0.7 spec/unit/veritas/relation/operation/offset/class_methods/new_spec.rb
veritas-0.0.6 spec/unit/veritas/relation/operation/offset/class_methods/new_spec.rb
veritas-0.0.5 spec/unit/veritas/relation/operation/offset/class_methods/new_spec.rb