Commit dc75897356e87e105a15c16ecd6366176fbb9bd3

Authored by AntonioTerceiro
1 parent 1d34da73

ActionItem36: processing friends


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1488 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/tasks_controller.rb
@@ -4,4 +4,20 @@ class TasksController < MyProfileController @@ -4,4 +4,20 @@ class TasksController < MyProfileController
4 @tasks = profile.tasks.pending 4 @tasks = profile.tasks.pending
5 end 5 end
6 6
  7 + def processed
  8 + @tasks = profile.tasks.finished
  9 + end
  10 +
  11 + VALID_DECISIONS = [ 'finish', 'cancel' ]
  12 +
  13 + def close
  14 + decision = params[:decision]
  15 + if request.post? && VALID_DECISIONS.include?(decision) && params[:id]
  16 + task = Task.find(params[:id])
  17 + task.update_attributes!(params[:task])
  18 + task.send(decision)
  19 + end
  20 + redirect_to :action => 'index'
  21 + end
  22 +
7 end 23 end
app/views/tasks/_add_friend.rhtml
@@ -7,12 +7,12 @@ @@ -7,12 +7,12 @@
7 <% labelled_form_for('task', task, :url => { :action => 'close', :id => task.id } ) do |f| %> 7 <% labelled_form_for('task', task, :url => { :action => 'close', :id => task.id } ) do |f| %>
8 8
9 <div> 9 <div>
10 - <%= radio_button_tag(:action, 'accept', true) %> 10 + <%= radio_button_tag(:decision, 'finish', true) %>
11 <%= _('Accept') %> 11 <%= _('Accept') %>
12 </div> 12 </div>
13 13
14 <div> 14 <div>
15 - <%= radio_button_tag(:action, 'ignore', false) %> 15 + <%= radio_button_tag(:decision, 'cancel', false) %>
16 <%= _('Ignore') %> 16 <%= _('Ignore') %>
17 </div> 17 </div>
18 18
app/views/tasks/index.rhtml
1 -<h1><%= _('Pending tasks') %></h1> 1 +<h1><%= _("%s's pending tasks") % profile.name %></h1>
2 2
3 -<ul class='task-list'>  
4 - <% @tasks.each do |item| %>  
5 - <li><%= render :partial => partial_for_class(item.class), :locals => { :task => item } %></li>  
6 - <% end %>  
7 -</ul> 3 +<% if @tasks.empty? %>
  4 + <p><em><%= _('No pending tasks for %s' % profile.name) %></em></p>
  5 +<% else %>
  6 + <ul class='task-list'>
  7 + <% @tasks.each do |item| %>
  8 + <li><%= render :partial => partial_for_class(item.class), :locals => { :task => item } %></li>
  9 + <% end %>
  10 + </ul>
  11 +<% end %>
  12 +
  13 +<% button_bar do %>
  14 + <%= button(:edit, _('View processed tasks'), :action => 'processed') %>
  15 + <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %>
  16 +<% end %>
app/views/tasks/processed.rhtml 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +<h1><%= _("%s's processed tasks") % profile.name %></h1>
  2 +
  3 +<% if @tasks.empty? %>
  4 + <p><em><%= _('No processed tasks.') %></em></p>
  5 +<% else %>
  6 + <ul>
  7 + <% @tasks.each do |item| %>
  8 + <li><%= item.class.name %></li>
  9 + <% end %>
  10 + </ul>
  11 +<% end %>
  12 +
  13 +<% button_bar do %>
  14 + <%= button(:back, _('Back'), :action => 'index') %>
  15 +<% end %>
test/functional/tasks_controller_test.rb
@@ -13,6 +13,7 @@ class TasksControllerTest &lt; Test::Unit::TestCase @@ -13,6 +13,7 @@ class TasksControllerTest &lt; Test::Unit::TestCase
13 @response = ActionController::TestResponse.new 13 @response = ActionController::TestResponse.new
14 14
15 self.profile = create_user('testuser').person 15 self.profile = create_user('testuser').person
  16 + @controller.stubs(:profile).returns(profile)
16 end 17 end
17 attr_accessor :profile 18 attr_accessor :profile
18 19
@@ -24,10 +25,32 @@ class TasksControllerTest &lt; Test::Unit::TestCase @@ -24,10 +25,32 @@ class TasksControllerTest &lt; Test::Unit::TestCase
24 assert_kind_of Array, assigns(:tasks) 25 assert_kind_of Array, assigns(:tasks)
25 end 26 end
26 27
27 - should 'display form for resolving a task' 28 + should 'list processed tasks' do
  29 + get :processed
28 30
29 - should 'be able to finish a task' 31 + assert_response :success
  32 + assert_template 'processed'
  33 + assert_kind_of Array, assigns(:tasks)
  34 + end
  35 +
  36 + should 'be able to finish a task' do
  37 + t = profile.tasks.build; t.save!
  38 +
  39 + post :close, :decision => 'finish', :id => t.id
  40 + assert_redirected_to :action => 'index'
30 41
31 - should 'be able to cancel a task' 42 + t.reload
  43 + ok('task should be finished') { t.status == Task::Status::FINISHED }
  44 + end
  45 +
  46 + should 'be able to cancel a task' do
  47 + t = profile.tasks.build; t.save!
  48 +
  49 + post :close, :decision => 'cancel', :id => t.id
  50 + assert_redirected_to :action => 'index'
  51 +
  52 + t.reload
  53 + ok('task should be cancelled') { t.status == Task::Status::CANCELLED }
  54 + end
32 55
33 end 56 end