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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +15 -15
- data/bin/bundle +114 -0
- data/doc/migrate.md +1 -1
- data/lib/ajax-datatables-rails/base.rb +1 -1
- data/lib/ajax-datatables-rails/datatable/column/search.rb +7 -3
- data/lib/ajax-datatables-rails/datatable/datatable.rb +0 -1
- data/lib/ajax-datatables-rails/version.rb +1 -1
- data/spec/ajax-datatables-rails/base_spec.rb +39 -19
- data/spec/ajax-datatables-rails/datatable/column_spec.rb +30 -33
- data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +11 -9
- data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +4 -2
- data/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +4 -2
- data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +61 -94
- data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +4 -2
- data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +5 -3
- data/spec/factories/user.rb +3 -1
- data/spec/spec_helper.rb +27 -11
- data/spec/support/datatables/complex_datatable.rb +2 -0
- data/spec/support/datatables/complex_datatable_array.rb +2 -0
- data/spec/support/datatables/datatable_cond_date.rb +2 -0
- data/spec/support/datatables/datatable_cond_numeric.rb +2 -0
- data/spec/support/datatables/datatable_cond_proc.rb +2 -0
- data/spec/support/datatables/datatable_cond_string.rb +4 -2
- data/spec/support/datatables/datatable_cond_unknown.rb +2 -0
- data/spec/support/datatables/datatable_order_nulls_last.rb +2 -0
- data/spec/support/helpers/params.rb +7 -5
- data/spec/support/models/user.rb +2 -0
- data/spec/support/schema.rb +3 -1
- metadata +4 -4
- data/spec/ajax-datatables-rails/orm/active_record_spec.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c458882fe0c2ff86e0b262ccdc9e37af67c348941f902e29bee7a9ec7b1ad9f0
|
4
|
+
data.tar.gz: 9fe38de08324f1f281f5a7c24d3e0c782c71bc741a23ae301952c0ef7bfcbb09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 943655268357523c6594845e708f41fbe515284736b1c96d6150514b6c39478d563719c4051c0c3568942e138c1166ab2193cec5585742c1640242a7adbdd381
|
7
|
+
data.tar.gz: 6507a0827be528e61dfb07f905b4016d0d65543b19b3becf8d557884890fa88dbdefd815441f0b6f4cc4c784b24ebb58924f0b69357576295138af67cdf7ca78
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.3.1 (2021-02-09)
|
4
|
+
|
5
|
+
* Fix rare case error `uninitialized constant AjaxDatatablesRails::ActiveRecord::Base` (merge: [#379](https://github.com/jbox-web/ajax-datatables-rails/pull/379))
|
6
|
+
|
3
7
|
## 1.3.0 (2021-01-04)
|
4
8
|
|
5
9
|
* Drop support of Rails 5.0.x and 5.1.x
|
data/README.md
CHANGED
@@ -532,13 +532,13 @@ available in our datatable to search and sort by.
|
|
532
532
|
|
533
533
|
def view_columns
|
534
534
|
@view_columns ||= {
|
535
|
-
first_name: 'User.first_name',
|
536
|
-
last_name: 'User.last_name',
|
537
|
-
order_number: 'PurchaseOrder.number',
|
538
|
-
order_created_at: 'PurchaseOrder.created_at',
|
539
|
-
quantity: 'Purchase::LineItem.quantity',
|
540
|
-
unit_price: 'Purchase::LineItem.unit_price',
|
541
|
-
item_total: 'Purchase::LineItem.item_total'
|
535
|
+
first_name: { source: 'User.first_name' },
|
536
|
+
last_name: { source: 'User.last_name' },
|
537
|
+
order_number: { source: 'PurchaseOrder.number' },
|
538
|
+
order_created_at: { source: 'PurchaseOrder.created_at' },
|
539
|
+
quantity: { source: 'Purchase::LineItem.quantity' },
|
540
|
+
unit_price: { source: 'Purchase::LineItem.unit_price' },
|
541
|
+
item_total: { source: 'Purchase::LineItem.item_total }'
|
542
542
|
}
|
543
543
|
end
|
544
544
|
```
|
@@ -570,14 +570,14 @@ The related definition would be :
|
|
570
570
|
```ruby
|
571
571
|
def view_columns
|
572
572
|
@view_columns ||= {
|
573
|
-
course_type: 'CourseType.name',
|
574
|
-
course_name: 'Course.name',
|
575
|
-
contact_name: 'Contact.full_name',
|
576
|
-
competency_type: 'CompetencyType.name',
|
577
|
-
event_title: 'Event.title',
|
578
|
-
event_start: 'Event.event_start',
|
579
|
-
event_end: 'Event.event_end',
|
580
|
-
event_status: 'Event.status',
|
573
|
+
course_type: { source: 'CourseType.name' },
|
574
|
+
course_name: { source: 'Course.name' },
|
575
|
+
contact_name: { source: 'Contact.full_name' },
|
576
|
+
competency_type: { source: 'CompetencyType.name' },
|
577
|
+
event_title: { source: 'Event.title' },
|
578
|
+
event_start: { source: 'Event.event_start' },
|
579
|
+
event_end: { source: 'Event.event_end' },
|
580
|
+
event_status: { source: 'Event.status' },
|
581
581
|
}
|
582
582
|
end
|
583
583
|
|
data/bin/bundle
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
27
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||=
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version
|
67
|
+
end
|
68
|
+
|
69
|
+
def bundler_requirement
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
71
|
+
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
73
|
+
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
75
|
+
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
77
|
+
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
79
|
+
|
80
|
+
requirement
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_bundler!
|
84
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
85
|
+
|
86
|
+
activate_bundler
|
87
|
+
end
|
88
|
+
|
89
|
+
def activate_bundler
|
90
|
+
gem_error = activation_error_handling do
|
91
|
+
gem "bundler", bundler_requirement
|
92
|
+
end
|
93
|
+
return if gem_error.nil?
|
94
|
+
require_error = activation_error_handling do
|
95
|
+
require "bundler/version"
|
96
|
+
end
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
99
|
+
exit 42
|
100
|
+
end
|
101
|
+
|
102
|
+
def activation_error_handling
|
103
|
+
yield
|
104
|
+
nil
|
105
|
+
rescue StandardError, LoadError => e
|
106
|
+
e
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
m.load_bundler!
|
111
|
+
|
112
|
+
if m.invoked_as_script?
|
113
|
+
load Gem.bin_path("bundler", "bundle")
|
114
|
+
end
|
data/doc/migrate.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module AjaxDatatablesRails
|
4
4
|
class Base
|
5
5
|
|
6
|
-
class_attribute :db_adapter, default: ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
6
|
+
class_attribute :db_adapter, default: ::ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
7
7
|
class_attribute :nulls_last, default: false
|
8
8
|
|
9
9
|
attr_reader :params, :options, :datatable
|
@@ -62,11 +62,11 @@ module AjaxDatatablesRails
|
|
62
62
|
when :eq, :not_eq, :lt, :gt, :lteq, :gteq, :in
|
63
63
|
searchable_integer? ? raw_search(cond) : empty_search
|
64
64
|
when :start_with
|
65
|
-
|
65
|
+
text_search("#{formatted_value}%")
|
66
66
|
when :end_with
|
67
|
-
|
67
|
+
text_search("%#{formatted_value}")
|
68
68
|
when :like
|
69
|
-
|
69
|
+
text_search("%#{formatted_value}%")
|
70
70
|
when :string_eq
|
71
71
|
raw_search(:eq)
|
72
72
|
when :string_in
|
@@ -95,6 +95,10 @@ module AjaxDatatablesRails
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
def text_search(value)
|
99
|
+
casted_column.matches(value)
|
100
|
+
end
|
101
|
+
|
98
102
|
def empty_search
|
99
103
|
casted_column.matches(EMPTY_VALUE)
|
100
104
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AjaxDatatablesRails::Base do
|
5
|
+
RSpec.describe AjaxDatatablesRails::Base do
|
4
6
|
|
5
7
|
describe 'an instance' do
|
6
8
|
it 'requires a hash of params' do
|
@@ -15,9 +17,11 @@ describe AjaxDatatablesRails::Base do
|
|
15
17
|
|
16
18
|
describe 'User API' do
|
17
19
|
describe '#view_columns' do
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
context 'when method is not defined by the user' do
|
21
|
+
it 'raises an error' do
|
22
|
+
datatable = described_class.new(sample_params)
|
23
|
+
expect { datatable.view_columns }.to raise_error NotImplementedError
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
context 'child class implements view_columns' do
|
@@ -29,22 +33,26 @@ describe AjaxDatatablesRails::Base do
|
|
29
33
|
end
|
30
34
|
|
31
35
|
describe '#get_raw_records' do
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
context 'when method is not defined by the user' do
|
37
|
+
it 'raises an error' do
|
38
|
+
datatable = described_class.new(sample_params)
|
39
|
+
expect { datatable.get_raw_records }.to raise_error NotImplementedError
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
describe '#data' do
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
context 'when method is not defined by the user' do
|
46
|
+
it 'raises an error' do
|
47
|
+
datatable = described_class.new(sample_params)
|
48
|
+
expect { datatable.data }.to raise_error NotImplementedError
|
49
|
+
end
|
42
50
|
end
|
43
51
|
|
44
52
|
context 'when data is defined as a hash' do
|
45
53
|
let(:datatable) { ComplexDatatable.new(sample_params) }
|
46
54
|
|
47
|
-
it '
|
55
|
+
it 'returns an array of hashes' do
|
48
56
|
create_list(:user, 5)
|
49
57
|
expect(datatable.data).to be_a(Array)
|
50
58
|
expect(datatable.data.size).to eq 5
|
@@ -52,7 +60,7 @@ describe AjaxDatatablesRails::Base do
|
|
52
60
|
expect(item).to be_a(Hash)
|
53
61
|
end
|
54
62
|
|
55
|
-
it '
|
63
|
+
it 'htmls escape data' do
|
56
64
|
create(:user, first_name: 'Name "><img src=x onerror=alert("first_name")>', last_name: 'Name "><img src=x onerror=alert("last_name")>')
|
57
65
|
data = datatable.send(:sanitize_data, datatable.data)
|
58
66
|
item = data.first
|
@@ -64,7 +72,7 @@ describe AjaxDatatablesRails::Base do
|
|
64
72
|
context 'when data is defined as a array' do
|
65
73
|
let(:datatable) { ComplexDatatableArray.new(sample_params) }
|
66
74
|
|
67
|
-
it '
|
75
|
+
it 'returns an array of arrays' do
|
68
76
|
create_list(:user, 5)
|
69
77
|
expect(datatable.data).to be_a(Array)
|
70
78
|
expect(datatable.data.size).to eq 5
|
@@ -72,7 +80,7 @@ describe AjaxDatatablesRails::Base do
|
|
72
80
|
expect(item).to be_a(Array)
|
73
81
|
end
|
74
82
|
|
75
|
-
it '
|
83
|
+
it 'htmls escape data' do
|
76
84
|
create(:user, first_name: 'Name "><img src=x onerror=alert("first_name")>', last_name: 'Name "><img src=x onerror=alert("last_name")>')
|
77
85
|
data = datatable.send(:sanitize_data, datatable.data)
|
78
86
|
item = data.first
|
@@ -131,6 +139,18 @@ describe AjaxDatatablesRails::Base do
|
|
131
139
|
datatable.new(sample_params)
|
132
140
|
end
|
133
141
|
|
142
|
+
describe '#fetch_records' do
|
143
|
+
it 'calls #get_raw_records' do
|
144
|
+
expect(datatable).to receive(:get_raw_records) { User.all }
|
145
|
+
datatable.fetch_records
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'returns a collection of records' do
|
149
|
+
expect(datatable).to receive(:get_raw_records) { User.all }
|
150
|
+
expect(datatable.fetch_records).to be_a(ActiveRecord::Relation)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
134
154
|
describe '#filter_records' do
|
135
155
|
it {
|
136
156
|
expect { datatable.filter_records([]) }.to raise_error(NotImplementedError).with_message('FOO')
|
@@ -156,7 +176,7 @@ describe AjaxDatatablesRails::Base do
|
|
156
176
|
describe '#as_json' do
|
157
177
|
let(:datatable) { ComplexDatatable.new(sample_params) }
|
158
178
|
|
159
|
-
it '
|
179
|
+
it 'returns a hash' do
|
160
180
|
create_list(:user, 5)
|
161
181
|
data = datatable.as_json
|
162
182
|
expect(data[:recordsTotal]).to eq 5
|
@@ -166,9 +186,9 @@ describe AjaxDatatablesRails::Base do
|
|
166
186
|
end
|
167
187
|
|
168
188
|
context 'with additional_data' do
|
169
|
-
it '
|
189
|
+
it 'returns a hash' do
|
170
190
|
create_list(:user, 5)
|
171
|
-
expect(datatable).to receive(:additional_data){ { foo: 'bar' } }
|
191
|
+
expect(datatable).to receive(:additional_data) { { foo: 'bar' } }
|
172
192
|
data = datatable.as_json
|
173
193
|
expect(data[:recordsTotal]).to eq 5
|
174
194
|
expect(data[:recordsFiltered]).to eq 5
|
@@ -184,7 +204,7 @@ describe AjaxDatatablesRails::Base do
|
|
184
204
|
describe '#column_id' do
|
185
205
|
let(:datatable) { ComplexDatatable.new(sample_params) }
|
186
206
|
|
187
|
-
it '
|
207
|
+
it 'returns column id from view_columns hash' do
|
188
208
|
expect(datatable.column_id(:username)).to eq(0)
|
189
209
|
expect(datatable.column_id('username')).to eq(0)
|
190
210
|
end
|
@@ -194,7 +214,7 @@ describe AjaxDatatablesRails::Base do
|
|
194
214
|
let(:datatable) { ComplexDatatable.new(sample_params) }
|
195
215
|
before { datatable.params[:columns]['0'][:search][:value] = 'doe' }
|
196
216
|
|
197
|
-
it '
|
217
|
+
it 'returns column data from params' do
|
198
218
|
expect(datatable.column_data(:username)).to eq('doe')
|
199
219
|
expect(datatable.column_data('username')).to eq('doe')
|
200
220
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AjaxDatatablesRails::Datatable::Column do
|
5
|
+
RSpec.describe AjaxDatatablesRails::Datatable::Column do
|
4
6
|
|
5
7
|
let(:datatable) { ComplexDatatable.new(sample_params) }
|
6
8
|
|
@@ -8,50 +10,49 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
8
10
|
|
9
11
|
let(:column) { datatable.datatable.columns.first }
|
10
12
|
|
11
|
-
before
|
12
|
-
datatable.params[:columns] = {'0'=>{'data'=>'username', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}}
|
13
|
-
end
|
13
|
+
before { datatable.params[:columns]['0'][:search][:value] = 'searchvalue' }
|
14
14
|
|
15
|
-
it '
|
15
|
+
it 'is orderable' do
|
16
16
|
expect(column.orderable?).to eq(true)
|
17
17
|
end
|
18
18
|
|
19
|
-
it '
|
19
|
+
it 'sorts nulls last' do
|
20
20
|
expect(column.nulls_last?).to eq(false)
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
23
|
+
it 'is searchable' do
|
24
24
|
expect(column.searchable?).to eq(true)
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
27
|
+
it 'is searched' do
|
28
28
|
expect(column.searched?).to eq(true)
|
29
29
|
end
|
30
30
|
|
31
|
-
it '
|
31
|
+
it 'has connected to id column' do
|
32
32
|
expect(column.data).to eq('username')
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#data' do
|
36
|
-
it '
|
36
|
+
it 'returns the data from params' do
|
37
37
|
expect(column.data).to eq 'username'
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe '#source' do
|
42
|
-
it '
|
42
|
+
it 'returns the data source from view_column' do
|
43
43
|
expect(column.source).to eq 'User.username'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe '#table' do
|
48
48
|
context 'with ActiveRecord ORM' do
|
49
|
-
it '
|
49
|
+
it 'returns the corresponding AR table' do
|
50
50
|
expect(column.table).to eq User.arel_table
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
53
54
|
context 'with other ORM' do
|
54
|
-
it '
|
55
|
+
it 'returns the corresponding model' do
|
55
56
|
expect(User).to receive(:respond_to?).with(:arel_table).and_return(false)
|
56
57
|
expect(column.table).to eq User
|
57
58
|
end
|
@@ -59,19 +60,19 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
59
60
|
end
|
60
61
|
|
61
62
|
describe '#model' do
|
62
|
-
it '
|
63
|
+
it 'returns the corresponding AR model' do
|
63
64
|
expect(column.model).to eq User
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
68
|
describe '#field' do
|
68
|
-
it '
|
69
|
+
it 'returns the corresponding field in DB' do
|
69
70
|
expect(column.field).to eq :username
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
74
|
describe '#custom_field?' do
|
74
|
-
it '
|
75
|
+
it 'returns false if field is bound to an AR field' do
|
75
76
|
expect(column.custom_field?).to be false
|
76
77
|
end
|
77
78
|
end
|
@@ -81,47 +82,47 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
81
82
|
expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch)
|
82
83
|
end
|
83
84
|
|
84
|
-
it '
|
85
|
+
it 'has search value' do
|
85
86
|
expect(column.search.value).to eq('searchvalue')
|
86
87
|
end
|
87
88
|
|
88
|
-
it '
|
89
|
+
it 'does not regex' do
|
89
90
|
expect(column.search.regexp?).to eq false
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
94
|
describe '#cond' do
|
94
|
-
it '
|
95
|
+
it 'is :like by default' do
|
95
96
|
expect(column.cond).to eq(:like)
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
99
100
|
describe '#source' do
|
100
|
-
it '
|
101
|
+
it 'is :like by default' do
|
101
102
|
expect(column.source).to eq('User.username')
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
106
|
describe '#search_query' do
|
106
|
-
it '
|
107
|
+
it 'bulds search query' do
|
107
108
|
expect(column.search_query.to_sql).to include('%searchvalue%')
|
108
109
|
end
|
109
110
|
end
|
110
111
|
|
111
112
|
describe '#sort_query' do
|
112
|
-
it '
|
113
|
+
it 'builds sort query' do
|
113
114
|
expect(column.sort_query).to eq('users.username')
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
117
118
|
describe '#use_regex?' do
|
118
|
-
it '
|
119
|
+
it 'is true by default' do
|
119
120
|
expect(column.use_regex?).to be true
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
124
|
describe '#delimiter' do
|
124
|
-
it '
|
125
|
+
it 'is - by default' do
|
125
126
|
expect(column.delimiter).to eq('-')
|
126
127
|
end
|
127
128
|
end
|
@@ -131,7 +132,7 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
131
132
|
let(:datatable) { DatatableWithFormater.new(sample_params) }
|
132
133
|
let(:column) { datatable.datatable.columns.find { |c| c.data == 'last_name' } }
|
133
134
|
|
134
|
-
it '
|
135
|
+
it 'is a proc' do
|
135
136
|
expect(column.formatter).to be_a(Proc)
|
136
137
|
end
|
137
138
|
end
|
@@ -140,7 +141,7 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
140
141
|
let(:datatable) { DatatableCondProc.new(sample_params) }
|
141
142
|
let(:column) { datatable.datatable.columns.find { |c| c.data == 'username' } }
|
142
143
|
|
143
|
-
it '
|
144
|
+
it 'is a proc' do
|
144
145
|
config = column.instance_variable_get('@view_column')
|
145
146
|
filter = config[:cond]
|
146
147
|
expect(filter).to be_a(Proc)
|
@@ -204,19 +205,15 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
204
205
|
end
|
205
206
|
|
206
207
|
describe 'when empty column' do
|
207
|
-
before
|
208
|
-
datatable.params[:columns] = {'0'=>{'data'=>'', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}}
|
209
|
-
end
|
208
|
+
before { datatable.params[:columns]['0'][:data] = '' }
|
210
209
|
|
211
210
|
it 'raises error' do
|
212
|
-
expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message(
|
211
|
+
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')
|
213
212
|
end
|
214
213
|
end
|
215
214
|
|
216
215
|
describe 'when unknown column' do
|
217
|
-
before
|
218
|
-
datatable.params[:columns] = {'0'=>{'data'=>'foo', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'searchvalue', 'regex'=>'false'}}}
|
219
|
-
end
|
216
|
+
before { datatable.params[:columns]['0'][:data] = 'foo' }
|
220
217
|
|
221
218
|
it 'raises error' do
|
222
219
|
expect { datatable.to_json }.to raise_error(AjaxDatatablesRails::Error::InvalidSearchColumn).with_message("Check that column 'foo' exists in view_columns")
|