ajax-datatables-rails 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +23 -1132
- data/.travis.yml +36 -24
- data/Appraisals +14 -8
- data/CHANGELOG.md +32 -7
- data/Gemfile +2 -0
- data/README.md +400 -335
- data/Rakefile +2 -1
- data/ajax-datatables-rails.gemspec +8 -6
- data/doc/webpack.md +50 -0
- data/gemfiles/{rails_4.1.15.gemfile → rails_4.1.16.gemfile} +1 -1
- data/gemfiles/{rails_4.2.8.gemfile → rails_4.2.10.gemfile} +2 -1
- data/gemfiles/{rails_5.0.3.gemfile → rails_5.0.7.gemfile} +1 -1
- data/gemfiles/{rails_5.1.1.gemfile → rails_5.1.6.gemfile} +1 -1
- data/gemfiles/rails_5.2.0.gemfile +13 -0
- data/lib/ajax-datatables-rails.rb +3 -11
- data/lib/ajax-datatables-rails/base.rb +44 -24
- data/lib/ajax-datatables-rails/config.rb +3 -0
- data/lib/ajax-datatables-rails/datatable/column.rb +33 -125
- data/lib/ajax-datatables-rails/datatable/column/date_filter.rb +77 -0
- data/lib/ajax-datatables-rails/datatable/column/order.rb +29 -0
- data/lib/ajax-datatables-rails/datatable/column/search.rb +88 -0
- data/lib/ajax-datatables-rails/datatable/datatable.rb +10 -7
- data/lib/ajax-datatables-rails/datatable/simple_order.rb +17 -2
- data/lib/ajax-datatables-rails/datatable/simple_search.rb +3 -0
- data/lib/ajax-datatables-rails/orm/active_record.rb +14 -5
- data/lib/ajax-datatables-rails/version.rb +3 -1
- data/lib/ajax_datatables_rails.rb +15 -0
- data/lib/generators/datatable/config_generator.rb +2 -0
- data/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +5 -0
- data/lib/generators/rails/datatable_generator.rb +6 -5
- data/lib/generators/rails/templates/datatable.rb +1 -15
- data/spec/ajax-datatables-rails/base_spec.rb +23 -26
- data/spec/ajax-datatables-rails/datatable/column_spec.rb +68 -23
- data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +1 -1
- data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +29 -2
- data/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +1 -1
- data/spec/ajax-datatables-rails/extended_spec.rb +3 -3
- data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +94 -35
- data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +6 -6
- data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +43 -0
- data/spec/ajax-datatables-rails/orm/active_record_spec.rb +1 -1
- data/spec/factories/user.rb +1 -1
- data/spec/install_oracle.sh +2 -2
- data/spec/spec_helper.rb +8 -3
- data/spec/support/datatable_cond_date.rb +5 -0
- data/spec/support/datatable_cond_numeric.rb +41 -0
- data/spec/support/datatable_cond_proc.rb +11 -0
- data/spec/support/datatable_cond_string.rb +23 -0
- data/spec/support/datatable_order_nulls_last.rb +5 -0
- data/spec/support/test_helpers.rb +13 -88
- metadata +28 -13
- data/lib/ajax-datatables-rails/datatable/column_date_filter.rb +0 -41
@@ -6,30 +6,25 @@ describe AjaxDatatablesRails::Base do
|
|
6
6
|
let(:view) { double('view', params: sample_params) }
|
7
7
|
|
8
8
|
it 'requires a view_context' do
|
9
|
-
expect {
|
9
|
+
expect { described_class.new }.to raise_error ArgumentError
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'accepts an options hash' do
|
13
|
-
datatable =
|
13
|
+
datatable = described_class.new(view, foo: 'bar')
|
14
14
|
expect(datatable.options).to eq(foo: 'bar')
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'Public API' do
|
19
19
|
let(:view) { double('view', params: sample_params) }
|
20
|
-
let(:datatable) { AjaxDatatablesRails::Base.new(view) }
|
21
20
|
|
22
21
|
describe '#view_columns' do
|
23
22
|
it 'raises an error if not defined by the user' do
|
24
|
-
|
23
|
+
datatable = described_class.new(view)
|
24
|
+
expect { datatable.view_columns }.to raise_error NotImplementedError
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'child class implements view_columns' do
|
28
|
-
it 'expects an array based defining columns' do
|
29
|
-
datatable = SampleDatatable.new(view)
|
30
|
-
expect(datatable.view_columns).to be_a(Array)
|
31
|
-
end
|
32
|
-
|
33
28
|
it 'expects a hash based defining columns' do
|
34
29
|
datatable = ComplexDatatable.new(view)
|
35
30
|
expect(datatable.view_columns).to be_a(Hash)
|
@@ -39,18 +34,21 @@ describe AjaxDatatablesRails::Base do
|
|
39
34
|
|
40
35
|
describe '#get_raw_records' do
|
41
36
|
it 'raises an error if not defined by the user' do
|
42
|
-
|
37
|
+
datatable = described_class.new(view)
|
38
|
+
expect { datatable.get_raw_records }.to raise_error NotImplementedError
|
43
39
|
end
|
44
40
|
end
|
45
41
|
|
46
42
|
describe '#data' do
|
47
43
|
it 'raises an error if not defined by the user' do
|
48
|
-
|
44
|
+
datatable = described_class.new(view)
|
45
|
+
expect { datatable.data }.to raise_error NotImplementedError
|
49
46
|
end
|
50
47
|
|
51
48
|
context 'when data is defined as a hash' do
|
49
|
+
let(:datatable) { ComplexDatatable.new(view) }
|
50
|
+
|
52
51
|
it 'should return an array of hashes' do
|
53
|
-
datatable = ComplexDatatableHash.new(view)
|
54
52
|
create_list(:user, 5)
|
55
53
|
expect(datatable.data).to be_a(Array)
|
56
54
|
expect(datatable.data.size).to eq 5
|
@@ -59,7 +57,6 @@ describe AjaxDatatablesRails::Base do
|
|
59
57
|
end
|
60
58
|
|
61
59
|
it 'should html escape data' do
|
62
|
-
datatable = ComplexDatatableHash.new(view)
|
63
60
|
create(:user, first_name: 'Name "><img src=x onerror=alert("first_name")>', last_name: 'Name "><img src=x onerror=alert("last_name")>')
|
64
61
|
data = datatable.send(:sanitize, datatable.data)
|
65
62
|
item = data.first
|
@@ -69,8 +66,9 @@ describe AjaxDatatablesRails::Base do
|
|
69
66
|
end
|
70
67
|
|
71
68
|
context 'when data is defined as a array' do
|
69
|
+
let(:datatable) { ComplexDatatableArray.new(view) }
|
70
|
+
|
72
71
|
it 'should return an array of arrays' do
|
73
|
-
datatable = ComplexDatatableArray.new(view)
|
74
72
|
create_list(:user, 5)
|
75
73
|
expect(datatable.data).to be_a(Array)
|
76
74
|
expect(datatable.data.size).to eq 5
|
@@ -79,7 +77,6 @@ describe AjaxDatatablesRails::Base do
|
|
79
77
|
end
|
80
78
|
|
81
79
|
it 'should html escape data' do
|
82
|
-
datatable = ComplexDatatableArray.new(view)
|
83
80
|
create(:user, first_name: 'Name "><img src=x onerror=alert("first_name")>', last_name: 'Name "><img src=x onerror=alert("last_name")>')
|
84
81
|
data = datatable.send(:sanitize, datatable.data)
|
85
82
|
item = data.first
|
@@ -90,8 +87,9 @@ describe AjaxDatatablesRails::Base do
|
|
90
87
|
end
|
91
88
|
|
92
89
|
describe '#as_json' do
|
90
|
+
let(:datatable) { ComplexDatatable.new(view) }
|
91
|
+
|
93
92
|
it 'should return a hash' do
|
94
|
-
datatable = ComplexDatatableHash.new(view)
|
95
93
|
create_list(:user, 5)
|
96
94
|
data = datatable.as_json
|
97
95
|
expect(data[:recordsTotal]).to eq 5
|
@@ -100,11 +98,10 @@ describe AjaxDatatablesRails::Base do
|
|
100
98
|
expect(data[:data].size).to eq 5
|
101
99
|
end
|
102
100
|
|
103
|
-
context 'with
|
101
|
+
context 'with additional_data' do
|
104
102
|
it 'should return a hash' do
|
105
|
-
datatable = ComplexDatatableHash.new(view)
|
106
103
|
create_list(:user, 5)
|
107
|
-
expect(datatable).to receive(:
|
104
|
+
expect(datatable).to receive(:additional_data){ { foo: 'bar' } }
|
108
105
|
data = datatable.as_json
|
109
106
|
expect(data[:recordsTotal]).to eq 5
|
110
107
|
expect(data[:recordsFiltered]).to eq 5
|
@@ -154,34 +151,34 @@ describe AjaxDatatablesRails::Base do
|
|
154
151
|
describe '#offset' do
|
155
152
|
it 'defaults to 0' do
|
156
153
|
default_view = double('view', params: {})
|
157
|
-
datatable =
|
154
|
+
datatable = described_class.new(default_view)
|
158
155
|
expect(datatable.datatable.send(:offset)).to eq(0)
|
159
156
|
end
|
160
157
|
|
161
|
-
it 'matches the value on view params[:start]
|
158
|
+
it 'matches the value on view params[:start]' do
|
162
159
|
paginated_view = double('view', params: { start: '11' })
|
163
|
-
datatable =
|
164
|
-
expect(datatable.datatable.send(:offset)).to eq(
|
160
|
+
datatable = described_class.new(paginated_view)
|
161
|
+
expect(datatable.datatable.send(:offset)).to eq(11)
|
165
162
|
end
|
166
163
|
end
|
167
164
|
|
168
165
|
describe '#page' do
|
169
166
|
it 'calculates page number from params[:start] and #per_page' do
|
170
167
|
paginated_view = double('view', params: { start: '11' })
|
171
|
-
datatable =
|
168
|
+
datatable = described_class.new(paginated_view)
|
172
169
|
expect(datatable.datatable.send(:page)).to eq(2)
|
173
170
|
end
|
174
171
|
end
|
175
172
|
|
176
173
|
describe '#per_page' do
|
177
174
|
it 'defaults to 10' do
|
178
|
-
datatable =
|
175
|
+
datatable = described_class.new(view)
|
179
176
|
expect(datatable.datatable.send(:per_page)).to eq(10)
|
180
177
|
end
|
181
178
|
|
182
179
|
it 'matches the value on view params[:length]' do
|
183
180
|
other_view = double('view', params: { length: 20 })
|
184
|
-
datatable =
|
181
|
+
datatable = described_class.new(other_view)
|
185
182
|
expect(datatable.datatable.send(:per_page)).to eq(20)
|
186
183
|
end
|
187
184
|
end
|
@@ -17,6 +17,10 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
17
17
|
expect(column.orderable?).to eq(true)
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'should sort nulls last' do
|
21
|
+
expect(column.nulls_last?).to eq(false)
|
22
|
+
end
|
23
|
+
|
20
24
|
it 'should be searchable' do
|
21
25
|
expect(column.searchable?).to eq(true)
|
22
26
|
end
|
@@ -29,6 +33,50 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
29
33
|
expect(column.data).to eq('username')
|
30
34
|
end
|
31
35
|
|
36
|
+
describe '#data' do
|
37
|
+
it 'should return the data from params' do
|
38
|
+
expect(column.data).to eq 'username'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#source' do
|
43
|
+
it 'should return the data source from view_column' do
|
44
|
+
expect(column.source).to eq 'User.username'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#table' do
|
49
|
+
context 'with ActiveRecord ORM' do
|
50
|
+
it 'should return the corresponding AR table' do
|
51
|
+
expect(column.table).to eq User.arel_table
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context 'with other ORM' do
|
55
|
+
it 'should return the corresponding model' do
|
56
|
+
expect(User).to receive(:respond_to?).with(:arel_table).and_return(false)
|
57
|
+
expect(column.table).to eq User
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#model' do
|
63
|
+
it 'should return the corresponding AR model' do
|
64
|
+
expect(column.model).to eq User
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#field' do
|
69
|
+
it 'should return the corresponding field in DB' do
|
70
|
+
expect(column.field).to eq :username
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#custom_field?' do
|
75
|
+
it 'should return false if field is bound to an AR field' do
|
76
|
+
expect(column.custom_field?).to be false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
32
80
|
describe '#search' do
|
33
81
|
it 'child class' do
|
34
82
|
expect(column.search).to be_a(AjaxDatatablesRails::Datatable::SimpleSearch)
|
@@ -73,37 +121,34 @@ describe AjaxDatatablesRails::Datatable::Column do
|
|
73
121
|
end
|
74
122
|
end
|
75
123
|
|
76
|
-
|
77
|
-
|
78
|
-
|
124
|
+
unless AjaxDatatablesRails.old_rails?
|
125
|
+
describe '#delimiter' do
|
126
|
+
it 'should be - by default' do
|
127
|
+
expect(column.delimiter).to eq('-')
|
128
|
+
end
|
79
129
|
end
|
80
130
|
end
|
81
131
|
end
|
82
132
|
|
83
|
-
describe '
|
84
|
-
let(:
|
85
|
-
|
86
|
-
before do
|
87
|
-
datatable.params[:columns] = {'0'=>{'data'=>'last_name', 'name'=>'', 'searchable'=>'true', 'orderable'=>'true', 'search'=>{'value'=>'', 'regex'=>'false'}}}
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should be orderable' do
|
91
|
-
expect(column.orderable?).to eq(true)
|
92
|
-
end
|
133
|
+
describe '#formater' do
|
134
|
+
let(:datatable) { DatatableWithFormater.new(view) }
|
135
|
+
let(:column) { datatable.datatable.columns.find { |c| c.data == 'last_name' } }
|
93
136
|
|
94
|
-
it 'should be
|
95
|
-
expect(column.
|
137
|
+
it 'should be a proc' do
|
138
|
+
expect(column.formater).to be_a(Proc)
|
96
139
|
end
|
140
|
+
end
|
97
141
|
|
98
|
-
|
99
|
-
|
100
|
-
|
142
|
+
describe '#filter' do
|
143
|
+
let(:datatable) { DatatableCondProc.new(view) }
|
144
|
+
let(:column) { datatable.datatable.columns.find { |c| c.data == 'username' } }
|
101
145
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
146
|
+
it 'should be a proc' do
|
147
|
+
config = column.instance_variable_get('@view_column')
|
148
|
+
filter = config[:cond]
|
149
|
+
expect(filter).to be_a(Proc)
|
150
|
+
expect(filter).to receive(:call).with(column, column.formated_value)
|
151
|
+
column.filter
|
106
152
|
end
|
107
153
|
end
|
108
|
-
|
109
154
|
end
|
@@ -2,12 +2,39 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AjaxDatatablesRails::Datatable::SimpleOrder do
|
4
4
|
|
5
|
-
let(:
|
6
|
-
let(:
|
5
|
+
let(:view) { double('view', params: sample_params) }
|
6
|
+
let(:datatable) { ComplexDatatable.new(view).datatable }
|
7
|
+
let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'column' => '1', 'dir' => 'desc'}) }
|
8
|
+
let(:simple_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(datatable, options) }
|
7
9
|
|
8
10
|
describe 'option methods' do
|
9
11
|
it 'sql query' do
|
10
12
|
expect(simple_order.query('firstname')).to eq('firstname DESC')
|
11
13
|
end
|
12
14
|
end
|
15
|
+
|
16
|
+
describe 'option methods with nulls last' do
|
17
|
+
describe 'using global option' do
|
18
|
+
before { AjaxDatatablesRails.config.nulls_last = true }
|
19
|
+
after { AjaxDatatablesRails.config.nulls_last = false }
|
20
|
+
|
21
|
+
it 'sql query' do
|
22
|
+
expect(simple_order.query('email')).to eq(
|
23
|
+
'CASE WHEN email IS NULL THEN 1 ELSE 0 END, email DESC'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'using column option' do
|
29
|
+
let(:sorted_datatable) { DatatableOrderNullsLast.new(view).datatable }
|
30
|
+
let(:nulls_last_order) { AjaxDatatablesRails::Datatable::SimpleOrder.new(sorted_datatable, options) }
|
31
|
+
|
32
|
+
it 'sql query' do
|
33
|
+
expect(nulls_last_order.query('email')).to eq(
|
34
|
+
'CASE WHEN email IS NULL THEN 1 ELSE 0 END, email DESC'
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
13
40
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AjaxDatatablesRails::Datatable::SimpleSearch do
|
4
4
|
|
5
|
-
let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'value'=>'search value', 'regex'=>'true'}) }
|
5
|
+
let(:options) { ActiveSupport::HashWithIndifferentAccess.new({'value' => 'search value', 'regex' => 'true'}) }
|
6
6
|
let(:simple_search) { AjaxDatatablesRails::Datatable::SimpleSearch.new(options) }
|
7
7
|
|
8
8
|
describe 'option methods' do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AjaxDatatablesRails::Base do
|
4
|
-
let(:view) { double('view', params: sample_params) }
|
5
|
-
let(:datatable) { ReallyComplexDatatable.new(view) }
|
6
|
-
|
7
4
|
describe 'it can transform search value before asking the database' do
|
5
|
+
let(:view) { double('view', params: sample_params) }
|
6
|
+
let(:datatable) { DatatableWithFormater.new(view) }
|
7
|
+
|
8
8
|
before(:each) do
|
9
9
|
create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'DOE')
|
10
10
|
create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'SMITH')
|
@@ -43,27 +43,69 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
context 'none of columns are connected' do
|
46
|
+
context 'when none of columns are connected' do
|
47
47
|
before(:each) do
|
48
48
|
allow(datatable).to receive(:searchable_columns) { [] }
|
49
49
|
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
context 'when search value is a string' do
|
52
|
+
before(:each) do
|
53
|
+
datatable.params[:search] = { value: 'msmith' }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns empty query result' do
|
57
|
+
expect(datatable.send(:build_conditions_for_datatable)).to be_blank
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns filtered results' do
|
61
|
+
query = datatable.send(:build_conditions_for_datatable)
|
62
|
+
results = records.where(query).map(&:username)
|
63
|
+
expect(results).to eq ['johndoe', 'msmith']
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when search value is space-separated string' do
|
68
|
+
before(:each) do
|
69
|
+
datatable.params[:search] = { value: 'foo bar' }
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns empty query result' do
|
73
|
+
expect(datatable.send(:build_conditions_for_datatable)).to be_blank
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns filtered results' do
|
77
|
+
query = datatable.send(:build_conditions_for_datatable)
|
78
|
+
results = records.where(query).map(&:username)
|
79
|
+
expect(results).to eq ['johndoe', 'msmith']
|
80
|
+
end
|
54
81
|
end
|
55
82
|
end
|
56
83
|
|
57
84
|
context 'with search query' do
|
58
|
-
|
59
|
-
|
85
|
+
context 'when search value is a string' do
|
86
|
+
before(:each) do
|
87
|
+
datatable.params[:search] = { value: 'john', regex: 'false' }
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns a filtering query' do
|
91
|
+
query = datatable.send(:build_conditions_for_datatable)
|
92
|
+
results = records.where(query).map(&:username)
|
93
|
+
expect(results).to include('johndoe')
|
94
|
+
expect(results).not_to include('msmith')
|
95
|
+
end
|
60
96
|
end
|
61
97
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
98
|
+
context 'when search value is space-separated string' do
|
99
|
+
before(:each) do
|
100
|
+
datatable.params[:search] = { value: 'john doe', regex: 'false' }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns a filtering query' do
|
104
|
+
query = datatable.send(:build_conditions_for_datatable)
|
105
|
+
results = records.where(query).map(&:username)
|
106
|
+
expect(results).to eq ['johndoe']
|
107
|
+
expect(results).not_to include('msmith')
|
108
|
+
end
|
67
109
|
end
|
68
110
|
end
|
69
111
|
end
|
@@ -141,61 +183,61 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
141
183
|
end
|
142
184
|
end
|
143
185
|
|
144
|
-
describe '#
|
186
|
+
describe '#type_cast helper method' do
|
145
187
|
let(:view) { double('view', params: sample_params) }
|
146
188
|
let(:column) { ComplexDatatable.new(view).datatable.columns.first }
|
147
189
|
|
148
190
|
it 'returns VARCHAR if :db_adapter is :pg' do
|
149
191
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :pg }
|
150
|
-
expect(column.send(:
|
192
|
+
expect(column.send(:type_cast)).to eq('VARCHAR')
|
151
193
|
end
|
152
194
|
|
153
195
|
it 'returns VARCHAR if :db_adapter is :postgre' do
|
154
196
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgre }
|
155
|
-
expect(column.send(:
|
197
|
+
expect(column.send(:type_cast)).to eq('VARCHAR')
|
156
198
|
end
|
157
199
|
|
158
200
|
it 'returns VARCHAR if :db_adapter is :postgresql' do
|
159
201
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :postgresql }
|
160
|
-
expect(column.send(:
|
202
|
+
expect(column.send(:type_cast)).to eq('VARCHAR')
|
161
203
|
end
|
162
204
|
|
163
205
|
it 'returns VARCHAR if :db_adapter is :oracle' do
|
164
206
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracle }
|
165
|
-
expect(column.send(:
|
207
|
+
expect(column.send(:type_cast)).to eq('VARCHAR2(4000)')
|
166
208
|
end
|
167
209
|
|
168
210
|
it 'returns VARCHAR if :db_adapter is :oracleenhanced' do
|
169
211
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :oracleenhanced }
|
170
|
-
expect(column.send(:
|
212
|
+
expect(column.send(:type_cast)).to eq('VARCHAR2(4000)')
|
171
213
|
end
|
172
214
|
|
173
215
|
it 'returns CHAR if :db_adapter is :mysql2' do
|
174
216
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql2 }
|
175
|
-
expect(column.send(:
|
217
|
+
expect(column.send(:type_cast)).to eq('CHAR')
|
176
218
|
end
|
177
219
|
|
178
220
|
it 'returns CHAR if :db_adapter is :mysql' do
|
179
221
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql }
|
180
|
-
expect(column.send(:
|
222
|
+
expect(column.send(:type_cast)).to eq('CHAR')
|
181
223
|
end
|
182
224
|
|
183
225
|
it 'returns TEXT if :db_adapter is :sqlite' do
|
184
226
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite }
|
185
|
-
expect(column.send(:
|
227
|
+
expect(column.send(:type_cast)).to eq('TEXT')
|
186
228
|
end
|
187
229
|
|
188
230
|
it 'returns TEXT if :db_adapter is :sqlite3' do
|
189
231
|
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite3 }
|
190
|
-
expect(column.send(:
|
232
|
+
expect(column.send(:type_cast)).to eq('TEXT')
|
191
233
|
end
|
192
234
|
end
|
193
235
|
|
194
236
|
describe 'filter conditions' do
|
195
|
-
let(:datatable) { ReallyComplexDatatable.new(view) }
|
196
|
-
|
197
237
|
unless AjaxDatatablesRails.old_rails?
|
198
238
|
describe 'it can filter records with condition :date_range' do
|
239
|
+
let(:datatable) { DatatableCondDate.new(view) }
|
240
|
+
|
199
241
|
before(:each) do
|
200
242
|
create(:user, username: 'johndoe', email: 'johndoe@example.com', last_name: 'Doe', created_at: '01/01/2000')
|
201
243
|
create(:user, username: 'msmith', email: 'mary.smith@example.com', last_name: 'Smith', created_at: '01/02/2000')
|
@@ -276,6 +318,8 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
276
318
|
end
|
277
319
|
|
278
320
|
describe 'it can filter records with condition :start_with' do
|
321
|
+
let(:datatable) { DatatableCondStartWith.new(view) }
|
322
|
+
|
279
323
|
before(:each) do
|
280
324
|
create(:user, first_name: 'John')
|
281
325
|
create(:user, first_name: 'Mary')
|
@@ -290,20 +334,35 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
290
334
|
end
|
291
335
|
|
292
336
|
describe 'it can filter records with condition :end_with' do
|
337
|
+
let(:datatable) { DatatableCondEndWith.new(view) }
|
338
|
+
|
293
339
|
before(:each) do
|
294
340
|
create(:user, last_name: 'JOHN')
|
295
341
|
create(:user, last_name: 'MARY')
|
296
342
|
end
|
297
343
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
344
|
+
if AjaxDatatablesRails.config.db_adapter == :oracleenhanced
|
345
|
+
context 'when db_adapter is oracleenhanced' do
|
346
|
+
it 'should filter records matching' do
|
347
|
+
datatable.params[:columns]['3'][:search][:value] = 'RY'
|
348
|
+
expect(datatable.data.size).to eq 1
|
349
|
+
item = datatable.data.first
|
350
|
+
expect(item[:last_name]).to eq 'MARY'
|
351
|
+
end
|
352
|
+
end
|
353
|
+
else
|
354
|
+
it 'should filter records matching' do
|
355
|
+
datatable.params[:columns]['3'][:search][:value] = 'ry'
|
356
|
+
expect(datatable.data.size).to eq 1
|
357
|
+
item = datatable.data.first
|
358
|
+
expect(item[:last_name]).to eq 'MARY'
|
359
|
+
end
|
303
360
|
end
|
304
361
|
end
|
305
362
|
|
306
363
|
describe 'it can filter records with condition :null_value' do
|
364
|
+
let(:datatable) { DatatableCondNullValue.new(view) }
|
365
|
+
|
307
366
|
before(:each) do
|
308
367
|
create(:user, first_name: 'john', email: 'foo@bar.com')
|
309
368
|
create(:user, first_name: 'mary', email: nil)
|
@@ -329,7 +388,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
329
388
|
end
|
330
389
|
|
331
390
|
describe 'it can filter records with condition :eq' do
|
332
|
-
let(:datatable) {
|
391
|
+
let(:datatable) { DatatableCondEq.new(view) }
|
333
392
|
|
334
393
|
before(:each) do
|
335
394
|
create(:user, first_name: 'john', post_id: 1)
|
@@ -345,7 +404,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
345
404
|
end
|
346
405
|
|
347
406
|
describe 'it can filter records with condition :not_eq' do
|
348
|
-
let(:datatable) {
|
407
|
+
let(:datatable) { DatatableCondNotEq.new(view) }
|
349
408
|
|
350
409
|
before(:each) do
|
351
410
|
create(:user, first_name: 'john', post_id: 1)
|
@@ -361,7 +420,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
361
420
|
end
|
362
421
|
|
363
422
|
describe 'it can filter records with condition :lt' do
|
364
|
-
let(:datatable) {
|
423
|
+
let(:datatable) { DatatableCondLt.new(view) }
|
365
424
|
|
366
425
|
before(:each) do
|
367
426
|
create(:user, first_name: 'john', post_id: 1)
|
@@ -377,7 +436,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
377
436
|
end
|
378
437
|
|
379
438
|
describe 'it can filter records with condition :gt' do
|
380
|
-
let(:datatable) {
|
439
|
+
let(:datatable) { DatatableCondGt.new(view) }
|
381
440
|
|
382
441
|
before(:each) do
|
383
442
|
create(:user, first_name: 'john', post_id: 1)
|
@@ -393,7 +452,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
393
452
|
end
|
394
453
|
|
395
454
|
describe 'it can filter records with condition :lteq' do
|
396
|
-
let(:datatable) {
|
455
|
+
let(:datatable) { DatatableCondLteq.new(view) }
|
397
456
|
|
398
457
|
before(:each) do
|
399
458
|
create(:user, first_name: 'john', post_id: 1)
|
@@ -407,7 +466,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
407
466
|
end
|
408
467
|
|
409
468
|
describe 'it can filter records with condition :gteq' do
|
410
|
-
let(:datatable) {
|
469
|
+
let(:datatable) { DatatableCondGteq.new(view) }
|
411
470
|
|
412
471
|
before(:each) do
|
413
472
|
create(:user, first_name: 'john', post_id: 1)
|
@@ -421,7 +480,7 @@ describe AjaxDatatablesRails::ORM::ActiveRecord do
|
|
421
480
|
end
|
422
481
|
|
423
482
|
describe 'it can filter records with condition :in' do
|
424
|
-
let(:datatable) {
|
483
|
+
let(:datatable) { DatatableCondIn.new(view) }
|
425
484
|
|
426
485
|
before(:each) do
|
427
486
|
create(:user, first_name: 'john', post_id: 1)
|