When a user adds, edits or deletes a task, then an entry is added to the
product's RSS feed.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/tasks_controller.rb | 17 ++++++++++++++---
app/views/tasks/_edit.html.erb | 3 ++-
doc/ChangeLog | 1 +
test/functional/tasks_controller_test.rb | 12 ++++++++++++
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb
index 13ccb0e..622f8d3 100644
--- a/app/controllers/tasks_controller.rb
+++ b/app/controllers/tasks_controller.rb
@@ -70,7 +70,9 @@ class TasksController < ApplicationController
report_error "Backup must be a member of the sprint team."
else
respond_to do |format|
- if @task.save && @task.backlog_item.save
+ add_product_rss_entry("#{(a)user.display_name} added a new #{(a)task.hours}
hour task.",
+ "#{(a)task.description}")
+ if @task.save && @task.backlog_item.save &&
@task.backlog_item.sprint.product.save
flash[:message] = "Recorded #{(a)task.hours} hours against this backlog
item."
format.html { redirect_to task_path(@task) }
else
@@ -89,7 +91,9 @@ class TasksController < ApplicationController
@task.update_attributes(params[:task])
respond_to do |format|
- if @task.save
+ add_product_rss_entry("#{(a)user.display_name} updated task
#{(a)task.id}.",
+ "#{(a)task.description}")
+ if @task.save && @task.backlog_item.sprint.product.save
flash[:message] = "Task successfully updated."
format.html { redirect_to task_path(@task) }
else
@@ -104,7 +108,9 @@ class TasksController < ApplicationController
# DELETE /tasks/1
def destroy
Task.transaction do
- if @task.destroy
+ add_product_rss_entry("#{(a)user.display_name} deleted task #{(a)task.id}.",
+ "#{(a)task.description}")
+ if @task.destroy && @task.backlog_item.sprint.product.save
flash[:message] = "Task has been deleted."
respond_to do |format|
format.html { redirect_to tasks_path(:user => @user) }
@@ -164,6 +170,11 @@ class TasksController < ApplicationController
@users = User.for_sprint((a)sprint.id)
end
+ def add_product_rss_entry(title, content)
+ product = @task.backlog_item.sprint.product
+ product.rss_entries << create_rss_entry(title, item_path((a)task.backlog_item),
content, @user)
+ end
+
def path_to_list
if @this_user
add_breadcrumb "Users", users_path
diff --git a/app/views/tasks/_edit.html.erb b/app/views/tasks/_edit.html.erb
index cd189d0..f5c9b52 100644
--- a/app/views/tasks/_edit.html.erb
+++ b/app/views/tasks/_edit.html.erb
@@ -1,6 +1,7 @@
<div id="content-no-sidebar">
<% html = @task.new_record? ? {:method => :post} : {:method => :put} %>
- <% form_for(:task, @task, :url => @task.new_record? ? tasks_path(:item =>
@backlog_item) : tasks_path(@task), :html => html) do |form| %>
+ <% url = @task.new_record? ? tasks_path(:item => @backlog_item) :
task_path(@task) %>
+ <% form_for(:task, @task, :url => url, :html => html) do |form| %>
<%= hidden_field_tag :item, @backlog_item.id %>
<table class="edit">
<caption><%= "#{(a)task.new_record? ? 'Create' : 'Edit'}
A Task" %></caption>
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 9e1aaa8..5567684 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -42,6 +42,7 @@ Change Log (0.3.0):
* #209 - A blocked item is shown in a different color on the item list page.
* #210 - Epics with no user stories should only be deleted. (BUG)
* #211 - Backlog item events show up in the product's RSS feed.
+ * #212 - Task events show up in the product's RSS feed.
* #213 - Users can disable receiving emails when replies are posted.
* #216 - The user's most recent postings are displayed on their details page.
* #217 - All of a user's posts can be viewed.
diff --git a/test/functional/tasks_controller_test.rb
b/test/functional/tasks_controller_test.rb
index 24eaa29..fd6c726 100644
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -221,22 +221,28 @@ class TasksControllerTest < ActionController::TestCase
# Ensures that creating a task works as expected.
def test_create
+ count = @item.sprint.product.rss_entries.size
post :create, { :item => @item.id, :task => @new_task }, { :user_id =>
@owner.id }
result = Task.find_by_description(@new_task[:description])
assert result, "Task should have been created."
assert_redirected_to task_path(result)
assert !result.backlog_item.completed?, "Backlog item should not have been
marked completed."
+ newcount = Product.find_by_id((a)item.sprint.product_id).rss_entries.size
+ assert_equal count + 1, newcount, "A new RSS entry should have been
added."
end
# Ensures that creating a task that marks the item completed works as expected.
def test_create_and_complete
+ count = @item.sprint.product.rss_entries.size
post :create, {:item => @item.id, :task => @new_task, :completed => true},
{:user_id => @owner.id}
result = Task.find_by_description(@new_task[:description])
assert result, "Task should have been created."
assert_redirected_to task_path(result)
assert result.backlog_item.completed?, "Item should have been marked as
completed."
+ newcount = Product.find_by_id((a)item.sprint.product_id).rss_entries.size
+ assert_equal count + 1, newcount, "A new RSS entry should have been
added."
end
# Ensures anonymous users can't update a task.
@@ -272,11 +278,14 @@ class TasksControllerTest < ActionController::TestCase
# Ensures that an update works.
def test_update
+ count = @item.sprint.product.rss_entries.size
put :update, { :id => @task.id, :task => { :hours => 12.5 }}, { :user_id
=> @owner.id }
assert_redirected_to task_path(@task)
assert_equal 12.5, Task.find_by_id((a)task.id).hours,
"Hours hould have been updated."
+ newcount = Product.find_by_id((a)item.sprint.product_id).rss_entries.size
+ assert_equal count + 1, newcount, "A new RSS entry should have been
added."
end
# Ensures that anonymous users cannot delete tasks.
@@ -302,9 +311,12 @@ class TasksControllerTest < ActionController::TestCase
# Ensures that delete a task works as expected.
def test_delete
+ count = @item.sprint.product.rss_entries.size
delete :destroy, { :id => @task.id }, { :user_id => @owner.id }
assert_redirected_to tasks_path(:user => @owner.id)
assert !Task.find_by_id((a)task.id), "Task should have been deleted."
+ newcount = Product.find_by_id((a)item.sprint.product_id).rss_entries.size
+ assert_equal count + 1, newcount, "A new RSS entry should have been
added."
end
end
--
1.6.2.5