Sha256: f2a612ec18b1a17a6df46b8ea2e80793201bf9e4c4c6b5062faf48738f8b9c59

Contents?: true

Size: 1.77 KB

Versions: 21

Compression:

Stored size: 1.77 KB

Contents

require 'rails_helper'

RSpec.describe ActiveAdmin::OrderClause do
  subject { described_class.new(config, clause) }

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

  describe 'id_asc (existing column)' do
    let(:clause) { 'id_asc' }

    it { is_expected.to be_valid }

    describe '#field' do
      subject { super().field }
      it { is_expected.to eq('id') }
    end

    describe '#order' do
      subject { super().order }
      it { is_expected.to eq('asc') }
    end

    specify '#to_sql prepends table name' do
      expect(subject.to_sql).to eq '"posts"."id" asc'
    end
  end

  describe 'virtual_column_asc' do
    let(:clause) { 'virtual_column_asc' }

    it { is_expected.to be_valid }

    describe '#field' do
      subject { super().field }
      it { is_expected.to eq('virtual_column') }
    end

    describe '#order' do
      subject { super().order }
      it { is_expected.to eq('asc') }
    end

    specify '#to_sql' do
      expect(subject.to_sql).to eq '"virtual_column" asc'
    end
  end

  describe "hstore_col->'field'_desc" do
    let(:clause) { "hstore_col->'field'_desc" }

    it { is_expected.to be_valid }

    describe '#field' do
      subject { super().field }
      it { is_expected.to eq("hstore_col->'field'") }
    end

    describe '#order' do
      subject { super().order }
      it { is_expected.to eq('desc') }
    end

    it 'converts to sql' do
      expect(subject.to_sql).to eq %Q("hstore_col"->'field' desc)
    end
  end

  describe '_asc' do
    let(:clause) { '_asc' }

    it { is_expected.not_to be_valid }
  end

  describe 'nil' do
    let(:clause) { nil }

    it { is_expected.not_to be_valid }
  end
end

Version data entries

21 entries across 21 versions & 4 rubygems

Version Path
activeadmin-rails-1.7.1 spec/unit/order_clause_spec.rb
activeadmin-rails-1.7.0 spec/unit/order_clause_spec.rb
activeadmin-rb-1.6.0 spec/unit/order_clause_spec.rb
activeadmin-rb-1.5.2 spec/unit/order_clause_spec.rb
activeadmin-rb-1.5.1 spec/unit/order_clause_spec.rb
activeadmin-rb-1.5.0 spec/unit/order_clause_spec.rb
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/order_clause_spec.rb
activeadmin-rb-1.4.0 spec/unit/order_clause_spec.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/order_clause_spec.rb
activeadmin-1.3.1 spec/unit/order_clause_spec.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/order_clause_spec.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/order_clause_spec.rb
activeadmin-1.3.0 spec/unit/order_clause_spec.rb
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/order_clause_spec.rb
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/order_clause_spec.rb
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/order_clause_spec.rb
activeadmin-1.2.1 spec/unit/order_clause_spec.rb
activeadmin-1.2.0 spec/unit/order_clause_spec.rb
activeadmin-1.1.0 spec/unit/order_clause_spec.rb
activeadmin-1.0.0 spec/unit/order_clause_spec.rb