|
13 | 13 | before { datatable.params[:columns]['0'][:search][:value] = 'searchvalue' } |
14 | 14 |
|
15 | 15 | it 'is orderable' do |
16 | | - expect(column.orderable?).to eq(true) |
| 16 | + expect(column.orderable?).to be(true) |
17 | 17 | end |
18 | 18 |
|
19 | 19 | it 'sorts nulls last' do |
20 | | - expect(column.nulls_last?).to eq(false) |
| 20 | + expect(column.nulls_last?).to be(false) |
21 | 21 | end |
22 | 22 |
|
23 | 23 | it 'is searchable' do |
24 | | - expect(column.searchable?).to eq(true) |
| 24 | + expect(column.searchable?).to be(true) |
25 | 25 | end |
26 | 26 |
|
27 | 27 | it 'is searched' do |
28 | | - expect(column.searched?).to eq(true) |
| 28 | + expect(column.searched?).to be(true) |
29 | 29 | end |
30 | 30 |
|
31 | 31 | it 'has connected to id column' do |
|
53 | 53 |
|
54 | 54 | context 'with other ORM' do |
55 | 55 | it 'returns the corresponding model' do |
56 | | - expect(User).to receive(:respond_to?).with(:arel_table).and_return(false) |
| 56 | + allow(User).to receive(:respond_to?).with(:arel_table).and_return(false) |
57 | 57 | expect(column.table).to eq User |
58 | 58 | end |
59 | 59 | end |
|
87 | 87 | end |
88 | 88 |
|
89 | 89 | it 'does not regex' do |
90 | | - expect(column.search.regexp?).to eq false |
| 90 | + expect(column.search.regexp?).to be false |
91 | 91 | end |
92 | 92 | end |
93 | 93 |
|
|
97 | 97 | end |
98 | 98 | end |
99 | 99 |
|
100 | | - describe '#source' do |
101 | | - it 'is :like by default' do |
102 | | - expect(column.source).to eq('User.username') |
103 | | - end |
104 | | - end |
105 | | - |
106 | 100 | describe '#search_query' do |
107 | 101 | it 'bulds search query' do |
108 | 102 | expect(column.search_query.to_sql).to include('%searchvalue%') |
|
129 | 123 | end |
130 | 124 |
|
131 | 125 | describe 'unsearchable column' do |
132 | | - let(:column) { datatable.datatable.columns.find{ |c| c.data == 'email_hash' } } |
| 126 | + let(:column) { datatable.datatable.columns.find { |c| c.data == 'email_hash' } } |
133 | 127 |
|
134 | 128 | it 'is not searchable' do |
135 | | - expect(column.searchable?).to eql(false) |
| 129 | + expect(column.searchable?).to be(false) |
136 | 130 | end |
137 | 131 | end |
138 | 132 |
|
|
150 | 144 | let(:column) { datatable.datatable.columns.find { |c| c.data == 'username' } } |
151 | 145 |
|
152 | 146 | it 'is a proc' do |
153 | | - config = column.instance_variable_get('@view_column') |
| 147 | + config = column.instance_variable_get(:@view_column) |
154 | 148 | filter = config[:cond] |
155 | 149 | expect(filter).to be_a(Proc) |
156 | | - expect(filter).to receive(:call).with(column, column.formatted_value) |
| 150 | + allow(filter).to receive(:call).with(column, column.formatted_value) |
157 | 151 | column.filter |
| 152 | + expect(filter).to have_received(:call).with(column, column.formatted_value) |
158 | 153 | end |
159 | 154 | end |
160 | 155 |
|
161 | 156 | describe '#type_cast' do |
162 | 157 | let(:column) { datatable.datatable.columns.first } |
163 | 158 |
|
164 | 159 | it 'returns VARCHAR if :db_adapter is :pg' do |
165 | | - expect(datatable).to receive(:db_adapter) { :pg } |
| 160 | + allow(datatable).to receive(:db_adapter).and_return(:pg) |
166 | 161 | expect(column.send(:type_cast)).to eq('VARCHAR') |
167 | 162 | end |
168 | 163 |
|
169 | 164 | it 'returns VARCHAR if :db_adapter is :postgre' do |
170 | | - expect(datatable).to receive(:db_adapter) { :postgre } |
| 165 | + allow(datatable).to receive(:db_adapter).and_return(:postgre) |
171 | 166 | expect(column.send(:type_cast)).to eq('VARCHAR') |
172 | 167 | end |
173 | 168 |
|
174 | 169 | it 'returns VARCHAR if :db_adapter is :postgresql' do |
175 | | - expect(datatable).to receive(:db_adapter) { :postgresql } |
| 170 | + allow(datatable).to receive(:db_adapter).and_return(:postgresql) |
176 | 171 | expect(column.send(:type_cast)).to eq('VARCHAR') |
177 | 172 | end |
178 | 173 |
|
179 | 174 | it 'returns VARCHAR if :db_adapter is :postgis' do |
180 | | - expect(datatable).to receive(:db_adapter) { :postgis } |
| 175 | + allow(datatable).to receive(:db_adapter).and_return(:postgis) |
181 | 176 | expect(column.send(:type_cast)).to eq('VARCHAR') |
182 | 177 | end |
183 | 178 |
|
184 | 179 | it 'returns VARCHAR2(4000) if :db_adapter is :oracle' do |
185 | | - expect(datatable).to receive(:db_adapter) { :oracle } |
| 180 | + allow(datatable).to receive(:db_adapter).and_return(:oracle) |
186 | 181 | expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') |
187 | 182 | end |
188 | 183 |
|
189 | 184 | it 'returns VARCHAR2(4000) if :db_adapter is :oracleenhanced' do |
190 | | - expect(datatable).to receive(:db_adapter) { :oracleenhanced } |
| 185 | + allow(datatable).to receive(:db_adapter).and_return(:oracleenhanced) |
191 | 186 | expect(column.send(:type_cast)).to eq('VARCHAR2(4000)') |
192 | 187 | end |
193 | 188 |
|
194 | 189 | it 'returns CHAR if :db_adapter is :mysql2' do |
195 | | - expect(datatable).to receive(:db_adapter) { :mysql2 } |
| 190 | + allow(datatable).to receive(:db_adapter).and_return(:mysql2) |
196 | 191 | expect(column.send(:type_cast)).to eq('CHAR') |
197 | 192 | end |
198 | 193 |
|
199 | 194 | it 'returns CHAR if :db_adapter is :trilogy' do |
200 | | - expect(datatable).to receive(:db_adapter) { :trilogy } |
| 195 | + allow(datatable).to receive(:db_adapter).and_return(:trilogy) |
201 | 196 | expect(column.send(:type_cast)).to eq('CHAR') |
202 | 197 | end |
203 | 198 |
|
204 | 199 | it 'returns CHAR if :db_adapter is :mysql' do |
205 | | - expect(datatable).to receive(:db_adapter) { :mysql } |
| 200 | + allow(datatable).to receive(:db_adapter).and_return(:mysql) |
206 | 201 | expect(column.send(:type_cast)).to eq('CHAR') |
207 | 202 | end |
208 | 203 |
|
209 | 204 | it 'returns TEXT if :db_adapter is :sqlite' do |
210 | | - expect(datatable).to receive(:db_adapter) { :sqlite } |
| 205 | + allow(datatable).to receive(:db_adapter).and_return(:sqlite) |
211 | 206 | expect(column.send(:type_cast)).to eq('TEXT') |
212 | 207 | end |
213 | 208 |
|
214 | 209 | it 'returns TEXT if :db_adapter is :sqlite3' do |
215 | | - expect(datatable).to receive(:db_adapter) { :sqlite3 } |
| 210 | + allow(datatable).to receive(:db_adapter).and_return(:sqlite3) |
216 | 211 | expect(column.send(:type_cast)).to eq('TEXT') |
217 | 212 | end |
218 | 213 |
|
219 | 214 | it 'returns VARCHAR(4000) if :db_adapter is :sqlserver' do |
220 | | - expect(datatable).to receive(:db_adapter) { :sqlserver } |
| 215 | + allow(datatable).to receive(:db_adapter).and_return(:sqlserver) |
221 | 216 | expect(column.send(:type_cast)).to eq('VARCHAR(4000)') |
222 | 217 | end |
223 | 218 | end |
224 | 219 |
|
225 | 220 | describe 'when empty column' do |
226 | 221 | before { datatable.params[:columns]['0'][:data] = '' } |
227 | 222 |
|
| 223 | + let(:message) { 'Unknown column. Check that `data` field is filled on JS side with the column name' } |
| 224 | + |
228 | 225 | it 'raises error' do |
229 | | - 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') |
| 226 | + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message(message) |
230 | 227 | end |
231 | 228 | end |
232 | 229 |
|
233 | 230 | describe 'when unknown column' do |
234 | 231 | before { datatable.params[:columns]['0'][:data] = 'foo' } |
235 | 232 |
|
| 233 | + let(:message) { "Check that column 'foo' exists in view_columns" } |
| 234 | + |
236 | 235 | it 'raises error' do |
237 | | - expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Check that column 'foo' exists in view_columns") |
| 236 | + expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message(message) |
238 | 237 | end |
239 | 238 | end |
240 | 239 | end |
0 commit comments