|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | require 'spec_helper'
|
2 | 4 |
|
3 | 5 | describe AjaxDatatablesRails::Datatable::Column do
|
|
9 | 11 | let(:column) { datatable.datatable.columns.first }
|
10 | 12 |
|
11 | 13 | before do
|
12 |
| - datatable.params[:columns] = {'0'=>{'data'=>'username', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} |
| 14 | + datatable.params[:columns] = { '0' => { 'data' => 'username', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } |
13 | 15 | end
|
14 | 16 |
|
15 |
| - it 'should be orderable' do |
| 17 | + it 'is orderable' do |
16 | 18 | expect(column.orderable?).to eq(true)
|
17 | 19 | end
|
18 | 20 |
|
19 |
| - it 'should sort nulls last' do |
| 21 | + it 'sorts nulls last' do |
20 | 22 | expect(column.nulls_last?).to eq(false)
|
21 | 23 | end
|
22 | 24 |
|
23 |
| - it 'should be searchable' do |
| 25 | + it 'is searchable' do |
24 | 26 | expect(column.searchable?).to eq(true)
|
25 | 27 | end
|
26 | 28 |
|
27 |
| - it 'should be searched' do |
| 29 | + it 'is searched' do |
28 | 30 | expect(column.searched?).to eq(true)
|
29 | 31 | end
|
30 | 32 |
|
31 |
| - it 'should have connected to id column' do |
| 33 | + it 'has connected to id column' do |
32 | 34 | expect(column.data).to eq('username')
|
33 | 35 | end
|
34 | 36 |
|
35 | 37 | describe '#data' do
|
36 |
| - it 'should return the data from params' do |
| 38 | + it 'returns the data from params' do |
37 | 39 | expect(column.data).to eq 'username'
|
38 | 40 | end
|
39 | 41 | end
|
40 | 42 |
|
41 | 43 | describe '#source' do
|
42 |
| - it 'should return the data source from view_column' do |
| 44 | + it 'returns the data source from view_column' do |
43 | 45 | expect(column.source).to eq 'User.username'
|
44 | 46 | end
|
45 | 47 | end
|
46 | 48 |
|
47 | 49 | describe '#table' do
|
48 | 50 | context 'with ActiveRecord ORM' do
|
49 |
| - it 'should return the corresponding AR table' do |
| 51 | + it 'returns the corresponding AR table' do |
50 | 52 | expect(column.table).to eq User.arel_table
|
51 | 53 | end
|
52 | 54 | end
|
53 | 55 | context 'with other ORM' do
|
54 |
| - it 'should return the corresponding model' do |
| 56 | + it 'returns the corresponding model' do |
55 | 57 | expect(User).to receive(:respond_to?).with(:arel_table).and_return(false)
|
56 | 58 | expect(column.table).to eq User
|
57 | 59 | end
|
58 | 60 | end
|
59 | 61 | end
|
60 | 62 |
|
61 | 63 | describe '#model' do
|
62 |
| - it 'should return the corresponding AR model' do |
| 64 | + it 'returns the corresponding AR model' do |
63 | 65 | expect(column.model).to eq User
|
64 | 66 | end
|
65 | 67 | end
|
66 | 68 |
|
67 | 69 | describe '#field' do
|
68 |
| - it 'should return the corresponding field in DB' do |
| 70 | + it 'returns the corresponding field in DB' do |
69 | 71 | expect(column.field).to eq :username
|
70 | 72 | end
|
71 | 73 | end
|
72 | 74 |
|
73 | 75 | describe '#custom_field?' do
|
74 |
| - it 'should return false if field is bound to an AR field' do |
| 76 | + it 'returns false if field is bound to an AR field' do |
75 | 77 | expect(column.custom_field?).to be false
|
76 | 78 | end
|
77 | 79 | end
|
|
81 | 83 | expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch)
|
82 | 84 | end
|
83 | 85 |
|
84 |
| - it 'should have search value' do |
| 86 | + it 'has search value' do |
85 | 87 | expect(column.search.value).to eq('searchvalue')
|
86 | 88 | end
|
87 | 89 |
|
88 |
| - it 'should not regex' do |
| 90 | + it 'does not regex' do |
89 | 91 | expect(column.search.regexp?).to eq false
|
90 | 92 | end
|
91 | 93 | end
|
92 | 94 |
|
93 | 95 | describe '#cond' do
|
94 |
| - it 'should be :like by default' do |
| 96 | + it 'is :like by default' do |
95 | 97 | expect(column.cond).to eq(:like)
|
96 | 98 | end
|
97 | 99 | end
|
98 | 100 |
|
99 | 101 | describe '#source' do
|
100 |
| - it 'should be :like by default' do |
| 102 | + it 'is :like by default' do |
101 | 103 | expect(column.source).to eq('User.username')
|
102 | 104 | end
|
103 | 105 | end
|
104 | 106 |
|
105 | 107 | describe '#search_query' do
|
106 |
| - it 'should buld search query' do |
| 108 | + it 'bulds search query' do |
107 | 109 | expect(column.search_query.to_sql).to include('%searchvalue%')
|
108 | 110 | end
|
109 | 111 | end
|
110 | 112 |
|
111 | 113 | describe '#sort_query' do
|
112 |
| - it 'should build sort query' do |
| 114 | + it 'builds sort query' do |
113 | 115 | expect(column.sort_query).to eq('users.username')
|
114 | 116 | end
|
115 | 117 | end
|
116 | 118 |
|
117 | 119 | describe '#use_regex?' do
|
118 |
| - it 'should be true by default' do |
| 120 | + it 'is true by default' do |
119 | 121 | expect(column.use_regex?).to be true
|
120 | 122 | end
|
121 | 123 | end
|
122 | 124 |
|
123 | 125 | describe '#delimiter' do
|
124 |
| - it 'should be - by default' do |
| 126 | + it 'is - by default' do |
125 | 127 | expect(column.delimiter).to eq('-')
|
126 | 128 | end
|
127 | 129 | end
|
|
131 | 133 | let(:datatable) { DatatableWithFormater.new(sample_params) }
|
132 | 134 | let(:column) { datatable.datatable.columns.find { |c| c.data == 'last_name' } }
|
133 | 135 |
|
134 |
| - it 'should be a proc' do |
| 136 | + it 'is a proc' do |
135 | 137 | expect(column.formatter).to be_a(Proc)
|
136 | 138 | end
|
137 | 139 | end
|
|
140 | 142 | let(:datatable) { DatatableCondProc.new(sample_params) }
|
141 | 143 | let(:column) { datatable.datatable.columns.find { |c| c.data == 'username' } }
|
142 | 144 |
|
143 |
| - it 'should be a proc' do |
| 145 | + it 'is a proc' do |
144 | 146 | config = column.instance_variable_get('@view_column')
|
145 | 147 | filter = config[:cond]
|
146 | 148 | expect(filter).to be_a(Proc)
|
|
205 | 207 |
|
206 | 208 | describe 'when empty column' do
|
207 | 209 | before do
|
208 |
| - datatable.params[:columns] = {'0'=>{'data'=>'', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} |
| 210 | + datatable.params[:columns] = { '0' => { 'data' => '', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } |
209 | 211 | end
|
210 | 212 |
|
211 | 213 | it 'raises error' do
|
212 |
| - expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Unknown column. Check that `data` field is filled on JS side with the column name") |
| 214 | + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message('Unknown column. Check that `data` field is filled on JS side with the column name') |
213 | 215 | end
|
214 | 216 | end
|
215 | 217 |
|
216 | 218 | describe 'when unknown column' do
|
217 | 219 | before do
|
218 |
| - datatable.params[:columns] = {'0'=>{'data'=>'foo', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}} |
| 220 | + datatable.params[:columns] = { '0' => { 'data' => 'foo', 'name' => '', 'searchable' => 'true', 'orderable' => 'true', 'search' => { 'value' => 'searchvalue', 'regex' => 'false' } } } |
219 | 221 | end
|
220 | 222 |
|
221 | 223 | it 'raises error' do
|
|
0 commit comments