Sha256: 4d852a06bd61a95f46ef20ad734e45e4780f7f6ed1db56fe790db9ec60297c5d

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'rails_helper'

module ActiveAdmin
  RSpec.describe Resource, "Ordering" do
    describe "#order_by" do

      let(:application) { ActiveAdmin::Application.new }
      let(:namespace) { ActiveAdmin::Namespace.new application, :admin }
      let(:resource_config) { ActiveAdmin::Resource.new namespace, Post }
      let(:dsl){ ActiveAdmin::ResourceDSL.new(resource_config, Post) }

      it "should register the ordering in the config" do
        dsl.run_registration_block do
          order_by(:age) do |order_clause|
            if order_clause.order == 'desc'
              [order_clause.to_sql, 'NULLS LAST'].join(' ')
            end
          end
        end
        expect(resource_config.ordering.size).to eq(1)
      end


      it "should allow to setup custom ordering class" do
        MyOrderClause = Class.new(ActiveAdmin::OrderClause)
        dsl.run_registration_block do
          config.order_clause = MyOrderClause
        end
        expect(resource_config.order_clause).to eq(MyOrderClause)
        expect(application.order_clause).to eq(ActiveAdmin::OrderClause)

      end

    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeadmin-1.0.0.pre5 spec/unit/resource/ordering_spec.rb