Commit 39394f370c5666834184b932ecdc38f844d1e061

Authored by AntonioTerceiro
1 parent 8ff8c9c1

ActionItem96: finishing implementation of tasks and mailing

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@623 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/environment.rb
... ... @@ -141,7 +141,7 @@ class Environment < ActiveRecord::Base
141 141  
142 142 def default_hostname
143 143 if self.domains(true).empty?
144   - nil
  144 + 'localhost.localdomain'
145 145 else
146 146 self.domains.find(:first, :order => 'id').name
147 147 end
... ...
app/models/task.rb
... ... @@ -53,18 +53,6 @@ class Task < ActiveRecord::Base
53 53 end
54 54 end
55 55  
56   - protected
57   -
58   - # This method must be overrided in subclasses, and its implementation must do
59   - # the job the task is intended to. This method will be called when the finish
60   - # method is called.
61   - #
62   - # To cancel the finish of the task, you can throw an exception in perform.
63   - #
64   - # The implementation on Task class just does nothing.
65   - def perform
66   - end
67   -
68 56 # The message that will be sent to the requestor of the task when its
69 57 # finished.
70 58 def finish_message
... ... @@ -77,4 +65,24 @@ class Task < ActiveRecord::Base
77 65 _("The task was cancelled at %s") % (self.end_date.to_s)
78 66 end
79 67  
  68 + # Returns the description of the task.
  69 + #
  70 + # This method +must+ be overriden in subclasses to return something
  71 + # meaningful for each kind of task
  72 + def description
  73 + _('Generic task')
  74 + end
  75 +
  76 + protected
  77 +
  78 + # This method must be overrided in subclasses, and its implementation must do
  79 + # the job the task is intended to. This method will be called when the finish
  80 + # method is called.
  81 + #
  82 + # To cancel the finish of the task, you can throw an exception in perform.
  83 + #
  84 + # The implementation on Task class just does nothing.
  85 + def perform
  86 + end
  87 +
80 88 end
... ...
app/models/task_mailer.rb
... ... @@ -3,7 +3,7 @@ class TaskMailer < ActionMailer::Base
3 3 def task_finished(task)
4 4 recipients task.requestor.email
5 5 from task.requestor.environment.contact_email
6   - subject task
  6 + subject task.description
7 7 body :requestor => task.requestor.name,
8 8 :message => task.finish_message,
9 9 :environment => task.requestor.environment.name,
... ... @@ -13,7 +13,7 @@ class TaskMailer < ActionMailer::Base
13 13 def task_cancelled(task)
14 14 recipients task.requestor.email
15 15 from task.requestor.environment.contact_email
16   - subject task
  16 + subject task.description
17 17 body :requestor => task.requestor.name,
18 18 :message => task.cancel_message,
19 19 :environment => task.requestor.environment.name,
... ...
app/views/task_mailer/task_cancelled.text.plain.rhtml
1   -<%= _('Dear %s,') % @requestor %>,
  1 +<%= _('Dear %s,') % @requestor %>
2 2  
3 3 <%= @message %>
4 4  
... ...
app/views/task_mailer/task_finished.text.plain.rhtml
1   -<%= _('Dear %s,') % @requestor %>,
  1 +<%= _('Dear %s,') % @requestor %>
2 2  
3 3 <%= @message %>
4 4  
... ...
db/migrate/017_create_tasks.rb
1 1 class CreateTasks < ActiveRecord::Migration
2 2 def self.up
3 3 create_table :tasks do |t|
4   - t.column :description, :string
5   -
6 4 t.column :data, :text
7 5 t.column :status, :integer
8 6 t.column :end_date, :date
... ...
test/unit/environment_test.rb
... ... @@ -155,10 +155,13 @@ class EnvironmentTest &lt; Test::Unit::TestCase
155 155  
156 156 should 'provide a default hostname' do
157 157 env = Environment.create!(:name => 'test environment')
158   - assert_nil env.default_hostname
159   -
160 158 env.domains << Domain.create(:name => 'example.com')
161 159 assert_equal 'example.com', env.default_hostname
162 160 end
163 161  
  162 + should 'default to localhost.localdomain as hostname' do
  163 + env = Environment.create!(:name => 'test environment')
  164 + assert_equal 'localhost.localdomain', env.default_hostname
  165 + end
  166 +
164 167 end
... ...
test/unit/task_mailer_test.rb
... ... @@ -20,6 +20,7 @@ class TaskMailerTest &lt; Test::Unit::TestCase
20 20  
21 21 task = mock()
22 22 task.expects(:finish_message).returns('the message')
  23 + task.expects(:description).returns('the task')
23 24  
24 25 requestor = mock()
25 26 requestor.expects(:email).returns('requestor@example.com')
... ...
test/unit/task_test.rb
... ... @@ -76,4 +76,8 @@ class TaskTest &lt; Test::Unit::TestCase
76 76 end
77 77 end
78 78  
  79 + should 'provide a description method' do
  80 + assert_kind_of String, Task.new.description
  81 + end
  82 +
79 83 end
... ...