ajax-datatables-rails 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +15 -15
  4. data/bin/bundle +114 -0
  5. data/doc/migrate.md +1 -1
  6. data/lib/ajax-datatables-rails/base.rb +1 -1
  7. data/lib/ajax-datatables-rails/datatable/column/search.rb +7 -3
  8. data/lib/ajax-datatables-rails/datatable/datatable.rb +0 -1
  9. data/lib/ajax-datatables-rails/version.rb +1 -1
  10. data/spec/ajax-datatables-rails/base_spec.rb +39 -19
  11. data/spec/ajax-datatables-rails/datatable/column_spec.rb +30 -33
  12. data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +11 -9
  13. data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +4 -2
  14. data/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +4 -2
  15. data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +61 -94
  16. data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +4 -2
  17. data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +5 -3
  18. data/spec/factories/user.rb +3 -1
  19. data/spec/spec_helper.rb +27 -11
  20. data/spec/support/datatables/complex_datatable.rb +2 -0
  21. data/spec/support/datatables/complex_datatable_array.rb +2 -0
  22. data/spec/support/datatables/datatable_cond_date.rb +2 -0
  23. data/spec/support/datatables/datatable_cond_numeric.rb +2 -0
  24. data/spec/support/datatables/datatable_cond_proc.rb +2 -0
  25. data/spec/support/datatables/datatable_cond_string.rb +4 -2
  26. data/spec/support/datatables/datatable_cond_unknown.rb +2 -0
  27. data/spec/support/datatables/datatable_order_nulls_last.rb +2 -0
  28. data/spec/support/helpers/params.rb +7 -5
  29. data/spec/support/models/user.rb +2 -0
  30. data/spec/support/schema.rb +3 -1
  31. metadata +4 -4
  32. data/spec/ajax-datatables-rails/orm/active_record_spec.rb +0 -24
@@ -1,23 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe AjaxDatatablesRails::Datatable::Datatable do
5
+ RSpec.describe AjaxDatatablesRails::Datatable::Datatable do
4
6
 
5
7
  let(:datatable) { ComplexDatatable.new(sample_params).datatable }
6
8
  let(:datatable_json) { ComplexDatatable.new(sample_params_json).datatable }
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'}] }
9
+ let(:order_option) { { '0' => { 'column' => '0', 'dir' => 'asc' }, '1' => { 'column' => '1', 'dir' => 'desc' } } }
10
+ let(:order_option_json) { [{ 'column' => '0', 'dir' => 'asc' }, { 'column' => '1', 'dir' => 'desc' }] }
9
11
 
10
12
  shared_examples 'order methods' do
11
- it 'should be orderable' do
13
+ it 'is orderable' do
12
14
  expect(datatable.orderable?).to eq(true)
13
15
  end
14
16
 
15
- it 'should not be orderable' do
17
+ it 'is not orderable' do
16
18
  datatable.options[:order] = nil
17
19
  expect(datatable.orderable?).to eq(false)
18
20
  end
19
21
 
20
- it 'should have 2 orderable columns' do
22
+ it 'has 2 orderable columns' do
21
23
  datatable.options[:order] = order_option
22
24
  expect(datatable.orders.count).to eq(2)
23
25
  end
@@ -38,7 +40,7 @@ describe AjaxDatatablesRails::Datatable::Datatable do
38
40
  end
39
41
 
40
42
  shared_examples 'columns methods' do
41
- it 'should have 4 columns' do
43
+ it 'has 4 columns' do
42
44
  expect(datatable.columns.count).to eq(6)
43
45
  end
44
46
 
@@ -60,12 +62,12 @@ describe AjaxDatatablesRails::Datatable::Datatable do
60
62
  end
61
63
 
62
64
  describe 'search methods' do
63
- it 'should be searchable' do
65
+ it 'is searchable' do
64
66
  datatable.options[:search][:value] = 'atom'
65
67
  expect(datatable.searchable?).to eq(true)
66
68
  end
67
69
 
68
- it 'should not be searchable' do
70
+ it 'is not searchable' do
69
71
  datatable.options[:search][:value] = nil
70
72
  expect(datatable.searchable?).to eq(false)
71
73
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe AjaxDatatablesRails::Datatable::SimpleOrder do
5
+ RSpec.describe AjaxDatatablesRails::Datatable::SimpleOrder do
4
6
 
