Skip to content

Commit

Permalink
#count breaks when default-scoped with select. Closes #2129, Fixes #2447
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Nov 3, 2015
1 parent 8b53060 commit aa458e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def all(options = {}, scope = nil)
end

def count(options = {}, scope = nil)
all(options.merge(limit: false, page: false), scope).count
all(options.merge(limit: false, page: false), scope).count(:all)
end

def destroy(objects)
Expand Down
20 changes: 18 additions & 2 deletions spec/rails_admin/adapters/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,24 @@
expect(@players).to include abstract_model.first
end

it '#count returns count of items' do
expect(abstract_model.count).to eq(@players.count)
describe '#count' do
it 'returns count of items' do
expect(abstract_model.count).to eq(@players.count)
end

context 'when default-scoped with select' do
before do
class PlayerWithDefaultScope < Player
self.table_name = 'players'
default_scope { select(:id, :name) }
end
end
let(:abstract_model) { RailsAdmin::AbstractModel.new('PlayerWithDefaultScope') }

it 'does not break' do
expect(abstract_model.count).to eq(@players.count)
end
end
end

it '#destroy destroys multiple items' do
Expand Down

0 comments on commit aa458e1

Please sign in to comment.