ACK
--
Benjamin LAN-SUN-LUK



Le 22/03/09 15:09, « Darryl L. Pierce » <mcpierce@gmail.com> a écrit :

Also made the unit tests around the can_reopen? rule more robust.

Signed-off-by: Darryl L. Pierce <mcpierce@gmail.com>
---
 app/models/backlog_item.rb       |    6 +++++-
 app/models/sprint.rb             |    2 +-
 app/views/sprints/_edit.html.erb |    2 +-
 test/unit/backlog_item_test.rb   |   36 ++++++++++++++++++++++++------------
 4 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/app/models/backlog_item.rb b/app/models/backlog_item.rb
index 4fd4501..37a81e9 100644
--- a/app/models/backlog_item.rb
+++ b/app/models/backlog_item.rb
@@ -173,7 +173,7 @@ class BacklogItem < ActiveRecord::Base

   # Returns whether the user can reopen this backlog item.
   def can_reopen?(user)
-    (owner?(user) || product_owner?(user)) &&
+    (owner?(user) || product_owner?(user) || team_lead?(user)) &&
       [STATE_COMPLETED, STATE_CANCELED].include?(state)
   end

@@ -186,4 +186,8 @@ class BacklogItem < ActiveRecord::Base
   def product_owner?(user)
     user && (sprint.product.owner.id == user.id)
   end
+
+  def team_lead?(user)
+    user && (sprint.team_lead.id == user.id)
+  end
 end
diff --git a/app/models/sprint.rb b/app/models/sprint.rb
index cd99d4d..596580e 100644
--- a/app/models/sprint.rb
+++ b/app/models/sprint.rb
@@ -134,7 +134,7 @@ class Sprint < ActiveRecord::Base
   def can_populate?(user)
     user &&
       ((user.id == product.owner.id) ||
-       (user.id == sprint.team_lead_id)) &&
+       (user.id == team_lead_id)) &&
       pending?
   end

diff --git a/app/views/sprints/_edit.html.erb b/app/views/sprints/_edit.html.erb
index 9fca540..26ef5d8 100644
--- a/app/views/sprints/_edit.html.erb
+++ b/app/views/sprints/_edit.html.erb
@@ -26,7 +26,7 @@
          <td class="value">
            <%= collection_select :sprint, :team_lead_id, @product.users, :id,
                :display_name, {:include_blank => false} %>
-           <%= error_message_on (:sprint, :team_lead_id) %>
+           <%= error_message_on(:sprint, :team_lead_id) %>
          </td>
        </tr>

diff --git a/test/unit/backlog_item_test.rb b/test/unit/backlog_item_test.rb
index c80c54a..bce39c6 100644
--- a/test/unit/backlog_item_test.rb
+++ b/test/unit/backlog_item_test.rb
@@ -36,6 +36,12 @@ class BacklogItemTest < ActiveSupport::TestCase
     @unowned_backlog_item = backlog_items(:unowned_backlog_item)
     raise "Unowned items must not have an owner!" if @unowned_backlog_item.owner

+    @closed_backlog_item = backlog_items(:closed_backlog_item)
+    raise "Closed items must be closed!" unless @closed_backlog_item.completed?
+
+    @nonmember = users(:celliot)
+    raise "Nonmember cannot be on the product team!" if @closed_backlog_item.sprint.product.is_member?(@nonmember)
+
     @item_on_inactive_sprint = backlog_items(:inactive_sprint_backlog_item)
     raise "Item should not have an owner!" if @item_on_inactive_sprint.owner
     raise "That sprint must no be active!" if @item_on_inactive_sprint.sprint.active?
@@ -46,7 +52,6 @@ class BacklogItemTest < ActiveSupport::TestCase
   end

   # Ensures that a sprint is required.
-  #
   def test_valid_fails_without_sprint
     @item.sprint_id = nil

@@ -54,7 +59,6 @@ class BacklogItemTest < ActiveSupport::TestCase
   end

   # Ensures that a user story is required.
-  #
   def test_valid_fails_without_user_story
     @item.user_story_id = nil

@@ -62,14 +66,12 @@ class BacklogItemTest < ActiveSupport::TestCase
   end

   # Ensures a well-formed story passes validation.
-  #
   def test_valid
     flunk "Something's fundamentally wrong." unless @item.valid?
   end

   # Ensures that the default value for remaining hours is the original estimated
   # hours.
-  #
   def test_remaining_when_undefined
     @item.estimated_hours = 2.5

@@ -80,7 +82,6 @@ class BacklogItemTest < ActiveSupport::TestCase

   # Ensures that adding a new remaining hours estimation affects the hours
   # reported.
-  #
   def test_remaining_hours_when_updated
     @item.estimated_hours = 5.0
     @item.remaining_hours_estimates << RemainingHoursEstimate.new(:hours => 2.5, :estimated_on => Date.today.next)
@@ -91,51 +92,62 @@ class BacklogItemTest < ActiveSupport::TestCase
   end

   # Ensures that a user can accept an unowned backlog item.
-  #
   def test_accept_an_unowned_item
     assert @unowned_backlog_item.can_accept?(@owner),
       "Users must be able to accept backlog items."
   end

   # Ensures that a user cannot accept an item on a non-active sprint.
-  #
   def test_accept_on_item_on_inactive_sprint
     assert !@item_on_inactive_sprint.can_accept?(@owner),
       "Users must not be allowed to accept items on inactive sprints."
   end

   # Ensures that a user cannot accept an already accepted backlog item.
-  #
   def test_accept_on_owned_backlog_item
     assert !@owned_backlog_item.can_accept?(@owner),
       "Users cannot accept an owned backlog item."
   end

   # Ensures that a user can drop a backlog item on an active sprint.
-  #
   def test_drop_on_backlog_item_on_closed_sprint
     assert !@item_on_closed_sprint.can_drop?(@owner),
       "Users cannot drop an item on a closed sprint."
   end

   # Ensures that a non-owner can't drop an owned sprint.
-  #
   def test_drop_for_nonowner
     assert !@owned_backlog_item.can_drop?(@nonowner),
       "Someone who doens't own a backlog item can't drop it!"
   end

   # Ensures that nobody can drop an unowned backlog item.
-  #
   def test_drop_for_unowned_item
     assert !@unowned_backlog_item.can_drop?(@owner),
       "You can't drop a backlog item that's not owned!"
   end

   # Ensures that the owner can drop a backlog item.
-  #
   def test_drop
     assert @owned_backlog_item.can_drop?(@owner),
       "The owern has to be able to drop a backlog item."
   end
+
+  # Ensures that not just anybody can reopen a backlog item
+  def test_reopen_by_anybody
+    assert !@closed_backlog_item.can_reopen?(@nonmember)
+  end
+
+  # Ensures that the item owner can reopen a backlog item.
+  def test_reopen_by_owner
+    assert @closed_backlog_item.can_reopen?(@closed_backlog_item.owner)
+  end
+
+  # Ensures that a team lead can reopen a backlog item.
+  def test_team_lead_can_reopen
+    team_lead = @closed_backlog_item.sprint.team_lead
+
+    assert @closed_backlog_item.can_reopen?(team_lead),
+    "Team leads must be able to reopen completed tasks."
+  end
 end
--
1.6.0.6

_______________________________________________
projxp-devel mailing list
projxp-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/projxp-devel