Sha256: 2cd1298fe9ee0d258a2e0251d54c485ef7bb07b89b59a85e850a31d4e6b67016

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

describe 'AjaxDatatablesRails::Datatable::Column' do
  let(:view) { double('view', params: sample_params) }
  let(:datatable) { ComplexDatatable.new(view) }
  before {
    datatable.params[:columns] = {"0"=>{"data"=>"username", "name"=>"", "searchable"=>"true", "orderable"=>"true", "search"=>{"value"=>"searchvalue", "regex"=>"false"}}}
  }

  describe 'helper methods' do
    describe 'order methods' do
      let(:column) { datatable.datatable.columns.first }

      it 'should be orderable' do
        expect(column.orderable?).to eq(true)
      end

      it 'should be searchable' do
        expect(column.searchable?).to eq(true)
      end

      it 'should have connected to id column' do
        expect(column.data).to eq('username')
      end

      context '#search' do
        it 'child class' do
          expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch)
        end

        it 'should have search value' do
          expect(column.search.value).to eq('searchvalue')
        end

        it 'should not regex' do
          expect(column.search.regexp?).to eq false
        end
      end

      describe '#cond' do
        it 'should be :like by default' do
          expect(column.cond).to eq(:like)
        end
      end

      describe '#source' do
        it 'should be :like by default' do
          expect(column.source).to eq('User.username')
        end
      end

      describe '#search_query' do
        it 'should buld search query' do
          expect(column.search_query.to_sql).to include('%searchvalue%')
        end
      end

      describe '#sort_query' do
        it 'should build sort query' do
          expect(column.sort_query).to eq('users.username')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datatables-net-0.4.0 spec/ajax-datatables-rails/datatable/column_spec.rb