Skip to content
This repository

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

Merged
merged 1 commit into from about 2 years ago

2 participants

Drew Ulmer Greg Bell
Drew Ulmer
Collaborator

Suppress scope count on the index page by passing :show_count => false to a scope definition.

This fixes issue #804.

Drew Ulmer Adds ability to suppress scope count on a per-scope basis
Suppress scope count on the index page by passing :show_count => false to
a scope definition.
c12dc45
Greg Bell gregbell merged commit 8abbeb4 into from February 16, 2012
Greg Bell gregbell closed this February 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 14, 2012
Drew Ulmer Adds ability to suppress scope count on a per-scope basis
Suppress scope count on the index page by passing :show_count => false to
a scope definition.
c12dc45
This page is out of date. Refresh to see the latest.
13  features/index/index_scopes.feature
@@ -56,6 +56,19 @@ Feature: Index Scoping
56 56
     And I should see the scope "All" with no count
57 57
     And I should see 10 posts in the table
58 58
 
  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
+
59 72
   Scenario: Viewing resources when scoping
60 73
     Given 6 posts exist
61 74
     And 4 published posts exist
3  lib/active_admin/scope.rb
... ...
@@ -1,7 +1,7 @@
1 1
 module ActiveAdmin
2 2
   class Scope
3 3
 
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
5 5
 
6 6
     # Create a Scope
7 7
     #
@@ -30,6 +30,7 @@ def initialize(name, method = nil, options = {}, &block)
30 30
         @scope_block = block
31 31
       end
32 32
 
  33
+      @show_count = options[:show_count].nil? ? true : options[:show_count]
33 34
       @display_if_block = options[:if]
34 35
     end
35 36
 
2  lib/active_admin/views/components/scopes.rb
@@ -38,7 +38,7 @@ def build_scope(scope, options)
38 38
             text_node scope_name
39 39
             span :class => 'count' do
40 40
               "(" + get_scope_count(scope).to_s + ")"
41  
-            end if options[:scope_count]
  41
+            end if options[:scope_count] && scope.show_count
42 42
           end
43 43
         end
44 44
       end
14  spec/unit/scope_spec.rb
@@ -52,4 +52,18 @@
52 52
 
53 53
   end
54 54
 
  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
+
55 69
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.