Sha256: 451232ae9f2540c09dd535dfa7127f9b086915965969b367f857fbe550f19147

Contents?: true

Size: 980 Bytes

Versions: 1

Compression:

Stored size: 980 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation::Operation::Order::Methods, '#order' do
  let(:described_class) { Relation                                                         }
  let(:object)          { described_class.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ] ].each) }

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

    it { should be_kind_of(Relation::Operation::Order) }

    its(:directions) { should == object.header }

    it 'behaves the same as Array#sort_by' do
      subject.to_a.should == object.to_a.sort_by { |tuple| tuple[:id] }
    end
  end

  context 'with a block' do
    subject { object.order(&block) }

    let(:block) { lambda { |relation| [ relation[:id].desc ] } }

    it { should be_kind_of(Relation::Operation::Order) }

    its(:directions) { should == block.call(object) }

    it 'behaves the same as Array#sort_by' do
      subject.to_a.should == object.to_a.sort_by { |tuple| tuple[:id] }.reverse
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.4 spec/unit/veritas/relation/operation/order/methods/order_spec.rb