Skip to content

Commit

Permalink
[#5746] Refactor: extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
edavis10 committed May 19, 2011
1 parent 60c3fb6 commit 709d85c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/models/overview_kanban.rb
Expand Up @@ -16,18 +16,17 @@ def filter_issues(issues, filters = {})
filtered_issues = super(issues, filters)
return filtered_issues unless filtered_issues.present?

# First issue sorted by highest priority
highest_priority_issue = filtered_issues.sort {|a,b| a.priority.position <=> b.priority.position}.first
[highest_priority_issue] # expects an Array returned
[extract_highest_priority_issue(filtered_issues)] # expects an Array returned
end

# After filtering issues, extract the highest priority one
def backlog_issues_for(options={})
issues = super
[extract_highest_priority_issue(issues)] # expects an Array returned
end

# First issue sorted by highest priority
highest_priority_issue = issues.sort {|a,b| a.priority.position <=> b.priority.position}.first
[highest_priority_issue] # expects an Array returned
# Returns the first issue sorted by highest priority
def extract_highest_priority_issue(issues)
issues.sort {|a,b| a.priority.position <=> b.priority.position}.first
end

end
27 changes: 27 additions & 0 deletions test/unit/overview_kanban_test.rb
@@ -0,0 +1,27 @@
require File.dirname(__FILE__) + '/../test_helper'

class OverviewKanbanTest < ActiveSupport::TestCase
def setup
@user = User.generate!
User.current = @user
@project = Project.generate!
@kanban = OverviewKanban.new
high_priority
medium_priority
low_priority
end

context "#extract_highest_priority_issue" do
should "return nil with no issues" do
assert_equal nil, @kanban.extract_highest_priority_issue([])
end

should "return the issue with the highest priority (by position)" do
@medium = Issue.generate_for_project!(@project, :priority => medium_priority).reload
@high = Issue.generate_for_project!(@project, :priority => high_priority).reload
@medium2 = Issue.generate_for_project!(@project, :priority => medium_priority).reload
assert_equal @high, @kanban.extract_highest_priority_issue([@medium, @high, @medium2])
end

end
end

0 comments on commit 709d85c

Please sign in to comment.