From 2b0420faf2e20fa59d0a5e16b6d6340dab53ed27 Mon Sep 17 00:00:00 2001 From: Michel Felipe de Oliveira Ferreira Date: Tue, 18 Aug 2015 09:35:30 -0300 Subject: [PATCH] Added new method that keep all params filters after perform a task --- app/controllers/my_profile/tasks_controller.rb | 12 ++++++++++-- test/functional/tasks_controller_test.rb | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 78dcee3..4478437 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -65,7 +65,7 @@ class TasksController < MyProfileController session[:notice] = _("Some decisions couldn't be applied.") url[:failed] = failed end - redirect_to url + redirect_with_filters url end def new @@ -76,7 +76,8 @@ class TasksController < MyProfileController @ticket.requestor = profile if request.post? if @ticket.save - redirect_to :action => 'index' + url = {:action => 'index'} + redirect_to url end end end @@ -89,4 +90,11 @@ class TasksController < MyProfileController @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) end + protected + + def redirect_with_filters(url_data) + + filter_params = params.select {|p| p =~ /filter_/} + redirect_to url_data.merge(filter_params) + end end diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 23839c2..5d97172 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -76,6 +76,17 @@ class TasksControllerTest < ActionController::TestCase ok('task should be finished') { t.status == Task::Status::FINISHED } end + should 'keep filters after close a task' do + t = profile.tasks.build; t.save! + + post :close, :tasks => {t.id => {:decision => 'finish', :task => {}}}, :filter_type => t.type + assert_redirected_to :action => 'index', :filter_type => t.type + assert_equal @controller.params[:filter_type], t.type + + 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! @@ -149,7 +160,7 @@ class TasksControllerTest < ActionController::TestCase should 'create a ticket with profile requestor' do post :new, :profile => profile.identifier, :ticket => {:name => 'new task'} - + assert_equal profile, assigns(:ticket).requestor end @@ -628,7 +639,7 @@ class TasksControllerTest < ActionController::TestCase assert_select ".task_responsible select", 0 assert_select ".task_responsible .value" - end + end should 'store the person who closes a task' do t = profile.tasks.build; t.save! -- libgit2 0.21.2