Skip to content

Commit 8abbeb4

Browse files
committed
Merge pull request activeadmin#1013 from latortuga/suppress-specific-scope-count
Adds ability to suppress scope count on a per-scope basis
2 parents c6e36ca + c12dc45 commit 8abbeb4

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

features/index/index_scopes.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ Feature: Index Scoping
5656
And I should see the scope "All" with no count
5757
And I should see 10 posts in the table
5858

59+
@scope
60+
Scenario: Viewing resources with a scope and scope count turned off for a single scope
61+
Given 10 posts exist
62+
And an index configuration of:
63+
"""
64+
ActiveAdmin.register Post do
65+
scope :all, :default => true, :show_count => false
66+
end
67+
"""
68+
Then I should see the scope "All" selected
69+
And I should see the scope "All" with no count
70+
And I should see 10 posts in the table
71+
5972
Scenario: Viewing resources when scoping
6073
Given 6 posts exist
6174
And 4 published posts exist

lib/active_admin/scope.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ActiveAdmin
22
class Scope
33

4-
attr_reader :name, :scope_method, :id, :scope_block, :display_if_block
4+
attr_reader :name, :scope_method, :id, :scope_block, :display_if_block, :show_count
55

66
# Create a Scope
77
#
@@ -30,6 +30,7 @@ def initialize(name, method = nil, options = {}, &block)
3030
@scope_block = block
3131
end
3232

33+
@show_count = options[:show_count].nil? ? true : options[:show_count]
3334
@display_if_block = options[:if]
3435
end
3536

lib/active_admin/views/components/scopes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def build_scope(scope, options)
3838
text_node scope_name
3939
span :class => 'count' do
4040
"(" + get_scope_count(scope).to_s + ")"
41-
end if options[:scope_count]
41+
end if options[:scope_count] && scope.show_count
4242
end
4343
end
4444
end

spec/unit/scope_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,18 @@
5252

5353
end
5454

55+
describe "show_count" do
56+
57+
it "should allow setting of show_count to prevent showing counts" do
58+
scope = ActiveAdmin::Scope.new(:default, nil, :show_count => false)
59+
scope.show_count.should == false
60+
end
61+
62+
it "should set show_count to true if not passed in" do
63+
scope = ActiveAdmin::Scope.new(:default)
64+
scope.show_count.should == true
65+
end
66+
67+
end
68+
5569
end

0 commit comments

Comments
 (0)