Sha256: 9dc6954478f06781714bc10b57c8da049427d0da1d7673d2cf59e86c7e426ac4

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation::Operation::Limit::Methods, '#first' do
  let(:described_class) { Relation                                                                   }
  let(:relation)        { described_class.new([[:id, Integer]], LazyEnumerable.new([[1], [2], [3]])) }
  let(:object)          { relation.sort_by { |r| r.id }                                              }

  context 'with no arguments' do
    subject { object.first }

    it { should be_instance_of(Relation::Operation::Limit) }

    its(:limit) { should == 1 }

    it 'returns the expected tuples' do
      should == [[1]]
    end

    it 'behaves similar to Array#first' do
      should == [object.to_a.first]
    end
  end

  context 'with a limit' do
    subject { object.first(limit) }

    let(:limit) { 2 }

    it { should be_instance_of(Relation::Operation::Limit) }

    its(:limit) { should == limit }

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

    it 'behaves the same as Array#first' do
      should == object.to_a.first(limit)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-0.2.0 spec/unit/axiom/relation/operation/limit/methods/first_spec.rb
axiom-0.1.1 spec/unit/axiom/relation/operation/limit/methods/first_spec.rb