From dc75897356e87e105a15c16ecd6366176fbb9bd3 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 22 Feb 2008 23:07:47 +0000 Subject: [PATCH] ActionItem36: processing friends --- app/controllers/my_profile/tasks_controller.rb | 16 ++++++++++++++++ app/views/tasks/_add_friend.rhtml | 4 ++-- app/views/tasks/index.rhtml | 21 +++++++++++++++------ app/views/tasks/processed.rhtml | 15 +++++++++++++++ test/functional/tasks_controller_test.rb | 29 ++++++++++++++++++++++++++--- 5 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 app/views/tasks/processed.rhtml diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 1f4371d..0049f8c 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -4,4 +4,20 @@ class TasksController < MyProfileController @tasks = profile.tasks.pending end + def processed + @tasks = profile.tasks.finished + end + + VALID_DECISIONS = [ 'finish', 'cancel' ] + + def close + decision = params[:decision] + if request.post? && VALID_DECISIONS.include?(decision) && params[:id] + task = Task.find(params[:id]) + task.update_attributes!(params[:task]) + task.send(decision) + end + redirect_to :action => 'index' + end + end diff --git a/app/views/tasks/_add_friend.rhtml b/app/views/tasks/_add_friend.rhtml index 8ed59fa..8cc9272 100644 --- a/app/views/tasks/_add_friend.rhtml +++ b/app/views/tasks/_add_friend.rhtml @@ -7,12 +7,12 @@ <% labelled_form_for('task', task, :url => { :action => 'close', :id => task.id } ) do |f| %>
- <%= radio_button_tag(:action, 'accept', true) %> + <%= radio_button_tag(:decision, 'finish', true) %> <%= _('Accept') %>
- <%= radio_button_tag(:action, 'ignore', false) %> + <%= radio_button_tag(:decision, 'cancel', false) %> <%= _('Ignore') %>
diff --git a/app/views/tasks/index.rhtml b/app/views/tasks/index.rhtml index 14430c3..20583e4 100644 --- a/app/views/tasks/index.rhtml +++ b/app/views/tasks/index.rhtml @@ -1,7 +1,16 @@ -

<%= _('Pending tasks') %>

+

<%= _("%s's pending tasks") % profile.name %>

- +<% if @tasks.empty? %> +

<%= _('No pending tasks for %s' % profile.name) %>

+<% else %> + +<% end %> + +<% button_bar do %> + <%= button(:edit, _('View processed tasks'), :action => 'processed') %> + <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> +<% end %> diff --git a/app/views/tasks/processed.rhtml b/app/views/tasks/processed.rhtml new file mode 100644 index 0000000..d0db19a --- /dev/null +++ b/app/views/tasks/processed.rhtml @@ -0,0 +1,15 @@ +

<%= _("%s's processed tasks") % profile.name %>

+ +<% if @tasks.empty? %> +

<%= _('No processed tasks.') %>

+<% else %> + +<% end %> + +<% button_bar do %> + <%= button(:back, _('Back'), :action => 'index') %> +<% end %> diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 88acb06..efcb0af 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -13,6 +13,7 @@ class TasksControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new self.profile = create_user('testuser').person + @controller.stubs(:profile).returns(profile) end attr_accessor :profile @@ -24,10 +25,32 @@ class TasksControllerTest < Test::Unit::TestCase assert_kind_of Array, assigns(:tasks) end - should 'display form for resolving a task' + should 'list processed tasks' do + get :processed - should 'be able to finish a task' + assert_response :success + assert_template 'processed' + assert_kind_of Array, assigns(:tasks) + end + + should 'be able to finish a task' do + t = profile.tasks.build; t.save! + + post :close, :decision => 'finish', :id => t.id + assert_redirected_to :action => 'index' - should 'be able to cancel a task' + t.reload + ok('task should be finished') { t.status == Task::Status::FINISHED } + end + + should 'be able to cancel a task' do + t = profile.tasks.build; t.save! + + post :close, :decision => 'cancel', :id => t.id + assert_redirected_to :action => 'index' + + t.reload + ok('task should be cancelled') { t.status == Task::Status::CANCELLED } + end end -- libgit2 0.21.2