[noosfero/noosfero][master] 2 commits: Store the person that closes a task
Leandro Nunes
gitlab at gitlab.com
Fri Jun 5 12:02:37 BRT 2015
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
9bfd45df by Victor Costa at 2015-06-05T11:13:24Z
Store the person that closes a task
- - - - -
24429b78 by Leandro Nunes at 2015-06-05T15:02:25Z
Merge branch 'task_closed_by' into 'master'
Store the person that closes a task
See merge request !590
- - - - -
5 changed files:
- app/controllers/my_profile/tasks_controller.rb
- app/models/task.rb
- + db/migrate/20150602142030_add_closed_by_to_task.rb
- test/functional/tasks_controller_test.rb
- test/unit/task_test.rb
Changes:
=====================================
app/controllers/my_profile/tasks_controller.rb
=====================================
--- a/app/controllers/my_profile/tasks_controller.rb
+++ b/app/controllers/my_profile/tasks_controller.rb
@@ -49,7 +49,7 @@ class TasksController < MyProfileController
task = profile.find_in_all_tasks(id)
begin
task.update_attributes(value[:task])
- task.send(decision)
+ task.send(decision, current_person)
rescue Exception => ex
message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})"
failed[ex.message] ? failed[ex.message] << message : failed[ex.message] = [message]
=====================================
app/models/task.rb
=====================================
--- a/app/models/task.rb
+++ b/app/models/task.rb
@@ -34,6 +34,7 @@ class Task < ActiveRecord::Base
belongs_to :requestor, :class_name => 'Profile', :foreign_key => :requestor_id
belongs_to :target, :foreign_key => :target_id, :polymorphic => true
belongs_to :responsible, :class_name => 'Person', :foreign_key => :responsible_id
+ belongs_to :closed_by, :class_name => 'Person', :foreign_key => :closed_by_id
validates_uniqueness_of :code, :on => :create
validates_presence_of :code
@@ -77,11 +78,9 @@ class Task < ActiveRecord::Base
# this method finished the task. It calls #perform, which must be overriden
# by subclasses. At the end a message (as returned by #finish_message) is
# sent to the requestor with #notify_requestor.
- def finish
+ def finish(closed_by=nil)
transaction do
- self.status = Task::Status::FINISHED
- self.end_date = Time.now
- self.save!
+ close(Task::Status::FINISHED, closed_by)
self.perform
begin
send_notification(:finished)
@@ -106,11 +105,9 @@ class Task < ActiveRecord::Base
# this method cancels the task. At the end a message (as returned by
# #cancel_message) is sent to the requestor with #notify_requestor.
- def cancel
+ def cancel(closed_by=nil)
transaction do
- self.status = Task::Status::CANCELLED
- self.end_date = Time.now
- self.save!
+ close(Task::Status::CANCELLED, closed_by)
begin
send_notification(:cancelled)
rescue NotImplementedError => ex
@@ -119,6 +116,13 @@ class Task < ActiveRecord::Base
end
end
+ def close(status, closed_by)
+ self.status = status
+ self.end_date = Time.now
+ self.closed_by = closed_by
+ self.save!
+ end
+
# Here are the tasks customizable options.
def title
=====================================
db/migrate/20150602142030_add_closed_by_to_task.rb
=====================================
--- /dev/null
+++ b/db/migrate/20150602142030_add_closed_by_to_task.rb
@@ -0,0 +1,7 @@
+class AddClosedByToTask < ActiveRecord::Migration
+
+ def change
+ add_column :tasks, :closed_by_id, :integer
+ end
+
+end
=====================================
test/functional/tasks_controller_test.rb
=====================================
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -628,6 +628,12 @@ class TasksControllerTest < ActionController::TestCase
assert_select ".task_responsible select", 0
assert_select ".task_responsible .value"
+ end
+
+ should 'store the person who closes a task' do
+ t = profile.tasks.build; t.save!
+ post :close, :tasks => {t.id => {:decision => 'finish', :task => {}}}
+ assert_equal profile, t.reload.closed_by
end
end
=====================================
test/unit/task_test.rb
=====================================
--- a/test/unit/task_test.rb
+++ b/test/unit/task_test.rb
@@ -440,6 +440,20 @@ class TaskTest < ActiveSupport::TestCase
assert_equal person, task.responsible
end
+ should 'store who finish the task' do
+ t = Task.create
+ person = fast_create(Person)
+ t.finish(person)
+ assert_equal person, t.reload.closed_by
+ end
+
+ should 'store who cancel the task' do
+ t = Task.create
+ person = fast_create(Person)
+ t.cancel(person)
+ assert_equal person, t.reload.closed_by
+ end
+
protected
def sample_user
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/4de02a20556018c58a13de42b258c3b2e779ce09...24429b78d1026a67465c52d9ebe15b5eec0f5abb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150605/5977ce69/attachment.html>
More information about the Noosfero-dev
mailing list