Skip to content

Commit

Permalink
Adds ability to suppress scope count on a per-scope basis
Browse files Browse the repository at this point in the history
Suppress scope count on the index page by passing :show_count => false to
a scope definition.
  • Loading branch information
latortuga committed Feb 14, 2012
1 parent bf341ba commit c12dc45
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
13 changes: 13 additions & 0 deletions features/index/index_scopes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ Feature: Index Scoping
And I should see the scope "All" with no count
And I should see 10 posts in the table

@scope
Scenario: Viewing resources with a scope and scope count turned off for a single scope
Given 10 posts exist
And an index configuration of:
"""
ActiveAdmin.register Post do
scope :all, :default => true, :show_count => false
end
"""
Then I should see the scope "All" selected
And I should see the scope "All" with no count
And I should see 10 posts in the table

Scenario: Viewing resources when scoping
Given 6 posts exist
And 4 published posts exist
Expand Down
3 changes: 2 additions & 1 deletion lib/active_admin/scope.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ActiveAdmin
class Scope

attr_reader :name, :scope_method, :id, :scope_block, :display_if_block
attr_reader :name, :scope_method, :id, :scope_block, :display_if_block, :show_count

# Create a Scope
#
Expand Down Expand Up @@ -30,6 +30,7 @@ def initialize(name, method = nil, options = {}, &block)
@scope_block = block
end

@show_count = options[:show_count].nil? ? true : options[:show_count]
@display_if_block = options[:if]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/views/components/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def build_scope(scope, options)
text_node scope_name
span :class => 'count' do
"(" + get_scope_count(scope).to_s + ")"
end if options[:scope_count]
end if options[:scope_count] && scope.show_count
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,18 @@

end

describe "show_count" do

it "should allow setting of show_count to prevent showing counts" do
scope = ActiveAdmin::Scope.new(:default, nil, :show_count => false)
scope.show_count.should == false
end

it "should set show_count to true if not passed in" do
scope = ActiveAdmin::Scope.new(:default)
scope.show_count.should == true
end

end

end

0 comments on commit c12dc45

Please sign in to comment.