trk_datatables 0.1.15 → 0.1.16

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: 13f7157e06eae31d336fcd8c561a1e681922f3b940677821012443fb6f4fd504
4
- data.tar.gz: 7648806094e45b2be4b2838180150284d8e05aa78764456267ac539fc7ff59d4
3
+ metadata.gz: c1aa2f1569881e6948b2c1adf114f495269fe7f95094b440e5090d16d17153ce
4
+ data.tar.gz: c976b45043a85ee2312654b4f0b02b79357f909c6cd161d0b04cf92148d310a0
5
5
  SHA512:
6
- metadata.gz: 04fde516dc05e4833d70bce836a91d6ce46aee65072065c22ab801f8878ab4665bf5af3d22b679aa6452750150328d246ee33cd900ccbac9daf246b3c95ffdea
7
- data.tar.gz: 6b72c1393c14ce9d567c349cc2a56e2d816478dfc768a39df4bf3c91f5f33347f8b4457e61bd0fd69c4b79325db8963b69c7e0b8a04a936ab037fdde8f5711b7
6
+ metadata.gz: cf9fd299b20ab006efca8570a88ac32564429daba58ec8c0e77a92cb62be660899d4e737822be3ab7f0d04176ac05f7e26286ee17765ebb37202d4496848b7bf
7
+ data.tar.gz: cfb2323199e837430283a31a12cd5998975943a5cfa269567933ca60acd5a6cfab356bb925631bafa3c1a7cee316316b1b0b8f9ce1aef602359e704e31c73f1c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trk_datatables (0.1.15)
4
+ trk_datatables (0.1.16)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -475,6 +475,30 @@ class PostsDatatable < TrkDatatables::ActiveRecord
475
475
  end
476
476
  ```
477
477
 
478
+ ## Test your datatables
479
+
480
+ Here is example how you can test
481
+
482
+ ```
483
+ # test/datatables/happ
484
+ require 'test_helper'
485
+
486
+ class PostsDatatableTest < ActiveSupport::TestCase
487
+ def sample_view_params(params = {})
488
+ OpenStruct.new(
489
+ params: params
490
+ )
491
+ end
492
+
493
+ test 'find kayaking posts' do
494
+ results = PostsDatatable.new(sample_view_params(activity_names: [activities(:kayaking).name])).all_items
495
+
496
+ assert_includes results, posts(:kayak_regata)
497
+ refute_includes results, posts(:half_marathon)
498
+ end
499
+ end
500
+ ```
501
+
478
502
  ## Debug
479
503
 
480
504
  You can override some of the methos and put byebug, for example
@@ -513,8 +537,13 @@ You can also run `bin/console` for an interactive prompt that will allow you to
513
537
 
514
538
  To install this gem onto your local machine, run `bundle exec rake install`. To
515
539
  release a new version, update the version number in
516
- `lib/trk_datatables/version.rb`, and then run `bundle exec rake release`, which
517
- will create a git tag for the version, push git commits and tags, and push the
540
+ `lib/trk_datatables/version.rb`, and then run
541
+
542
+ ```
543
+ bundle exec rake release
544
+ ```
545
+
546
+ which will create a git tag for the version, push git commits and tags, and push the
518
547
  `.gem` file to [rubygems.org](https://rubygems.org).
519
548
 
520
549
  Instead of installing you can point directly to your path
@@ -34,7 +34,7 @@ module TrkDatatables
34
34
 
35
35
  # For range you can this helper to insert BETWEEN_SEPARATOR
36
36
  def range_string(range)
37
- raise ArgumentError, "#{range} is not a Range" unless range.is_a? Range
37
+ raise Error, "#{range} is not a Range" unless range.is_a? Range
38
38
 
39
39
  from = range.min
40
40
  to = range.max
@@ -88,11 +88,13 @@ module TrkDatatables
88
88
 
89
89
  def search_all
90
90
  @params.dig(:search, :value) || ''
91
+ rescue TypeError => e
92
+ raise Error, e.message + '. Global search is in a format: { "search": { "value": "ABC" } }'
91
93
  end
92
94
 
93
95
  def as_json(all_count, filtered_items_count, data, additional = {})
94
96
  additional = {} if additional.nil?
95
- raise ArgumentError, 'additional_data_for_json needs to be a hash' unless additional.is_a? Hash
97
+ raise Error, 'additional_data_for_json needs to be a hash' unless additional.is_a? Hash
96
98
 
97
99
  draw = @params[:draw].to_i
98
100
  {
@@ -114,6 +116,8 @@ module TrkDatatables
114
116
 
115
117
  def param_get(column_index)
116
118
  @params.dig :columns, column_index.to_s, :search, :value
119
+ rescue TypeError => e
120
+ raise Error, e.message + '. Column search is in a format: { "columns": { "0": { "search": { "value": { "ABC" } } } } }'
117
121
  end
118
122
 
119
123
  def self.sample_view_params(options = {})
@@ -1,3 +1,3 @@
1
1
  module TrkDatatables
2
- VERSION = '0.1.15'.freeze
2
+ VERSION = '0.1.16'.freeze
3
3
  end
@@ -18,4 +18,9 @@ require 'active_support/core_ext/time/zones'
18
18
 
19
19
  # we need to define here since some conventions will look for definition in this file
20
20
  module TrkDatatables
21
+ class Error < StandardError
22
+ def message
23
+ "TrkDatatables: #{super}"
24
+ end
25
+ end
21
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trk_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Orlovic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-25 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport