|
60 | 60 | end
|
61 | 61 | end
|
62 | 62 |
|
63 <
10000
/td> |
| - it "uses AsyncCounts when available", if: Post.respond_to?(:async_count) do |
64 |
| - scopes |
65 |
| - |
66 |
| - expect(ActiveAdmin::AsyncCount).to have_received(:new).with(Post.all) |
67 |
| - expect(ActiveAdmin::AsyncCount).to have_received(:new).with(Post.where.not(published_date: nil)) |
68 |
| - end |
69 |
| - |
70 |
| - it "avoids AsyncCounts when unavailable", unless: Post.respond_to?(:async_count) do |
71 |
| - scopes |
72 |
| - |
73 |
| - expect(ActiveAdmin::AsyncCount).not_to have_received(:new) |
74 |
| - end |
75 |
| - |
76 |
| - context "when an individual scope is configured to hide its count" do |
| 63 | + context "when scopes are configured to query their counts asynchronously" do |
77 | 64 | let(:configured_scopes) do
|
78 | 65 | [
|
79 |
| - ActiveAdmin::Scope.new(:all, nil, show_count: false) |
| 66 | + ActiveAdmin::Scope.new(:all, nil, show_count: :async), |
| 67 | + ActiveAdmin::Scope.new(:published, nil, show_count: :async) { |posts| posts.where.not(published_date: nil) } |
80 | 68 | ]
|
81 | 69 | end
|
82 | 70 |
|
83 |
| - it "avoids AsyncCounts" do |
84 |
| - scopes |
85 |
| - |
86 |
| - expect(ActiveAdmin::AsyncCount).not_to have_received(:new) |
87 |
| - end |
88 |
| - end |
89 |
| - |
90 |
| - context "when a scope is not to be displayed" do |
91 |
| - let(:configured_scopes) do |
92 |
| - [ |
93 |
| - ActiveAdmin::Scope.new(:all, nil, if: -> { false }) |
94 |
| - ] |
| 71 | + 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}) |
95 | 73 | end
|
96 | 74 |
|
97 |
| - it "avoids AsyncCounts" do |
98 |
| - scopes |
99 |
| - |
100 |
| - expect(ActiveAdmin::AsyncCount).not_to have_received(:new) |
| 75 | + context "when async_count is available in Rails", if: Post.respond_to?(:async_count) do |
| 76 | + it "uses AsyncCounts" do |
| 77 | + scopes |
| 78 | + |
| 79 | + expect(ActiveAdmin::AsyncCount).to have_received(:new).with(Post.all) |
| 80 | + expect(ActiveAdmin::AsyncCount).to have_received(:new).with(Post.where.not(published_date: nil)) |
| 81 | + end |
| 82 | + |
| 83 | + context "when an individual scope is configured to show its count async" do |
| 84 | + let(:configured_scopes) do |
| 85 | + [ |
| 86 | + ActiveAdmin::Scope.new(:all), |
| 87 | + ActiveAdmin::Scope.new(:published, nil, show_count: :async) { |posts| posts.where.not(published_date: nil) } |
| 88 | + ] |
| 89 | + end |
| 90 | + |
| 91 | + it "only uses AsyncCounts for the configured scopes" do |
| 92 | + scopes |
| 93 | + |
| 94 | + expect(ActiveAdmin::AsyncCount).not_to have_received(:new).with(Post.all) |
| 95 | + expect(ActiveAdmin::AsyncCount).to have_received(:new).with(Post.where.not(published_date: nil)) |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + context "when an individual scope is configured to hide its count" do |
| 100 | + let(:configured_scopes) do |
| 101 | + [ |
| 102 | + ActiveAdmin::Scope.new(:all, nil, show_count: false), |
| 103 | + ActiveAdmin::Scope.new(:published, nil, show_count: :async) { |posts| posts.where.not(published_date: nil) } |
| 104 | + ] |
| 105 | + end |
| 106 | + |
| 107 | + it "only uses AsyncCounts for the configured scopes" do |
| 108 | + scopes |
| 109 | + |
| 110 | + expect(ActiveAdmin::AsyncCount).not_to have_received(:new).with(Post.all) |
| 111 | + expect(ActiveAdmin::AsyncCount).to have_received(:new).with(Post.where.not(published_date: nil)) |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + context "when a scope is not to be displayed" do |
| 116 | + let(:configured_scopes) do |
| 117 | + [ |
| 118 | + ActiveAdmin::Scope.new(:all, nil, show_count: :async, if: -> { false }) |
| 119 | + ] |
| 120 | + end |
| 121 | + |
| 122 | + it "avoids AsyncCounts" do |
| 123 | + scopes |
| 124 | + |
| 125 | + expect(ActiveAdmin::AsyncCount).not_to have_received(:new) |
| 126 | + end |
| 127 | + end |
101 | 128 | end
|
102 |
| - end |
103 | 129 |
|
104 |
| - context "when :show_count is configured as false" do |
105 |
| - let(:scope_options) do |
106 |
| - { scope_count: false } |
107 |
| - end |
| 130 | + context "when :show_count is configured as false" do |
| 131 | + let(:scope_options) do |
| 132 | + { scope_count: false } |
| 133 | + end |
108 | 134 |
|
109 |
| - it "avoids AsyncCounts" do |
110 |
| - scopes |
| 135 | + it "avoids AsyncCounts" do |
| 136 | + scopes |
111 | 137 |
|
112 |
| - expect(ActiveAdmin::AsyncCount).not_to have_received(:new) |
| 138 | + expect(ActiveAdmin::AsyncCount).not_to have_received(:new) |
| 139 | + end |
113 | 140 | end
|
114 | 141 | end
|
115 | 142 | end
|
|
0 commit comments