Sha256: a681ac48033f9a33afcfa0edb3cdb143e37adae13350b1659cb57ed5623e3ed8

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

shared_examples_for 'order parameter' do

  describe ':order' do

    if testing_active_record?

      it 'should be able to order the result set asc' do
        scope = Post.by_year(Time.zone.now.year, order: 'created_at ASC')
        expect(scope.order_values).to eq ['created_at ASC']
        expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
      end

      it 'should be able to order the result set desc' do
        scope = Post.by_year(Time.zone.now.year, order: 'created_at DESC')
        expect(scope.order_values).to eq ['created_at DESC']
        expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
      end

    elsif testing_mongoid?

      it 'should be able to order the result set asc' do
        scope = Post.by_year(Time.zone.now.year, order: {created_at: :asc})
        expect(scope.options[:sort]).to eq({'created_at' => 1})
        expect(scope.first.created_at).to eq Time.zone.parse('2014-01-01 17:00:00')
      end

      it 'should be able to order the result set desc' do
        scope = Post.by_year(Time.zone.now.year, order: {created_at: :desc})
        expect(scope.options[:sort]).to eq({'created_at' => -1})
        expect(scope.first.created_at).to eq Time.zone.parse('2014-04-15 17:00:00')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
ta_by_star-4.1.0 spec/integration/shared/order_parameter.rb
ta_by_star-4.0.0 spec/integration/shared/order_parameter.rb
by_star-4.0.0 spec/integration/shared/order_parameter.rb
by_star-3.0.0 spec/integration/shared/order_parameter.rb