Signed-off-by: Benjamin LAN-SUN-LUK <benjamin.lan-sun-luk(a)supinfo.com>
---
app/controllers/sprints_controller.rb | 22 ++++++++++++++--------
app/models/sprint.rb | 10 ++++++++++
app/views/sprints/show.html.erb | 2 +-
test/functional/sprints_controller_test.rb | 14 ++++++++++++++
4 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/app/controllers/sprints_controller.rb
b/app/controllers/sprints_controller.rb
index 09ebe5b..a0b318f 100644
--- a/app/controllers/sprints_controller.rb
+++ b/app/controllers/sprints_controller.rb
@@ -87,15 +87,21 @@ class SprintsController < ApplicationController
def update
respond_to do |format|
if @sprint.can_edit?(@user)
- @sprint.update_attributes(params[:sprint])
-
- if @sprint.save
- flash[:message] = "Sprint updated successfully."
- format.html { redirect_to params[:url] ? params[:url] :
product_sprints_path(@product) }
+ unless @sprint.allowed_status?(params[:sprint][:status] ||
@sprint.status)
+ flash[:error] = "Sprints with work history cannot be moved to the
planned state."
+ format.html { redirect_to :action => :show }
else
- @title = "Sprint #{(a)sprint.id} (Edit)"
- @sprint.valid?
- format.html { render :action => :edit }
+
+ @sprint.update_attributes(params[:sprint])
+
+ if @sprint.save
+ flash[:message] = "Sprint updated successfully."
+ format.html { redirect_to params[:url] ? params[:url] :
product_sprints_path(@product) }
+ else
+ @title = "Sprint #{(a)sprint.id} (Edit)"
+ @sprint.valid?
+ format.html { render :action => :edit }
+ end
end
else
flash[:error] = "You are now allowed to edit sprints for
#{(a)product.name}."
diff --git a/app/models/sprint.rb b/app/models/sprint.rb
index 2638613..da092ee 100644
--- a/app/models/sprint.rb
+++ b/app/models/sprint.rb
@@ -171,4 +171,14 @@ class Sprint < ActiveRecord::Base
return false
end
+
+ # Check if the sprint is active and have tasks againsts him.
+ def has_activity?
+ status == STATUS_ACTIVE && !actual_hours.zero?
+ end
+
+ # Check if the sprint can move to this new status
+ def allowed_status?(new_status)
+ !(has_activity? && new_status.to_i == STATUS_PLANNED)
+ end
end
diff --git a/app/views/sprints/show.html.erb
b/app/views/sprints/show.html.erb
index 0b826c6..5b60810 100644
--- a/app/views/sprints/show.html.erb
+++ b/app/views/sprints/show.html.erb
@@ -49,7 +49,7 @@
<% form_for(:sprint, @sprint, :url =>
product_sprint_path(@product, @sprint),
:html => {:method => :put}) do |form| %>
<%= hidden_field_tag :url, product_sprint_url(@product,
@sprint) %>
- <%= select :sprint, :status, Sprint::STATUS_TEXT %>
+ <%= select :sprint, :status, Sprint::STATUS_TEXT -
(@sprint.has_activity? ? [Sprint::STATUS_TEXT[Sprint::STATUS_PLANNED]] : [])
%>
<%= submit_tag "Apply" %>
<% end %>
<% else %>
diff --git a/test/functional/sprints_controller_test.rb
b/test/functional/sprints_controller_test.rb
index 3bb0eda..bd61c0e 100644
--- a/test/functional/sprints_controller_test.rb
+++ b/test/functional/sprints_controller_test.rb
@@ -298,6 +298,20 @@ class SprintsControllerTest <
ActionController::TestCase
"Sprint should have been updated."
end
+ # Ensures that can't updating a sprint with the active status to the
planned status if sprint got work history.
+ def test_update_with_unallowed_status
+ sprint = {:title => "Do it!", :status => Sprint::STATUS_ACTIVE}
+ put :update,
+ {:product_id => @product.id, :id => @active_sprint.id,
+ :sprint => sprint},
+ {:user_id => @owner.id, :status => Sprint::STATUS_PLANNED}
+
+ assert_redirected_to product_sprints_path(@product)
+ result = Sprint.find_by_id((a)active_sprint.id)
+ assert_equal Sprint::STATUS_ACTIVE, result.status,
+ "Sprint should have not been updated."
+ end
+
# Ensures anonymous users can't delete sprins.
def test_delete_as_anonymous
delete :destroy
--
1.6.0.2
Show replies by date