|
3 | 3 | describe AjaxDatatablesRails::Datatable::Datatable do |
4 | 4 |
|
5 | 5 | let(:datatable) { ComplexDatatable.new(sample_params).datatable } |
| 6 | + let(:datatable_json) { ComplexDatatable.new(sample_params_json).datatable } |
6 | 7 | let(:order_option) { {'0'=>{'column'=>'0', 'dir'=>'asc'}, '1'=>{'column'=>'1', 'dir'=>'desc'}} } |
| 8 | + let(:order_option_json) { [{'column'=>'0', 'dir'=>'asc'}, {'column'=>'1', 'dir'=>'desc'}] } |
7 | 9 |
|
8 | | - describe 'order methods' do |
| 10 | + shared_examples 'order methods' do |
9 | 11 | it 'should be orderable' do |
10 | 12 | expect(datatable.orderable?).to eq(true) |
11 | 13 | end |
|
35 | 37 | end |
36 | 38 | end |
37 | 39 |
|
| 40 | + shared_examples 'columns methods' do |
| 41 | + it 'should have 4 columns' do |
| 42 | + expect(datatable.columns.count).to eq(6) |
| 43 | + end |
| 44 | + |
| 45 | + it 'child class' do |
| 46 | + expect(datatable.columns.first).to be_a(AjaxDatatablesRails::Datatable::Column) |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + describe 'with query params' do |
| 51 | + it_behaves_like 'order methods' |
| 52 | + it_behaves_like 'columns methods' |
| 53 | + end |
| 54 | + |
| 55 | + describe 'with json params' do |
| 56 | + let(:order_option) { order_option_json } |
| 57 | + let(:datatable) { datatable_json } |
| 58 | + it_behaves_like 'order methods' |
| 59 | + it_behaves_like 'columns methods' |
| 60 | + end |
| 61 | + |
38 | 62 | describe 'search methods' do |
39 | 63 | it 'should be searchable' do |
40 | 64 | datatable.options[:search][:value] = 'atom' |
|
51 | 75 | end |
52 | 76 | end |
53 | 77 |
|
54 | | - describe 'columns methods' do |
55 | | - it 'should have 4 columns' do |
56 | | - expect(datatable.columns.count).to eq(6) |
57 | | - end |
58 | | - |
59 | | - it 'child class' do |
60 | | - expect(datatable.columns.first).to be_a(AjaxDatatablesRails::Datatable::Column) |
61 | | - end |
62 | | - end |
63 | | - |
64 | 78 | describe 'option methods' do |
65 | 79 | before :each do |
66 | 80 | datatable.options[:start] = '50' |
|
0 commit comments