5
7
  let(:parent) { ComplexDatatable.new(sample_params) }
6
8
  let(:datatable) { parent.datatable }
7
- let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'column' => '1', 'dir' => 'desc'}) }
9
+ let(:options) { ActiveSupport::HashWithIndifferentAccess.new({ 'column' => '1', 'dir' => 'desc' }) }
8
10
  let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(datatable, options) }
9
11
 
10
12
  describe 'option methods' do
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe AjaxDatatablesRails::Datatable::SimpleSearch do
5
+ RSpec.describe AjaxDatatablesRails::Datatable::SimpleSearch do
4
6
 
5
- let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'value' => 'search value', 'regex' => 'true'}) }
7
+ let(:options) { ActiveSupport::HashWithIndifferentAccess.new({ 'value' => 'search value', 'regex' => 'true' }) }
6
8
  let(:simple_search) { AjaxDatatablesRails::Datatable::SimpleSearch.new(options) }
7
9
 
8
10
  describe 'option methods' do
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe AjaxDatatablesRails::ORM::ActiveRecord do
5
+ RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do
4
6
 
5
7
  let(:datatable) { ComplexDatatable.new(sample_params) }
6
8
  let(:records) { User.all }
7
9
 
8
10
  describe '#filter_records' do
9
11
  it 'requires a records collection as argument' do
10
- expect { datatable.filter_records() }.to raise_error(ArgumentError)
12
+ expect { datatable.filter_records }.to raise_error(ArgumentError)
11
13
  end
12
14
 
13
15
  it 'performs a simple search first' do
@@ -24,14 +26,14 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
24
26
  end
25
27
 
26
28
  describe '#build_conditions' do
27
- before(:each) do
29
+ before do
28
30
  create(:user, username: 'johndoe', email: 'johndoe@example.com')
29
31
  create(:user, username: 'msmith', email: 'mary.smith@example.com')
30
32
  create(:user, username: 'hsmith', email: 'henry.smith@example.net')
31
33
  end
32
34
 
33
35
  context 'with column and global search' do
34
- before(:each) do
36
+ before do
35
37
  datatable.params[:search] = { value: 'example.com', regex: 'false' }
36
38
  datatable.params[:columns]['0'][:search][:value] = 'smith'
37
39
  end
@@ -47,7 +49,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
47
49
  end
48
50
 
49
51
  describe '#build_conditions_for_datatable' do
50
- before(:each) do
52
+ before do
51
53
  create(:user, username: 'johndoe', email: 'johndoe@example.com')
52
54
  create(:user, username: 'msmith', email: 'mary.smith@example.com')
53
55
  end
@@ -66,12 +68,12 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
66
68
  end
67
69
 
68
70
  context 'when none of columns are connected' do
69
- before(:each) do
71
+ before do
70
72
  allow(datatable).to receive(:searchable_columns) { [] }
71
73
  end
72
74
 
73
75
  context 'when search value is a string' do
74
- before(:each) do
76
+ before do
75
77
  datatable.params[:search] = { value: 'msmith' }
76
78
  end
77
79
 
@@ -87,7 +89,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
87
89
  end
88
90
 
89
91
  context 'when search value is space-separated string' do
90
- before(:each) do
92
+ before do
91
93
  datatable.params[:search] = { value: 'foo bar' }
92
94
  end
93
95
 
@@ -105,7 +107,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
105
107
 
106
108
  context 'with search query' do
107
109
  context 'when search value is a string' do
108
- before(:each) do
110
+ before do
109
111
  datatable.params[:search] = { value: 'john', regex: 'false' }
110
112
  end
111
113
 
@@ -118,7 +120,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
118
120
  end
119
121
 
120
122
  context 'when search value is space-separated string' do
121
- before(:each) do
123
+ before do
122
124
  datatable.params[:search] = { value: 'john doe', regex: 'false' }
123
125
  end
124
126
 
@@ -134,7 +136,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
134
136
  context 'when column.search_query returns nil' do
135
137
  let(:datatable) { DatatableCondUnknown.new(sample_params) }
136
138
 
137
- before(:each) do
139
+ before do
138
140
  datatable.params[:search] = { value: 'john doe', regex: 'false' }
