ajax-datatables-rails 0.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +8 -0
- data/.github/workflows/ci.yml +128 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/.rubocop.yml +58 -0
- data/Appraisals +28 -0
- data/CHANGELOG.md +102 -7
- data/Gemfile +4 -1
- data/Guardfile +16 -0
- data/LICENSE +17 -18
- data/README.md +595 -404
- data/Rakefile +4 -2
- data/ajax-datatables-rails.gemspec +41 -25
- data/appraisal.yml +56 -0
- data/bin/_guard-core +29 -0
- data/bin/appraisal +29 -0
- data/bin/bundle +114 -0
- data/bin/guard +29 -0
- data/bin/rackup +27 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/config.ru +7 -0
- data/doc/migrate.md +97 -0
- data/doc/webpack.md +55 -0
- data/gemfiles/rails_5.2.8.gemfile +21 -0
- data/gemfiles/rails_6.0.6.gemfile +21 -0
- data/gemfiles/rails_6.1.7.gemfile +21 -0
- data/gemfiles/rails_7.0.4.gemfile +21 -0
- data/lib/ajax-datatables-rails/active_record.rb +7 -0
- data/lib/ajax-datatables-rails/base.rb +114 -149
- data/lib/ajax-datatables-rails/datatable/column/date_filter.rb +68 -0
- data/lib/ajax-datatables-rails/datatable/column/order.rb +29 -0
- data/lib/ajax-datatables-rails/datatable/column/search.rb +125 -0
- data/lib/ajax-datatables-rails/datatable/column.rb +123 -0
- data/lib/ajax-datatables-rails/datatable/datatable.rb +91 -0
- data/lib/ajax-datatables-rails/datatable/simple_order.rb +59 -0
- data/lib/ajax-datatables-rails/datatable/simple_search.rb +23 -0
- data/lib/ajax-datatables-rails/datatable.rb +6 -0
- data/lib/ajax-datatables-rails/error.rb +9 -0
- data/lib/ajax-datatables-rails/orm/active_record.rb +60 -0
- data/lib/ajax-datatables-rails/orm.rb +6 -0
- data/lib/ajax-datatables-rails/version.rb +15 -1
- data/lib/ajax-datatables-rails.rb +11 -7
- data/lib/generators/rails/datatable_generator.rb +11 -22
- data/lib/generators/rails/templates/datatable.rb +13 -15
- data/spec/ajax-datatables-rails/base_spec.rb +223 -0
- data/spec/ajax-datatables-rails/datatable/column_spec.rb +222 -0
- data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +127 -0
- data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +62 -0
- data/spec/ajax-datatables-rails/datatable/simple_search_spec.rb +19 -0
- data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +639 -0
- data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +67 -0
- data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +80 -0
- data/spec/dummy/app/assets/config/manifest.js +0 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/storage.yml +3 -0
- data/spec/dummy/db/schema.rb +13 -0
- data/spec/dummy/log/.gitignore +1 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/user.rb +11 -0
- data/spec/install_oracle.sh +18 -0
- data/spec/spec_helper.rb +85 -6
- data/spec/support/datatables/complex_datatable.rb +33 -0
- data/spec/support/datatables/complex_datatable_array.rb +16 -0
- data/spec/support/datatables/datatable_cond_date.rb +7 -0
- data/spec/support/datatables/datatable_cond_numeric.rb +53 -0
- data/spec/support/datatables/datatable_cond_proc.rb +13 -0
- data/spec/support/datatables/datatable_cond_string.rb +43 -0
- data/spec/support/datatables/datatable_cond_unknown.rb +7 -0
- data/spec/support/datatables/datatable_custom_column.rb +17 -0
- data/spec/support/datatables/datatable_order_nulls_last.rb +7 -0
- data/spec/support/helpers/params.rb +80 -0
- data/spec/support/models/user.rb +7 -0
- metadata +249 -48
- data/lib/ajax-datatables-rails/config.rb +0 -25
- data/lib/ajax-datatables-rails/extensions/kaminari.rb +0 -12
- data/lib/ajax-datatables-rails/extensions/simple_paginator.rb +0 -12
- data/lib/ajax-datatables-rails/extensions/will_paginate.rb +0 -12
- data/lib/ajax-datatables-rails/models.rb +0 -6
- data/lib/generators/datatable/config_generator.rb +0 -17
- data/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +0 -7
- data/spec/ajax-datatables-rails/ajax_datatables_rails_spec.rb +0 -351
- data/spec/ajax-datatables-rails/kaminari_spec.rb +0 -35
- data/spec/ajax-datatables-rails/models_spec.rb +0 -10
- data/spec/ajax-datatables-rails/simple_paginator_spec.rb +0 -32
- data/spec/ajax-datatables-rails/will_paginate_spec.rb +0 -28
- data/spec/schema.rb +0 -35
- data/spec/test_models.rb +0 -21
@@ -1,351 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AjaxDatatablesRails::Base do
|
4
|
-
|
5
|
-
params = {
|
6
|
-
:draw => '5',
|
7
|
-
:columns => {
|
8
|
-
"0" => {
|
9
|
-
:data => '0',
|
10
|
-
:name => '',
|
11
|
-
:searchable => true,
|
12
|
-
:orderable => true,
|
13
|
-
:search => { :value => '', :regex => false }
|
14
|
-
},
|
15
|
-
"1" => {
|
16
|
-
:data => '1',
|
17
|
-
:name => '',
|
18
|
-
:searchable => true,
|
19
|
-
:orderable => true,
|
20
|
-
:search => { :value => '', :regex => false }
|
21
|
-
}
|
22
|
-
},
|
23
|
-
:order => { "0" => { :column => '1', :dir => 'desc' } },
|
24
|
-
:start => '0',
|
25
|
-
:length => '10',
|
26
|
-
:search => { :value => '', :regex => false },
|
27
|
-
'_' => '1403141483098'
|
28
|
-
}
|
29
|
-
let(:view) { double('view', :params => params) }
|
30
|
-
|
31
|
-
describe 'an instance' do
|
32
|
-
it 'requires a view_context' do
|
33
|
-
expect { AjaxDatatablesRails::Base.new }.to raise_error
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'accepts an options hash' do
|
37
|
-
datatable = AjaxDatatablesRails::Base.new(view, :foo => 'bar')
|
38
|
-
expect(datatable.options).to eq(:foo => 'bar')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'helper methods' do
|
43
|
-
describe '#offset' do
|
44
|
-
it 'defaults to 0' do
|
45
|
-
default_view = double('view', :params => {})
|
46
|
-
datatable = AjaxDatatablesRails::Base.new(default_view)
|
47
|
-
expect(datatable.send(:offset)).to eq(0)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'matches the value on view params[:start] minus 1' do
|
51
|
-
paginated_view = double('view', :params => { :start => '11' })
|
52
|
-
datatable = AjaxDatatablesRails::Base.new(paginated_view)
|
53
|
-
expect(datatable.send(:offset)).to eq(10)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#page' do
|
58
|
-
it 'calculates page number from params[:start] and #per_page' do
|
59
|
-
paginated_view = double('view', :params => { :start => '11' })
|
60
|
-
datatable = AjaxDatatablesRails::Base.new(paginated_view)
|
61
|
-
expect(datatable.send(:page)).to eq(2)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#per_page' do
|
66
|
-
it 'defaults to 10' do
|
67
|
-
datatable = AjaxDatatablesRails::Base.new(view)
|
68
|
-
expect(datatable.send(:per_page)).to eq(10)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'matches the value on view params[:length]' do
|
72
|
-
other_view = double('view', :params => { :length => 20 })
|
73
|
-
datatable = AjaxDatatablesRails::Base.new(other_view)
|
74
|
-
expect(datatable.send(:per_page)).to eq(20)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '#sort_column' do
|
79
|
-
it 'returns a column name from the #sorting_columns array' do
|
80
|
-
sort_view = double(
|
81
|
-
'view', :params => params
|
82
|
-
)
|
83
|
-
datatable = AjaxDatatablesRails::Base.new(sort_view)
|
84
|
-
allow(datatable).to receive(:sortable_displayed_columns) { ["0", "1"] }
|
85
|
-
allow(datatable).to receive(:sortable_columns) { ['User.foo', 'User.bar', 'User.baz'] }
|
86
|
-
|
87
|
-
expect(datatable.send(:sort_column, sort_view.params[:order]["0"])).to eq('users.bar')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#sort_direction' do
|
92
|
-
it 'matches value of params[:sSortDir_0]' do
|
93
|
-
sorting_view = double(
|
94
|
-
'view',
|
95
|
-
:params => {
|
96
|
-
:order => {
|
97
|
-
'0' => { :column => '1', :dir => 'desc' }
|
98
|
-
}
|
99
|
-
}
|
100
|
-
)
|
101
|
-
datatable = AjaxDatatablesRails::Base.new(sorting_view)
|
102
|
-
expect(datatable.send(:sort_direction, sorting_view.params[:order]["0"])).to eq('DESC')
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'can only be one option from ASC or DESC' do
|
106
|
-
sorting_view = double(
|
107
|
-
'view',
|
108
|
-
:params => {
|
109
|
-
:order => {
|
110
|
-
'0' => { :column => '1', :dir => 'foo' }
|
111
|
-
}
|
112
|
-
}
|
113
|
-
)
|
114
|
-
datatable = AjaxDatatablesRails::Base.new(sorting_view)
|
115
|
-
expect(datatable.send(:sort_direction, sorting_view.params[:order]["0"])).to eq('ASC')
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "#configure" do
|
120
|
-
let(:datatable) do
|
121
|
-
class FooDatatable < AjaxDatatablesRails::Base
|
122
|
-
end
|
123
|
-
|
124
|
-
FooDatatable.new view
|
125
|
-
end
|
126
|
-
|
127
|
-
context "when model class name is regular" do
|
128
|
-
it "should successfully get right model class" do
|
129
|
-
expect(
|
130
|
-
datatable.send(:search_condition, 'User.bar', 'bar')
|
131
|
-
).to be_a(Arel::Nodes::Matches)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "when custom named model class" do
|
136
|
-
it "should successfully get right model class" do
|
137
|
-
expect(
|
138
|
-
datatable.send(:search_condition, 'Statistics::Request.bar', 'bar')
|
139
|
-
).to be_a(Arel::Nodes::Matches)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
|
144
|
-
context "when model class name camelcased" do
|
145
|
-
it "should successfully get right model class" do
|
146
|
-
expect(
|
147
|
-
datatable.send(:search_condition, 'PurchasedOrder.bar', 'bar')
|
148
|
-
).to be_a(Arel::Nodes::Matches)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when model class name is namespaced" do
|
153
|
-
it "should successfully get right model class" do
|
154
|
-
expect(
|
155
|
-
datatable.send(:search_condition, 'Statistics::Session.bar', 'bar')
|
156
|
-
).to be_a(Arel::Nodes::Matches)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context "when model class defined but not found" do
|
161
|
-
it "raise 'uninitialized constant'" do
|
162
|
-
expect {
|
163
|
-
datatable.send(:search_condition, 'UnexistentModel.bar', 'bar')
|
164
|
-
}.to raise_error(NameError, /uninitialized constant/)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'when using deprecated notation' do
|
169
|
-
it 'should successfully get right model class if exists' do
|
170
|
-
expect(
|
171
|
-
datatable.send(:search_condition, 'users.bar', 'bar')
|
172
|
-
).to be_a(Arel::Nodes::Matches)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should display a deprecated message' do
|
176
|
-
expect(AjaxDatatablesRails::Base).to receive(:deprecated)
|
177
|
-
datatable.send(:search_condition, 'users.bar', 'bar')
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe '#sortable_columns' do
|
183
|
-
it 'returns an array representing database columns' do
|
184
|
-
datatable = AjaxDatatablesRails::Base.new(view)
|
185
|
-
expect(datatable.sortable_columns).to eq([])
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
describe '#searchable_columns' do
|
190
|
-
it 'returns an array representing database columns' do
|
191
|
-
datatable = AjaxDatatablesRails::Base.new(view)
|
192
|
-
expect(datatable.searchable_columns).to eq([])
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe 'perform' do
|
198
|
-
let(:results) { double('Collection', :offset => [], :limit => []) }
|
199
|
-
let(:view) { double('view', :params => params) }
|
200
|
-
let(:datatable) { AjaxDatatablesRails::Base.new(view) }
|
201
|
-
let(:records) { double('Array').as_null_object }
|
202
|
-
|
203
|
-
before(:each) do
|
204
|
-
allow(datatable).to receive(:sortable_columns) { ['User.foo', 'User.bar'] }
|
205
|
-
allow(datatable).to receive(:sortable_displayed_columns) { ["0", "1"] }
|
206
|
-
end
|
207
|
-
|
208
|
-
describe '#paginate_records' do
|
209
|
-
it 'defaults to Extensions::SimplePaginator#paginate_records' do
|
210
|
-
allow(records).to receive_message_chain(:offset, :limit)
|
211
|
-
|
212
|
-
expect { datatable.send(:paginate_records, records) }.not_to raise_error
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe '#sort_records' do
|
217
|
-
it 'calls #order on a collection' do
|
218
|
-
expect(results).to receive(:order)
|
219
|
-
datatable.send(:sort_records, results)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe '#filter_records' do
|
224
|
-
let(:records) { double('User', :where => []) }
|
225
|
-
let(:search_view) { double('view', :params => params) }
|
226
|
-
|
227
|
-
it 'applies search like functionality on a collection' do
|
228
|
-
datatable = AjaxDatatablesRails::Base.new(search_view)
|
229
|
-
allow(datatable).to receive(:searchable_columns) { ['users.foo'] }
|
230
|
-
|
231
|
-
expect(records).to receive(:where)
|
232
|
-
records.where
|
233
|
-
datatable.send(:filter_records, records)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe '#filter_records with multi word model' do
|
238
|
-
let(:records) { double('UserData', :where => []) }
|
239
|
-
let(:search_view) { double('view', :params => params) }
|
240
|
-
|
241
|
-
it 'applies search like functionality on a collection' do
|
242
|
-
datatable = AjaxDatatablesRails::Base.new(search_view)
|
243
|
-
allow(datatable).to receive(:searchable_columns) { ['user_datas.bar'] }
|
244
|
-
|
245
|
-
expect(records).to receive(:where)
|
246
|
-
records.where
|
247
|
-
datatable.send(:filter_records, records)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe 'hook methods' do
|
253
|
-
let(:datatable) { AjaxDatatablesRails::Base.new(view) }
|
254
|
-
|
255
|
-
describe '#data' do
|
256
|
-
it 'raises a MethodNotImplementedError' do
|
257
|
-
expect { datatable.data }.to raise_error(
|
258
|
-
AjaxDatatablesRails::Base::MethodNotImplementedError,
|
259
|
-
'Please implement this method in your class.'
|
260
|
-
)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe '#get_raw_records' do
|
265
|
-
it 'raises a MethodNotImplementedError' do
|
266
|
-
expect { datatable.get_raw_records }.to raise_error(
|
267
|
-
AjaxDatatablesRails::Base::MethodNotImplementedError,
|
268
|
-
'Please implement this method in your class.'
|
269
|
-
)
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
|
276
|
-
describe AjaxDatatablesRails::Configuration do
|
277
|
-
let(:config) { AjaxDatatablesRails::Configuration.new }
|
278
|
-
|
279
|
-
describe "default config" do
|
280
|
-
it "default db_adapter should :pg (postgresql)" do
|
281
|
-
expect(config.db_adapter).to eq(:pg)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
describe "custom config" do
|
286
|
-
it 'should accept db_adapter custom value' do
|
287
|
-
config.db_adapter = :mysql2
|
288
|
-
expect(config.db_adapter).to eq(:mysql2)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
describe '#typecast' do
|
293
|
-
params = {
|
294
|
-
:draw => '5',
|
295
|
-
:columns => {
|
296
|
-
"0" => {
|
297
|
-
:data => '0',
|
298
|
-
:name => '',
|
299
|
-
:searchable => true,
|
300
|
-
:orderable => true,
|
301
|
-
:search => { :value => '', :regex => false }
|
302
|
-
},
|
303
|
-
"1" => {
|
304
|
-
:data => '1',
|
305
|
-
:name => '',
|
306
|
-
:searchable => true,
|
307
|
-
:orderable => true,
|
308
|
-
:search => { :value => '', :regex => false }
|
309
|
-
}
|
310
|
-
},
|
311
|
-
:order => { "0" => { :column => '1', :dir => 'desc' } },
|
312
|
-
:start => '0',
|
313
|
-
:length => '10',
|
314
|
-
:search => { :value => '', :regex => false },
|
315
|
-
'_' => '1403141483098'
|
316
|
-
}
|
317
|
-
let(:view) { double('view', :params => params) }
|
318
|
-
let(:datatable) { AjaxDatatablesRails::Base.new(view) }
|
319
|
-
|
320
|
-
it 'returns VARCHAR if :db_adapter is :pg' do
|
321
|
-
expect(datatable.send(:typecast)).to eq('VARCHAR')
|
322
|
-
end
|
323
|
-
|
324
|
-
it 'returns CHAR if :db_adapter is :mysql2' do
|
325
|
-
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :mysql2 }
|
326
|
-
expect(datatable.send(:typecast)).to eq('CHAR')
|
327
|
-
end
|
328
|
-
|
329
|
-
it 'returns TEXT if :db_adapter is :sqlite3' do
|
330
|
-
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:db_adapter) { :sqlite3 }
|
331
|
-
expect(datatable.send(:typecast)).to eq('TEXT')
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
describe AjaxDatatablesRails do
|
337
|
-
describe "configurations" do
|
338
|
-
context "configurable from outside" do
|
339
|
-
before(:each) do
|
340
|
-
AjaxDatatablesRails.configure do |config|
|
341
|
-
config.db_adapter = :mysql2
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
it "should have custom value" do
|
346
|
-
expect(AjaxDatatablesRails.config.db_adapter).to eq(:mysql2)
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
end
|
351
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class KaminariDatatable < AjaxDatatablesRails::Base
|
4
|
-
end
|
5
|
-
|
6
|
-
describe KaminariDatatable do
|
7
|
-
before(:each) do
|
8
|
-
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:paginator) { :kaminari }
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#paginate_records' do
|
12
|
-
let(:users_database) do
|
13
|
-
double('User',
|
14
|
-
:all => double('RecordCollection',
|
15
|
-
:page => double('Array', :per => [])
|
16
|
-
)
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:datatable) { KaminariDatatable.new(double('view', :params => {})) }
|
21
|
-
let(:records) { users_database.all }
|
22
|
-
|
23
|
-
it 'calls #page on passed record collection' do
|
24
|
-
expect(records).to receive(:page)
|
25
|
-
datatable.send(:paginate_records, records)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'calls #per_page on passed record collection' do
|
29
|
-
arry = double('Array', :per => [])
|
30
|
-
allow(records).to receive(:page).and_return(arry)
|
31
|
-
expect(arry).to receive(:per)
|
32
|
-
datatable.send(:paginate_records, records)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class SimplePaginateDatatable < AjaxDatatablesRails::Base
|
4
|
-
include AjaxDatatablesRails::Extensions::SimplePaginator
|
5
|
-
end
|
6
|
-
|
7
|
-
describe SimplePaginateDatatable do
|
8
|
-
describe '#paginate_records' do
|
9
|
-
let(:users_database) do
|
10
|
-
double('User',
|
11
|
-
:all => double('RecordCollection',
|
12
|
-
:offset => double('Array', :limit => [])
|
13
|
-
)
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:datatable) { SimplePaginateDatatable.new(double('view', :params => {})) }
|
18
|
-
let(:records) { users_database.all }
|
19
|
-
|
20
|
-
it 'calls #offset on passed record collection' do
|
21
|
-
expect(records).to receive(:offset)
|
22
|
-
datatable.send(:paginate_records, records)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'calls #limit on passed record collection' do
|
26
|
-
arry = double('Array', :limit => [])
|
27
|
-
allow(records).to receive(:offset).and_return(arry)
|
28
|
-
expect(arry).to receive(:limit)
|
29
|
-
datatable.send(:paginate_records, records)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class WillPaginateDatatable < AjaxDatatablesRails::Base
|
4
|
-
end
|
5
|
-
|
6
|
-
describe WillPaginateDatatable do
|
7
|
-
before(:each) do
|
8
|
-
allow_any_instance_of(AjaxDatatablesRails::Configuration).to receive(:paginator) { :will_paginate }
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#paginate_records' do
|
12
|
-
let(:users_database) do
|
13
|
-
double('User',
|
14
|
-
:all => double('RecordCollection',
|
15
|
-
:paginate => double('Array', :per_page => [])
|
16
|
-
)
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:datatable) { WillPaginateDatatable.new(double('view', :params => {})) }
|
21
|
-
let(:records) { users_database.all }
|
22
|
-
|
23
|
-
it 'calls #page and #per_page on passed record collection' do
|
24
|
-
expect(records).to receive(:paginate).with(:page=>1, :per_page=>10)
|
25
|
-
datatable.send(:paginate_records, records)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/spec/schema.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
self.verbose = false
|
3
|
-
|
4
|
-
create_table :users, :force => true do |t|
|
5
|
-
t.string :username
|
6
|
-
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
|
10
|
-
create_table :user_data, :force => true do |t|
|
11
|
-
t.string :address
|
12
|
-
|
13
|
-
t.timestamps
|
14
|
-
end
|
15
|
-
|
16
|
-
create_table :purchased_orders, :force => true do |t|
|
17
|
-
t.string :foo
|
18
|
-
t.string :bar
|
19
|
-
|
20
|
-
t.timestamps
|
21
|
-
end
|
22
|
-
|
23
|
-
create_table :statistics_requests, :force => true do |t|
|
24
|
-
t.string :baz
|
25
|
-
|
26
|
-
t.timestamps
|
27
|
-
end
|
28
|
-
|
29
|
-
create_table :statistics_sessions, :force => true do |t|
|
30
|
-
t.string :foo
|
31
|
-
t.integer :bar
|
32
|
-
|
33
|
-
t.timestamps
|
34
|
-
end
|
35
|
-
end
|
data/spec/test_models.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
end
|
3
|
-
|
4
|
-
class UserData < ActiveRecord::Base
|
5
|
-
self.table_name = "user_data"
|
6
|
-
end
|
7
|
-
|
8
|
-
class PurchasedOrder < ActiveRecord::Base
|
9
|
-
end
|
10
|
-
|
11
|
-
module Statistics
|
12
|
-
def self.table_name_prefix
|
13
|
-
"statistics_"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Statistics::Request < ActiveRecord::Base
|
18
|
-
end
|
19
|
-
|
20
|
-
class Statistics::Session < ActiveRecord::Base
|
21
|
-
end
|