8000 Provide friendlier error when async_count is not supported · activeadmin/activeadmin@71e7125 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71e7125

Browse files
committed
Provide friendlier error when async_count is not supported
1 parent 7dd372e commit 71e7125

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/active_admin/async_count.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# frozen_string_literal: true
22
module ActiveAdmin
33
class AsyncCount
4+
class NotSupportedError < RuntimeError; end
5+
46
def initialize(collection)
7+
raise NotSupportedError, "#{collection.inspect} does not support :async_count" unless collection.respond_to?(:async_count)
8+
59
@collection = collection.except(:select, :order)
610
@promise = @collection.async_count
711
end

spec/unit/views/components/scopes_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
end
7070

7171
it "raises an error when ActiveRecord async_count is unavailable", unless: Post.respond_to?(:async_count) do
72-
expect { scopes }.to raise_error(NoMethodError, %r{async_count})
72+
expect { scopes }.to raise_error(ActiveAdmin::AsyncCount::NotSupportedError, %r{does not support :async_count})
7373
end
7474

7575
context "when async_count is available in Rails", if: Post.respond_to?(:async_count) do

0 commit comments

Comments
 (0)
0