139
141
  end
140
142
 
@@ -150,7 +152,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
150
152
  end
151
153
 
152
154
  describe '#build_conditions_for_selected_columns' do
153
- before(:each) do
155
+ before do
154
156
  create(:user, username: 'johndoe', email: 'johndoe@example.com')
155
157
  create(:user, username: 'msmith', email: 'mary.smith@example.com')
156
158
  end
@@ -209,7 +211,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
209
211
  end
210
212
 
211
213
  context 'with search values in columns' do
212
- before(:each) do
214
+ before do
213
215
  datatable.params[:columns]['0'][:search][:value] = 'doe'
214
216
  end
215
217
 
@@ -227,13 +229,13 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
227
229
  describe 'it can filter records with condition :date_range' do
228
230
  let(:datatable) { DatatableCondDate.new(sample_params) }
229
231
 
230
- before(:each) do
232
+ before do
231
233
  create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000')
232
234
  create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'Smith', created_at: '01/02/2000')
233
235
  end
234
236
 
235
237
  context 'when range is empty' do
236
- it 'should not filter records' do
238
+ it 'does not filter records' do
237
239
  datatable.params[:columns]['5'][:search][:value] = '-'
238
240
  expect(datatable.data.size).to eq 2
239
241
  item = datatable.data.first
@@ -242,21 +244,21 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
242
244
  end
243
245
 
244
246
  context 'when start date is filled' do
245
- it 'should filter records created after this date' do
247
+ it 'filters records created after this date' do
246
248
  datatable.params[:columns]['5'][:search][:value] = '31/12/1999-'
247
249
  expect(datatable.data.size).to eq 2
248
250
  end
249
251
  end
250
252
 
251
253
  context 'when end date is filled' do
252
- it 'should filter records created before this date' do
254
+ it 'filters records created before this date' do
253
255
  datatable.params[:columns]['5'][:search][:value] = '-31/12/1999'
254
256
  expect(datatable.data.size).to eq 0
255
257
  end
256
258
  end
257
259
 
258
260
  context 'when both date are filled' do
259
- it 'should filter records created between the range' do
261
+ it 'filters records created between the range' do
260
262
  datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000'
261
263
  expect(datatable.data.size).to eq 1
262
264
  end
@@ -264,7 +266,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
264
266
 
265
267
  context 'when another filter is active' do
266
268
  context 'when range is empty' do
267
- it 'should filter records' do
269
+ it 'filters records' do
268
270
  datatable.params[:columns]['0'][:search][:value] = 'doe'
269
271
  datatable.params[:columns]['5'][:search][:value] = '-'
270
272
  expect(datatable.data.size).to eq 1
@@ -274,7 +276,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
274
276
  end
275
277
 
276
278
  context 'when start date is filled' do
277
- it 'should filter records' do
279
+ it 'filters records' do
278
280
  datatable.params[:columns]['0'][:search][:value] = 'doe'
279
281
  datatable.params[:columns]['5'][:search][:value] = '01/12/1999-'
280
282
  expect(datatable.data.size).to eq 1
@@ -284,7 +286,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
284
286
  end
285
287
 
286
288
  context 'when end date is filled' do
287
- it 'should filter records' do
289
+ it 'filters records' do
288
290
  datatable.params[:columns]['0'][:search][:value] = 'doe'
289
291
  datatable.params[:columns]['5'][:search][:value] = '-15/01/2000'
290
292
  expect(datatable.data.size).to eq 1
@@ -294,7 +296,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
294
296
  end
295
297
 
296
298
  context 'when both date are filled' do
297
- it 'should filter records' do
299
+ it 'filters records' do
298
300
  datatable.params[:columns]['0'][:search][:value] = 'doe'
299
301
  datatable.params[:columns]['5'][:search][:value] = '01/12/1999-15/01/2000'
300
302
  expect(datatable.data.size).to eq 1
@@ -307,15 +309,15 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
307
309
  end
308
310
 
309
311
  context 'numeric condition' do
312
+ before do
313
+ create(:user, first_name: 'john', post_id: 1)
314
+ create(:user, first_name: 'mary', post_id: 2)
315
+ end
316
+
310
317
  describe 'it can filter records with condition :eq' do
