Commit 8f30d072097daa63ddfc32b30af4ab20e6e12417
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
merging with master
Showing
5 changed files
with
39 additions
and
9 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
| ... | ... | @@ -65,7 +65,7 @@ class TasksController < MyProfileController |
| 65 | 65 | task ||= profile.find_in_all_tasks(id) |
| 66 | 66 | begin |
| 67 | 67 | task.update_attributes(value[:task]) |
| 68 | - task.send(decision) | |
| 68 | + task.send(decision, current_person) | |
| 69 | 69 | rescue Exception => ex |
| 70 | 70 | message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" |
| 71 | 71 | failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message] | ... | ... |
app/models/task.rb
| ... | ... | @@ -35,6 +35,7 @@ class Task < ActiveRecord::Base |
| 35 | 35 | belongs_to :requestor, :class_name => 'Profile', :foreign_key => :requestor_id |
| 36 | 36 | belongs_to :target, :foreign_key => :target_id, :polymorphic => true |
| 37 | 37 | belongs_to :responsible, :class_name => 'Person', :foreign_key => :responsible_id |
| 38 | + belongs_to :closed_by, :class_name => 'Person', :foreign_key => :closed_by_id | |
| 38 | 39 | |
| 39 | 40 | validates_uniqueness_of :code, :on => :create |
| 40 | 41 | validates_presence_of :code |
| ... | ... | @@ -78,11 +79,9 @@ class Task < ActiveRecord::Base |
| 78 | 79 | # this method finished the task. It calls #perform, which must be overriden |
| 79 | 80 | # by subclasses. At the end a message (as returned by #finish_message) is |
| 80 | 81 | # sent to the requestor with #notify_requestor. |
| 81 | - def finish | |
| 82 | + def finish(closed_by=nil) | |
| 82 | 83 | transaction do |
| 83 | - self.status = Task::Status::FINISHED | |
| 84 | - self.end_date = Time.now | |
| 85 | - self.save! | |
| 84 | + close(Task::Status::FINISHED, closed_by) | |
| 86 | 85 | self.perform |
| 87 | 86 | begin |
| 88 | 87 | send_notification(:finished) |
| ... | ... | @@ -107,11 +106,9 @@ class Task < ActiveRecord::Base |
| 107 | 106 | |
| 108 | 107 | # this method cancels the task. At the end a message (as returned by |
| 109 | 108 | # #cancel_message) is sent to the requestor with #notify_requestor. |
| 110 | - def cancel | |
| 109 | + def cancel(closed_by=nil) | |
| 111 | 110 | transaction do |
| 112 | - self.status = Task::Status::CANCELLED | |
| 113 | - self.end_date = Time.now | |
| 114 | - self.save! | |
| 111 | + close(Task::Status::CANCELLED, closed_by) | |
| 115 | 112 | begin |
| 116 | 113 | send_notification(:cancelled) |
| 117 | 114 | rescue NotImplementedError => ex |
| ... | ... | @@ -120,6 +117,13 @@ class Task < ActiveRecord::Base |
| 120 | 117 | end |
| 121 | 118 | end |
| 122 | 119 | |
| 120 | + def close(status, closed_by) | |
| 121 | + self.status = status | |
| 122 | + self.end_date = Time.now | |
| 123 | + self.closed_by = closed_by | |
| 124 | + self.save! | |
| 125 | + end | |
| 126 | + | |
| 123 | 127 | # Here are the tasks customizable options. |
| 124 | 128 | |
| 125 | 129 | def title | ... | ... |
test/functional/tasks_controller_test.rb
| ... | ... | @@ -679,6 +679,12 @@ class TasksControllerTest < ActionController::TestCase |
| 679 | 679 | |
| 680 | 680 | assert_select ".task_responsible select", 0 |
| 681 | 681 | assert_select ".task_responsible .value" |
| 682 | + end | |
| 683 | + | |
| 684 | + should 'store the person who closes a task' do | |
| 685 | + t = profile.tasks.build; t.save! | |
| 686 | + post :close, :tasks => {t.id => {:decision => 'finish', :task => {}}} | |
| 687 | + assert_equal profile, t.reload.closed_by | |
| 682 | 688 | end |
| 683 | 689 | |
| 684 | 690 | should 'save task tags' do | ... | ... |
test/unit/task_test.rb
| ... | ... | @@ -485,7 +485,20 @@ class TaskTest < ActiveSupport::TestCase |
| 485 | 485 | |
| 486 | 486 | assert_includes task_one.tags_from(nil), 'test' |
| 487 | 487 | assert_not_includes task_two.tags_from(nil), 'noosfero' |
| 488 | + end | |
| 488 | 489 | |
| 490 | + should 'store who finish the task' do | |
| 491 | + t = Task.create | |
| 492 | + person = fast_create(Person) | |
| 493 | + t.finish(person) | |
| 494 | + assert_equal person, t.reload.closed_by | |
| 495 | + end | |
| 496 | + | |
| 497 | + should 'store who cancel the task' do | |
| 498 | + t = Task.create | |
| 499 | + person = fast_create(Person) | |
| 500 | + t.cancel(person) | |
| 501 | + assert_equal person, t.reload.closed_by | |
| 489 | 502 | end |
| 490 | 503 | |
| 491 | 504 | protected | ... | ... |