1
1
# frozen_string_literal: true
2
2
require "rails_helper"
3
3
4
- RSpec . describe ActiveAdmin ::AsyncCount , if : Post . respond_to? ( :async_count ) do
4
+ RSpec . describe ActiveAdmin ::AsyncCount do
5
5
include ActiveAdmin ::IndexHelper
6
6
7
7
def seed_posts
@@ -10,22 +10,29 @@ def seed_posts
10
10
end
11
11
end
12
12
13
- it "can be passed to the collection_size helper" do
13
+ it "can be passed to the collection_size helper" , if : Post . respond_to? ( :async_count ) do
14
14
seed_posts
15
15
16
16
expect ( collection_size ( described_class . new ( Post . all ) ) ) . to eq ( Post . count )
17
17
expect ( collection_size ( described_class . new ( Post . group ( :author_id ) ) ) ) . to eq ( Post . distinct . pluck ( :author_id ) . size )
18
18
end
19
19
20
20
describe "#initialize" do
21
- it "initiates an async_count query" do
22
- collection = Post . all
21
+ let ( :collection ) { Post . all }
22
+
23
+ it "initiates an async_count query" , if : Post . respond_to? ( :async_count ) do
23
24
expect ( collection ) . to receive ( :async_count )
24
25
described_class . new ( collection )
25
26
end
27
+
28
+ it "raises an error when ActiveRecord async_count is unavailable" , unless : Post . respond_to? ( :async_count ) do
29
+ expect do
30
+ described_class . new ( collection )
31
+ end . to raise_error ( ActiveAdmin ::AsyncCount ::NotSupportedError , %r{does not support :async_count} )
32
+ end
26
33
end
27
34
28
- describe "#count" do
35
+ describe "#count" , if : Post . respond_to? ( :async_count ) do
29
36
before { seed_posts }
30
37
31
38
it "returns the result of a count query" do
@@ -49,7 +56,7 @@ def seed_posts
49
56
end
50
57
end
51
58
52
- describe "delegation" do
59
+ describe "delegation" , if : Post . respond_to? ( :async_count ) do
53
60
let ( :collection ) { Post . all }
54
61
55
62
%i[
0 commit comments