311
318
  let(:datatable) { DatatableCondEq.new(sample_params) }
312
319
 
313
- before(:each) do
314
- create(:user, first_name: 'john', post_id: 1)
315
- create(:user, first_name: 'mary', post_id: 2)
316
- end
317
-
318
- it 'should filter records matching' do
320
+ it 'filters records matching' do
319
321
  datatable.params[:columns]['4'][:search][:value] = 1
320
322
  expect(datatable.data.size).to eq 1
321
323
  item = datatable.data.first
@@ -326,12 +328,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
326
328
  describe 'it can filter records with condition :not_eq' do
327
329
  let(:datatable) { DatatableCondNotEq.new(sample_params) }
328
330
 
329
- before(:each) do
330
- create(:user, first_name: 'john', post_id: 1)
331
- create(:user, first_name: 'mary', post_id: 2)
332
- end
333
-
334
- it 'should filter records matching' do
331
+ it 'filters records matching' do
335
332
  datatable.params[:columns]['4'][:search][:value] = 1
336
333
  expect(datatable.data.size).to eq 1
337
334
  item = datatable.data.first
@@ -342,12 +339,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
342
339
  describe 'it can filter records with condition :lt' do
343
340
  let(:datatable) { DatatableCondLt.new(sample_params) }
344
341
 
345
- before(:each) do
346
- create(:user, first_name: 'john', post_id: 1)
347
- create(:user, first_name: 'mary', post_id: 2)
348
- end
349
-
350
- it 'should filter records matching' do
342
+ it 'filters records matching' do
351
343
  datatable.params[:columns]['4'][:search][:value] = 2
352
344
  expect(datatable.data.size).to eq 1
353
345
  item = datatable.data.first
@@ -358,12 +350,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
358
350
  describe 'it can filter records with condition :gt' do
359
351
  let(:datatable) { DatatableCondGt.new(sample_params) }
360
352
 
361
- before(:each) do
362
- create(:user, first_name: 'john', post_id: 1)
363
- create(:user, first_name: 'mary', post_id: 2)
364
- end
365
-
366
- it 'should filter records matching' do
353
+ it 'filters records matching' do
367
354
  datatable.params[:columns]['4'][:search][:value] = 1
368
355
  expect(datatable.data.size).to eq 1
369
356
  item = datatable.data.first
@@ -374,12 +361,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
374
361
  describe 'it can filter records with condition :lteq' do
375
362
  let(:datatable) { DatatableCondLteq.new(sample_params) }
376
363
 
377
- before(:each) do
378
- create(:user, first_name: 'john', post_id: 1)
379
- create(:user, first_name: 'mary', post_id: 2)
380
- end
381
-
382
- it 'should filter records matching' do
364
+ it 'filters records matching' do
383
365
  datatable.params[:columns]['4'][:search][:value] = 2
384
366
  expect(datatable.data.size).to eq 2
385
367
  end
@@ -388,12 +370,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
388
370
  describe 'it can filter records with condition :gteq' do
389
371
  let(:datatable) { DatatableCondGteq.new(sample_params) }
390
372
 
391
- before(:each) do
392
- create(:user, first_name: 'john', post_id: 1)
393
- create(:user, first_name: 'mary', post_id: 2)
394
- end
395
-
396
- it 'should filter records matching' do
373
+ it 'filters records matching' do
397
374
  datatable.params[:columns]['4'][:search][:value] = 1
398
375
  expect(datatable.data.size).to eq 2
399
376
  end
@@ -402,12 +379,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
402
379
  describe 'it can filter records with condition :in' do
403
380
  let(:datatable) { DatatableCondIn.new(sample_params) }
404
381
 
405
- before(:each) do
406
- create(:user, first_name: 'john', post_id: 1)
407
- create(:user, first_name: 'mary', post_id: 2)
408
- end
409
-
410
- it 'should filter records matching' do
382
+ it 'filters records matching' do
411
383
  datatable.params[:columns]['4'][:search][:value] = [1]
412
384
  expect(datatable.data.size).to eq 1
413
385
  item = datatable.data.first
@@ -418,12 +390,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
418
390
  describe 'it can filter records with condition :in with regex' do
419
391
  let(:datatable) { DatatableCondInWithRegex.new(sample_params) }
