Commit 39394f370c5666834184b932ecdc38f844d1e061
1 parent
8ff8c9c1
Exists in
master
and in
29 other branches
ActionItem96: finishing implementation of tasks and mailing
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@623 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
35 additions
and
21 deletions
Show diff stats
app/models/environment.rb
@@ -141,7 +141,7 @@ class Environment < ActiveRecord::Base | @@ -141,7 +141,7 @@ class Environment < ActiveRecord::Base | ||
141 | 141 | ||
142 | def default_hostname | 142 | def default_hostname |
143 | if self.domains(true).empty? | 143 | if self.domains(true).empty? |
144 | - nil | 144 | + 'localhost.localdomain' |
145 | else | 145 | else |
146 | self.domains.find(:first, :order => 'id').name | 146 | self.domains.find(:first, :order => 'id').name |
147 | end | 147 | end |
app/models/task.rb
@@ -53,18 +53,6 @@ class Task < ActiveRecord::Base | @@ -53,18 +53,6 @@ class Task < ActiveRecord::Base | ||
53 | end | 53 | end |
54 | end | 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 | # The message that will be sent to the requestor of the task when its | 56 | # The message that will be sent to the requestor of the task when its |
69 | # finished. | 57 | # finished. |
70 | def finish_message | 58 | def finish_message |
@@ -77,4 +65,24 @@ class Task < ActiveRecord::Base | @@ -77,4 +65,24 @@ class Task < ActiveRecord::Base | ||
77 | _("The task was cancelled at %s") % (self.end_date.to_s) | 65 | _("The task was cancelled at %s") % (self.end_date.to_s) |
78 | end | 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 | end | 88 | end |
app/models/task_mailer.rb
@@ -3,7 +3,7 @@ class TaskMailer < ActionMailer::Base | @@ -3,7 +3,7 @@ class TaskMailer < ActionMailer::Base | ||
3 | def task_finished(task) | 3 | def task_finished(task) |
4 | recipients task.requestor.email | 4 | recipients task.requestor.email |
5 | from task.requestor.environment.contact_email | 5 | from task.requestor.environment.contact_email |
6 | - subject task | 6 | + subject task.description |
7 | body :requestor => task.requestor.name, | 7 | body :requestor => task.requestor.name, |
8 | :message => task.finish_message, | 8 | :message => task.finish_message, |
9 | :environment => task.requestor.environment.name, | 9 | :environment => task.requestor.environment.name, |
@@ -13,7 +13,7 @@ class TaskMailer < ActionMailer::Base | @@ -13,7 +13,7 @@ class TaskMailer < ActionMailer::Base | ||
13 | def task_cancelled(task) | 13 | def task_cancelled(task) |
14 | recipients task.requestor.email | 14 | recipients task.requestor.email |
15 | from task.requestor.environment.contact_email | 15 | from task.requestor.environment.contact_email |
16 | - subject task | 16 | + subject task.description |
17 | body :requestor => task.requestor.name, | 17 | body :requestor => task.requestor.name, |
18 | :message => task.cancel_message, | 18 | :message => task.cancel_message, |
19 | :environment => task.requestor.environment.name, | 19 | :environment => task.requestor.environment.name, |
app/views/task_mailer/task_cancelled.text.plain.rhtml
app/views/task_mailer/task_finished.text.plain.rhtml
db/migrate/017_create_tasks.rb
1 | class CreateTasks < ActiveRecord::Migration | 1 | class CreateTasks < ActiveRecord::Migration |
2 | def self.up | 2 | def self.up |
3 | create_table :tasks do |t| | 3 | create_table :tasks do |t| |
4 | - t.column :description, :string | ||
5 | - | ||
6 | t.column :data, :text | 4 | t.column :data, :text |
7 | t.column :status, :integer | 5 | t.column :status, :integer |
8 | t.column :end_date, :date | 6 | t.column :end_date, :date |
test/unit/environment_test.rb
@@ -155,10 +155,13 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -155,10 +155,13 @@ class EnvironmentTest < Test::Unit::TestCase | ||
155 | 155 | ||
156 | should 'provide a default hostname' do | 156 | should 'provide a default hostname' do |
157 | env = Environment.create!(:name => 'test environment') | 157 | env = Environment.create!(:name => 'test environment') |
158 | - assert_nil env.default_hostname | ||
159 | - | ||
160 | env.domains << Domain.create(:name => 'example.com') | 158 | env.domains << Domain.create(:name => 'example.com') |
161 | assert_equal 'example.com', env.default_hostname | 159 | assert_equal 'example.com', env.default_hostname |
162 | end | 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 | end | 167 | end |
test/unit/task_mailer_test.rb
@@ -20,6 +20,7 @@ class TaskMailerTest < Test::Unit::TestCase | @@ -20,6 +20,7 @@ class TaskMailerTest < Test::Unit::TestCase | ||
20 | 20 | ||
21 | task = mock() | 21 | task = mock() |
22 | task.expects(:finish_message).returns('the message') | 22 | task.expects(:finish_message).returns('the message') |
23 | + task.expects(:description).returns('the task') | ||
23 | 24 | ||
24 | requestor = mock() | 25 | requestor = mock() |
25 | requestor.expects(:email).returns('requestor@example.com') | 26 | requestor.expects(:email).returns('requestor@example.com') |
test/unit/task_test.rb