-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from dmorehouse/grouped_counts
Add support for grouped results
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
spec/ajax-datatables-rails/orm/active_record_count_records_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe AjaxDatatablesRails::ORM::ActiveRecord do | ||
|
||
let(:datatable) { ComplexDatatable.new(sample_params) } | ||
let(:records) { User.all } | ||
|
||
describe '#records_total_count' do | ||
context 'ungrouped results' do | ||
it 'returns the count' do | ||
expect(datatable.send(:records_total_count)).to eq records.count | ||
end | ||
end | ||
|
||
context 'grouped results' do | ||
let(:datatable) { GroupedDatatable.new(sample_params) } | ||
|
||
it 'returns the count' do | ||
expect(datatable.send(:records_total_count)).to eq records.count | ||
end | ||
end | ||
end | ||
|
||
|
||
describe '#records_filtered_count' do | ||
context 'ungrouped results' do | ||
it 'returns the count' do | ||
expect(datatable.send(:records_filtered_count)).to eq records.count | ||
end | ||
end | ||
|
||
context 'grouped results' do | ||
let(:datatable) { GroupedDatatable.new(sample_params) } | ||
|
||
it 'returns the count' do | ||
expect(datatable.send(:records_filtered_count)).to eq records.count | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class GroupedDatatable < ComplexDatatable | ||
|
||
def get_raw_records | ||
User.all.group(:id) | ||
end | ||
end |