420
392
 
421
- before(:each) do
422
- create(:user, first_name: 'john', post_id: 1)
423
- create(:user, first_name: 'mary', post_id: 2)
424
- end
425
-
426
- it 'should filter records matching' do
393
+ it 'filters records matching' do
427
394
  datatable.params[:columns]['4'][:search][:value] = '1|2'
428
395
  datatable.params[:order]['0'] = { column: '4', dir: 'asc' }
429
396
  expect(datatable.data.size).to eq 2
@@ -434,10 +401,10 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
434
401
 
435
402
  describe 'Integer overflows' do
436
403
  let(:datatable) { DatatableCondEq.new(sample_params) }
437
- let(:largest_postgresql_integer_value) { 2147483647 }
438
- let(:smallest_postgresql_integer_value) { -2147483648 }
404
+ let(:largest_postgresql_integer_value) { 2_147_483_647 }
405
+ let(:smallest_postgresql_integer_value) { -2_147_483_648 }
439
406
 
440
- before(:each) do
407
+ before do
441
408
  create(:user, first_name: 'john', post_id: 1)
442
409
  create(:user, first_name: 'mary', post_id: 2)
443
410
  create(:user, first_name: 'phil', post_id: largest_postgresql_integer_value)
@@ -464,13 +431,13 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
464
431
  describe 'it can filter records with lambda/proc condition' do
465
432
  let(:datatable) { DatatableCondProc.new(sample_params) }
466
433
 
467
- before(:each) do
434
+ before do
468
435
  create(:user, username: 'johndoe', email: 'johndoe@example.com')
469
436
  create(:user, username: 'johndie', email: 'johndie@example.com')
470
437
  create(:user, username: 'msmith', email: 'mary.smith@example.com')
471
438
  end
472
439
 
473
- it 'should filter records matching' do
440
+ it 'filters records matching' do
474
441
  datatable.params[:columns]['0'][:search][:value] = 'john'
475
442
  expect(datatable.data.size).to eq 2
476
443
  item = datatable.data.first
@@ -483,12 +450,12 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
483
450
  describe 'it can filter records with condition :start_with' do
484
451
  let(:datatable) { DatatableCondStartWith.new(sample_params) }
485
452
 
486
- before(:each) do
453
+ before do
487
454
  create(:user, first_name: 'John')
488
455
  create(:user, first_name: 'Mary')
489
456
  end
490
457
 
491
- it 'should filter records matching' do
458
+ it 'filters records matching' do
492
459
  datatable.params[:columns]['2'][:search][:value] = 'Jo'
493
460
  expect(datatable.data.size).to eq 1
494
461
  item = datatable.data.first
@@ -499,14 +466,14 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
499
466
  describe 'it can filter records with condition :end_with' do
500
467
  let(:datatable) { DatatableCondEndWith.new(sample_params) }
501
468
 
502
- before(:each) do
469
+ before do
503
470
  create(:user, last_name: 'JOHN')
504
471
  create(:user, last_name: 'MARY')
505
472
  end
506
473
 
507
474
  if ENV['DB_ADAPTER'] == 'oracle_enhanced'
508
475
  context 'when db_adapter is oracleenhanced' do
509
- it 'should filter records matching' do
476
+ it 'filters records matching' do
510
477
  datatable.params[:columns]['3'][:search][:value] = 'RY'
511
478
  expect(datatable.data.size).to eq 1
512
479
  item = datatable.data.first
@@ -514,7 +481,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
514
481
  end
515
482
  end
516
483
  else
517
- it 'should filter records matching' do
484
+ it 'filters records matching' do
518
485
  datatable.params[:columns]['3'][:search][:value] = 'ry'
519
486
  expect(datatable.data.size).to eq 1
520
487
  item = datatable.data.first
@@ -526,12 +493,12 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
526
493
  describe 'it can filter records with condition :like' do
527
494
  let(:datatable) { DatatableCondLike.new(sample_params) }
528
495
 
529
- before(:each) do
496
+ before do
530
497
  create(:user, email: 'john@foo.com')
531
498
  create(:user, email: 'mary@bar.com')
532
499
  end
533
500
 
534
- it 'should filter records matching' do
501
+ it 'filters records matching' do
535
502
  datatable.params[:columns]['1'][:search][:value] = 'foo'
