ajax-datatables-rails 0.4.2 → 0.4.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2064c07e3bb12f0a75c6dc7836a55bc4dd867346b14a94201d44cda7bd79acb
4
- data.tar.gz: c22548d1c62ffc8a80c93dc4b5d22bd6de5fd31fc6cd97b6fc06fc4a6e7689ee
3
+ metadata.gz: 32f4790c082cfaf7a15b4463d51e7bfd1d16ddb215ad132a40572765ff79e262
4
+ data.tar.gz: cca488fce38bd4ea5dcba5112dca37fbc106c196010362ad1b2c24d231d0cf72
5
5
  SHA512:
6
- metadata.gz: da9707d5d8c8b8af19739f6286b5c3e7eef88b59482975f209ff4f6cf5296fed91ed512a5f8802e81ca6ec58e140d15c7598748cae0c75db06adf9a5c797e7d8
7
- data.tar.gz: 6bfb29fa4b4ffb222a144acfa378947edc7112e180968ddf10807ba4c63e9f77ce10fe784782273a6f119c0c9e077ec5ef987321f20e4f96de5369c6ce843365
6
+ metadata.gz: 3f50889d4584929e3a01f8895d7b3e10e8118dcfa7fe2a4188eefe38f2cdc4b3bf0b043f996a7c7d43ba7706f085dd3dddab84756f8e21d74e3f55f1a73ab083
7
+ data.tar.gz: 7b36341f278d8cf407cd21060635b37723c14f7b564e510bf5699e6665d81b8fd282220d5fe031ad97f8b67224ce3ab0dddd4131ff18287ff3576d34df1af74d
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.3 (2018-06-05)
4
+
5
+ * Add: Add `:string_eq` condition on columns filter [Issue #291](https://github.com/jbox-web/ajax-datatables-rails/issues/291)
6
+
7
+ **Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x
8
+
3
9
  ## 0.4.2 (2018-05-11)
4
10
 
5
11
  * 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)
@@ -16,9 +22,6 @@
16
22
  * Change: Add # frozen_string_literal: true pragma
17
23
  * Various improvements in internal API
18
24
 
19
- **Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x
20
-
21
-
22
25
  ## 0.4.0 (2017-05-21)
23
26
 
24
27
  **Warning:** this version is a **major break** from v0.3. The core has been rewriten to remove dependency on Kaminari (or WillPaginate).
data/README.md CHANGED
@@ -205,7 +205,7 @@ end
205
205
 
206
206
  `cond` can be :
207
207
 
208
- * `:like`, `:start_with`, `:end_with` for string or full text search
208
+ * `:like`, `:start_with`, `:end_with`, `:string_eq` for string or full text search
209
209
  * `:eq`, `:not_eq`, `:lt`, `:gt`, `:lteq`, `:gteq`, `:in` for numeric
210
210
  * `:date_range` for date range (only for Rails > 4.2.x, see [here](#daterange-search))
211
211
  * `:null_value` for nil field
@@ -57,7 +57,7 @@ module AjaxDatatablesRails
57
57
  when Proc
58
58
  filter
59
59
  when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in
60
- is_searchable_integer? ? numeric_search : empty_search
60
+ is_searchable_integer? ? raw_search(cond) : empty_search
61
61
  when :null_value
62
62
  null_value_search
63
63
  when :start_with
@@ -66,6 +66,8 @@ module AjaxDatatablesRails
66
66
  casted_column.matches("%#{formated_value}")
67
67
  when :like
68
68
  casted_column.matches("%#{formated_value}%")
69
+ when :string_eq
70
+ raw_search(:eq)
69
71
  end
70
72
  end
71
73
 
@@ -77,7 +79,7 @@ module AjaxDatatablesRails
77
79
  end
78
80
  end
79
81
 
80
- def numeric_search
82
+ def raw_search(cond)
81
83
  if custom_field?
82
84
  ::Arel::Nodes::SqlLiteral.new(field).eq(formated_value)
83
85
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AjaxDatatablesRails
4
- VERSION = '0.4.2'
4
+ VERSION = '0.4.3'
5
5
  end
@@ -360,6 +360,38 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
360
360
  end
361
361
  end
362
362
 
363
+ describe 'it can filter records with condition :like' do
364
+ let(:datatable) { DatatableCondLike.new(view) }
365
+
366
+ before(:each) do
367
+ create(:user, email: 'john@foo.com')
368
+ create(:user, email: 'mary@bar.com')
369
+ end
370
+
371
+ it 'should filter records matching' do
372
+ datatable.params[:columns]['1'][:search][:value] = 'foo'
373
+ expect(datatable.data.size).to eq 1
374
+ item = datatable.data.first
375
+ expect(item[:email]).to eq 'john@foo.com'
376
+ end
377
+ end
378
+
379
+ describe 'it can filter records with condition :string_eq' do
380
+ let(:datatable) { DatatableCondStringEq.new(view) }
381
+
382
+ before(:each) do
383
+ create(:user, email: 'john@foo.com')
384
+ create(:user, email: 'mary@bar.com')
385
+ end
386
+
387
+ it 'should filter records matching' do
388
+ datatable.params[:columns]['1'][:search][:value] = 'john@foo.com'
389
+ expect(datatable.data.size).to eq 1
390
+ item = datatable.data.first
391
+ expect(item[:email]).to eq 'john@foo.com'
392
+ end
393
+ end
394
+
363
395
  describe 'it can filter records with condition :null_value' do
364
396
  let(:datatable) { DatatableCondNullValue.new(view) }
365
397
 
@@ -10,6 +10,18 @@ class DatatableCondEndWith < ComplexDatatable
10
10
  end
11
11
  end
12
12
 
13
+ class DatatableCondLike < ComplexDatatable
14
+ def view_columns
15
+ super.deep_merge(email: { cond: :like })
16
+ end
17
+ end
18
+
19
+ class DatatableCondStringEq < ComplexDatatable
20
+ def view_columns
21
+ super.deep_merge(email: { cond: :string_eq })
22
+ end
23
+ end
24
+
13
25
  class DatatableCondNullValue < ComplexDatatable
14
26
  def view_columns
15
27
  super.deep_merge(email: { cond: :null_value })
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.2
4
+ version: 0.4.3
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-17 00:00:00.000000000 Z
12
+ date: 2018-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -308,7 +308,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
308
  version: '0'
309
309
  requirements: []
310
310
  rubyforge_project:
311
- rubygems_version: 2.7.6
311
+ rubygems_version: 2.7.7
312
312
  signing_key:
313
313
  specification_version: 4
314
314
  summary: A gem that simplifies using datatables and hundreds of records via ajax