File tree Expand file tree Collapse file tree 3 files changed +56
-2
lines changed
lib/ajax-datatables-rails
ajax-datatables-rails/orm Expand file tree Collapse file tree 3 files changed +56
-2
lines changed Original file line number Diff line number Diff line change @@ -139,11 +139,15 @@ def retrieve_records
139
139
end
140
140
141
141
def records_total_count
142
- fetch_records . count ( :all )
142
+ numeric_count ( fetch_records . count ( :all ) )
143
143
end
144
144
145
145
def records_filtered_count
146
- filter_records ( fetch_records ) . count ( :all )
146
+ numeric_count ( filter_records ( fetch_records ) . count ( :all ) )
147
+ end
148
+
149
+ def numeric_count ( count )
150
+ count . is_a? ( Hash ) ? count . values . size : count
147
151
end
148
152
149
153
def global_search_delimiter
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec . describe AjaxDatatablesRails ::ORM ::ActiveRecord do
6
+
7
+ let ( :datatable ) { ComplexDatatable . new ( sample_params ) }
8
+ let ( :records ) { User . all }
9
+
10
+ describe '#records_total_count' do
11
+ context 'ungrouped results' do
12
+ it 'returns the count' do
13
+ expect ( datatable . send ( :records_total_count ) ) . to eq records . count
14
+ end
15
+ end
16
+
17
+ context 'grouped results' do
18
+ let ( :datatable ) { GroupedDatatable . new ( sample_params ) }
19
+
20
+ it 'returns the count' do
21
+ expect ( datatable . send ( :records_total_count ) ) . to eq records . count
22
+ end
23
+ end
24
+ end
25
+
26
+
27
+ describe '#records_filtered_count' do
28
+ context 'ungrouped results' do
29
+ it 'returns the count' do
30
+ expect ( datatable . send ( :records_filtered_count ) ) . to eq records . count
31
+ end
32
+ end
33
+
34
+ context 'grouped results' do
35
+ let ( :datatable ) { GroupedDatatable . new ( sample_params ) }
36
+
37
+ it 'returns the count' do
38
+ expect ( datatable . send ( :records_filtered_count ) ) . to eq records . count
39
+ end
40
+ end
41
+ end
42
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ class GroupedDatatable < ComplexDatatable
4
+
5
+ def get_raw_records
6
+ User . all . group ( :id )
7
+ end
8
+ end
You can’t perform that action at this time.
0 commit comments