ajax-datatables-rails 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0e67f285cdb991efbf4ab474b3a7fff772c37a546637f004bc57bf71a3402af
4
- data.tar.gz: c599a40dde96f2244e0645900d48366ea0624b16502944b5ba2256698725c707
3
+ metadata.gz: e2064c07e3bb12f0a75c6dc7836a55bc4dd867346b14a94201d44cda7bd79acb
4
+ data.tar.gz: c22548d1c62ffc8a80c93dc4b5d22bd6de5fd31fc6cd97b6fc06fc4a6e7689ee
5
5
  SHA512:
6
- metadata.gz: c33dc7544a72a23c02524bd8b1480dcf903d2a28076411e762a1af68a2a644b288f48d7aba19a25eb0774db2277807b0911b612ef023bdf04cb8e985ff85869c
7
- data.tar.gz: 67d1e16bdb6ea901614234e30690cd8a42bcc3edfd70099c85857ae4e1aa70736594cbbcfda5e0aba9459a59b08ce43a29e18ac471244880aa882cad5b49470c
6
+ metadata.gz: da9707d5d8c8b8af19739f6286b5c3e7eef88b59482975f209ff4f6cf5296fed91ed512a5f8802e81ca6ec58e140d15c7598748cae0c75db06adf9a5c797e7d8
7
+ data.tar.gz: 6bfb29fa4b4ffb222a144acfa378947edc7112e180968ddf10807ba4c63e9f77ce10fe784782273a6f119c0c9e077ec5ef987321f20e4f96de5369c6ce843365
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.2 (2018-05-11)
4
+
5
+ * Fix: Integer out of range [PR #289](https://github.com/jbox-web/ajax-datatables-rails/pull/289) from [PR #284](https://github.com/jbox-web/ajax-datatables-rails/pull/284)
6
+
3
7
  ## 0.4.1 (2018-05-06)
4
8
 
5
9
  * Fix: Restore behavior of #filter method [Comment](https://github.com/jbox-web/ajax-datatables-rails/commit/07795fd26849ff1b3b567f4ce967f722907a45be#comments)
@@ -5,6 +5,9 @@ module AjaxDatatablesRails
5
5
  class Column
6
6
  module Search
7
7
 
8
+ SMALLEST_PQ_INTEGER = -2147483648
9
+ LARGEST_PQ_INTEGER = 2147483647
10
+
8
11
  def searchable?
9
12
  @view_column.fetch(:searchable, true)
10
13
  end
@@ -54,7 +57,7 @@ module AjaxDatatablesRails
54
57
  when Proc
55
58
  filter
56
59
  when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in
57
- numeric_search
60
+ is_searchable_integer? ? numeric_search : empty_search
58
61
  when :null_value
59
62
  null_value_search
60
63
  when :start_with
@@ -82,6 +85,27 @@ module AjaxDatatablesRails
82
85
  end
83
86
  end
84
87
 
88
+ def empty_search
89
+ casted_column.matches('')
90
+ end
91
+
92
+ def is_searchable_integer?
93
+ if formated_value.is_a?(Array)
94
+ valids = formated_value.map { |v| is_integer?(v) && !is_out_of_range?(v) }
95
+ !valids.include?(false)
96
+ else
97
+ is_integer?(formated_value) && !is_out_of_range?(formated_value)
98
+ end
99
+ end
100
+
101
+ def is_out_of_range?(search_value)
102
+ Integer(search_value) > LARGEST_PQ_INTEGER || Integer(search_value) < SMALLEST_PQ_INTEGER
103
+ end
104
+
105
+ def is_integer?(string)
106
+ true if Integer(string) rescue false
107
+ end
108
+
85
109
  end
86
110
  end
87
111
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AjaxDatatablesRails
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  end
@@ -494,5 +494,49 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
494
494
  expect(item[:first_name]).to eq 'john'
495
495
  end
496
496
  end
497
+
498
+ describe 'it can filter records with condition :in with regex' do
499
+ let(:datatable) { DatatableCondInWithRegex.new(view) }
500
+
501
+ before(:each) do
502
+ create(:user, first_name: 'john', post_id: 1)
503
+ create(:user, first_name: 'mary', post_id: 2)
504
+ end
505
+
506
+ it 'should filter records matching' do
507
+ datatable.params[:columns]['4'][:search][:value] = '1|2'
508
+ datatable.params[:order]['0'] = { column: '4', dir: 'asc' }
509
+ expect(datatable.data.size).to eq 2
510
+ item = datatable.data.first
511
+ expect(item[:first_name]).to eq 'john'
512
+ end
513
+ end
514
+
515
+ describe 'Integer overflows' do
516
+ let(:datatable) { DatatableCondEq.new(view) }
517
+ let(:largest_postgresql_integer_value) { 2147483647 }
518
+ let(:smallest_postgresql_integer_value) { -2147483648 }
519
+
520
+ before(:each) do
521
+ create(:user, first_name: 'john', post_id: 1)
522
+ create(:user, first_name: 'mary', post_id: 2)
523
+ create(:user, first_name: 'phil', post_id: largest_postgresql_integer_value)
524
+ end
525
+
526
+ it 'Returns an empty result if input value is too large' do
527
+ datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value + 1
528
+ expect(datatable.data.size).to eq 0
529
+ end
530
+
531
+ it 'Returns an empty result if input value is too small' do
532
+ datatable.params[:columns]['4'][:search][:value] = smallest_postgresql_integer_value - 1
533
+ expect(datatable.data.size).to eq 0
534
+ end
535
+
536
+ it 'returns the matching user' do
537
+ datatable.params[:columns]['4'][:search][:value] = largest_postgresql_integer_value
538
+ expect(datatable.data.size).to eq 1
539
+ end
540
+ end
497
541
  end
498
542
  end
@@ -39,3 +39,13 @@ class DatatableCondIn < ComplexDatatable
39
39
  super.deep_merge(post_id: { cond: :in })
40
40
  end
41
41
  end
42
+
43
+ class DatatableCondInWithRegex < DatatableCondIn
44
+ def view_columns
45
+ super.deep_merge(post_id: { cond: :in, use_regex: false, orderable: true, formater: ->(str) { cast_regex_value(str) } })
46
+ end
47
+
48
+ def cast_regex_value(value)
49
+ value.split('|').map(&:to_i)
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajax-datatables-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Quenneville
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-05-06 00:00:00.000000000 Z
12
+ date: 2018-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties