Permalink
Browse files

Issue counter doesn't show up for zero open issues.

  • Loading branch information...
1 parent 270ce55 commit 2c088596752af25a4386ebb17d4588615104575e @pwnall committed Apr 25, 2012
Showing with 32 additions and 40 deletions.
  1. +10 −9 app/helpers/issues_helper.rb
  2. +1 −2 app/views/repositories/_repository.html.erb
  3. +21 −29 test/unit/helpers/issues_helper_test.rb
@@ -7,18 +7,19 @@ def issue_author_image(issue)
:style => 'width: 20px; height: 20px;'
end
- # Returns array of open issues a user can read
- def readable_open_issues(issues, user)
- issues.select { |i| i.can_read?(user) && i.open? }
- end
-
- # Returns array of closed issues a user can read
+ # Returns array of closed issues that a user can read.
def readable_closed_issues(issues, user)
issues.select { |i| i.can_read?(user) && !i.open? }
end
- # Returns number of readable open issues
- def readable_open_issues_counter(issues, user)
- issues.select { |i| i.can_read?(user) && i.open? }.length
+ # Returns array of open issues that a user can read.
+ def readable_open_issues(issues, user)
+ issues.select { |i| i.can_read?(user) && i.open? }
+ end
+
+ # Returns a user notification counting the number of open issues.
+ def issue_counter(repository, user)
+ count = readable_open_issues(repository.issues, user).length
+ count == 0 ? '' : "(#{count})"
end
end
@@ -83,8 +83,7 @@
repository) %>
</li>
<li>
- <%= link_to "Issues (#{readable_open_issues_counter(repository.issues,
- current_user)})",
+ <%= link_to "Issues #{issue_counter(repository, current_user)}",
profile_repository_issues_path(repository.profile, repository) %>
</li>
<% if repository.can_edit? current_user %>
@@ -1,41 +1,33 @@
require 'test_helper'
class IssuesHelperTest < ActionView::TestCase
- test "readable open issues" do
- readable_issues = readable_open_issues([issues(:public_ghost_pizza),
- issues(:public_ghost_dead_code), issues(:public_ghost_code_language),
- issues(:public_ghost_jquery)], users(:costan))
- assert_equal [issues(:public_ghost_dead_code)], readable_issues
-
- readable_issues = readable_open_issues([issues(:public_ghost_pizza),
- issues(:public_ghost_dead_code), issues(:public_ghost_code_language),
- issues(:public_ghost_jquery)], users(:rms))
- assert_equal [issues(:public_ghost_pizza),
- issues(:public_ghost_dead_code)].sort, readable_issues.sort
+ setup do
+ @repository = repositories(:public_ghost)
+ @issues = @repository.issues
end
test "readable closed issues" do
- readable_issues = readable_closed_issues([issues(:public_ghost_pizza),
- issues(:public_ghost_dead_code), issues(:public_ghost_code_language),
- issues(:public_ghost_jquery)], users(:costan))
- assert_equal [issues(:public_ghost_jquery)], readable_issues
+ assert_equal [issues(:public_ghost_jquery)],
+ readable_closed_issues(@issues, users(:costan))
- readable_issues = readable_closed_issues([issues(:public_ghost_pizza),
- issues(:public_ghost_dead_code), issues(:public_ghost_code_language),
- issues(:public_ghost_jquery)], users(:rms))
- assert_equal [issues(:public_ghost_jquery),
- issues(:public_ghost_code_language)].sort, readable_issues.sort
+ assert_equal [issues(:public_ghost_jquery),
+ issues(:public_ghost_code_language)].sort,
+ readable_closed_issues(@issues, users(:rms)).sort
end
- test "readable open issues counter" do
- num = readable_open_issues_counter([issues(:public_ghost_pizza),
- issues(:public_ghost_dead_code), issues(:public_ghost_code_language),
- issues(:public_ghost_jquery)], users(:costan))
- assert_equal 1, num
+ test "readable open issues" do
+ assert_equal [issues(:public_ghost_dead_code)],
+ readable_open_issues(@issues, users(:costan))
- num = readable_open_issues_counter([issues(:public_ghost_pizza),
- issues(:public_ghost_dead_code), issues(:public_ghost_code_language),
- issues(:public_ghost_jquery)], users(:rms))
- assert_equal 2, num
+ assert_equal [issues(:public_ghost_security_vulnerability),
+ issues(:public_ghost_pizza),
+ issues(:public_ghost_dead_code)].sort,
+ readable_open_issues(@issues, users(:rms)).sort
+ end
+
+ test "open issue counter" do
+ assert_equal '(3)', issue_counter(@repository, users(:rms))
+ assert_equal '(1)', issue_counter(@repository, users(:costan))
+ assert_equal '', issue_counter(Repository.new, users(:costan))
end
end

0 comments on commit 2c08859

Please sign in to comment.