Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to suppress scope count on a per-scope basis #1013

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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