Sha256: d7548dde9774779710559636ca2e63b996cc4ccb903b8f6039637183751df7d4

Contents?: true

Size: 1.6 KB

Versions: 9

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true
require 'spec_helper'
require 'drillbit/resource/processors/sorting'

module    Drillbit
module    Resource
module    Processors
describe  Sorting do
  let(:sorting_resource) { double }

  it 'can return an ascending sort' do
    sorting = Sorting.new(sorting_resource, 'sort' => 'my_attribute')

    allow(sorting_resource).to receive(:order).
    with('my_attribute' => 'asc').
    and_return('sorted')

    expect(sorting.processed).to eql 'sorted'
    expect(sorting.meta).to      eql(
      'sort' => {
        'my_attribute' => 'asc',
      },
    )
  end

  it 'can return a descending sort' do
    sorting = Sorting.new(sorting_resource, 'sort' => '-my_attribute')

    allow(sorting_resource).to receive(:order).
    with('my_attribute' => 'desc').
    and_return('sorted')

    expect(sorting.processed).to eql 'sorted'
    expect(sorting.meta).to eql(
      'sort' => {
        'my_attribute' => 'desc',
      },
    )
  end

  it 'can return multiple sorts' do
    sorting = Sorting.new(sorting_resource, 'sort' => '-my_attribute,my_other_attribute')

    allow(sorting_resource).to receive(:order).
    with('my_attribute'       => 'desc',
         'my_other_attribute' => 'asc').
    and_return('sorted')

    expect(sorting.processed).to eql 'sorted'
    expect(sorting.meta).to eql(
      'sort' => {
        'my_attribute'       => 'desc',
        'my_other_attribute' => 'asc',
      },
    )
  end

  it 'does not do anything if sorting params are not passed in' do
    sorting = Sorting.new(sorting_resource)

    expect(sorting.processed).to eql sorting_resource
  end
end
end
end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
drillbit-2.9.1 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.9.0 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.8.0 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.7.0 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.6.0 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.5.0 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.4.0 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.3.1 spec/drillbit/resource/processors/sorting_spec.rb
drillbit-2.3.0 spec/drillbit/resource/processors/sorting_spec.rb