536
503
  expect(datatable.data.size).to eq 1
537
504
  item = datatable.data.first
@@ -542,12 +509,12 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
542
509
  describe 'it can filter records with condition :string_eq' do
543
510
  let(:datatable) { DatatableCondStringEq.new(sample_params) }
544
511
 
545
- before(:each) do
512
+ before do
546
513
  create(:user, email: 'john@foo.com')
547
514
  create(:user, email: 'mary@bar.com')
548
515
  end
549
516
 
550
- it 'should filter records matching' do
517
+ it 'filters records matching' do
551
518
  datatable.params[:columns]['1'][:search][:value] = 'john@foo.com'
552
519
  expect(datatable.data.size).to eq 1
553
520
  item = datatable.data.first
@@ -558,20 +525,20 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
558
525
  describe 'it can filter records with condition :string_in' do
559
526
  let(:datatable) { DatatableCondStringIn.new(sample_params) }
560
527
 
561
- before(:each) do
528
+ before do
562
529
  create(:user, email: 'john@foo.com')
563
530
  create(:user, email: 'mary@bar.com')
564
531
  create(:user, email: 'henry@baz.com')
565
532
  end
566
533
 
567
- it 'should filter records matching' do
534
+ it 'filters records matching' do
568
535
  datatable.params[:columns]['1'][:search][:value] = 'john@foo.com'
569
536
  expect(datatable.data.size).to eq 1
570
537
  item = datatable.data.first
571
538
  expect(item[:email]).to eq 'john@foo.com'
572
539
  end
573
540
 
574
- it 'should filter records matching with multiple' do
541
+ it 'filters records matching with multiple' do
575
542
  datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry@baz.com'
576
543
  expect(datatable.data.size).to eq 2
577
544
  items = datatable.data.sort_by { |h| h[:email] }
@@ -581,7 +548,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
581
548
  expect(item_last[:email]).to eq 'john@foo.com'
582
549
  end
583
550
 
584
- it 'should filter records matching with multiple contains not found' do
551
+ it 'filters records matching with multiple contains not found' do
585
552
  datatable.params[:columns]['1'][:search][:value] = 'john@foo.com|henry_not@baz.com'
586
553
  expect(datatable.data.size).to eq 1
587
554
  item = datatable.data.first
@@ -592,13 +559,13 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
592
559
  describe 'it can filter records with condition :null_value' do
593
560
  let(:datatable) { DatatableCondNullValue.new(sample_params) }
594
561
 
595
- before(:each) do
562
+ before do
596
563
  create(:user, first_name: 'john', email: 'foo@bar.com')
597
564
  create(:user, first_name: 'mary', email: nil)
598
565
  end
599
566
 
600
567
  context 'when condition is NULL' do
601
- it 'should filter records matching' do
568
+ it 'filters records matching' do
602
569
  datatable.params[:columns]['1'][:search][:value] = 'NULL'
603
570
  expect(datatable.data.size).to eq 1
604
571
  item = datatable.data.first
@@ -607,7 +574,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
607
574
  end
608
575
 
609
576
  context 'when condition is !NULL' do
610
- it 'should filter records matching' do
577
+ it 'filters records matching' do
611
578
  datatable.params[:columns]['1'][:search][:value] = '!NULL'
612
579
  expect(datatable.data.size).to eq 1
613
580
  item = datatable.data.first
@@ -620,11 +587,11 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
620
587
  context 'unknown condition' do
621
588
  let(:datatable) { DatatableCondUnknown.new(sample_params) }
622
589
 
623
- before(:each) do
590
+ before do
624
591
  datatable.params[:search] = { value: 'john doe', regex: 'false' }
625
592
  end
626
593
 
627
- it 'should raise error' do
594
+ it 'raises error' do
628
595
  expect {
629
596
  datatable.data.size
630
597
  }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchCondition).with_message('foo')
@@ -635,7 +602,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
635
602
  describe 'formatter option' do
636
603
  let(:datatable) { DatatableWithFormater.new(sample_params) }
637
604
 
638
- before(:each) do
605
+ before do
639
606
  create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'DOE')
640
607
  create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'SMITH')
641
608
  datatable.params[:columns]['3'][:search][:value] = 'doe'