From 39394f370c5666834184b932ecdc38f844d1e061 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Thu, 4 Oct 2007 20:41:50 +0000 Subject: [PATCH] ActionItem96: finishing implementation of tasks and mailing --- app/models/environment.rb | 2 +- app/models/task.rb | 32 ++++++++++++++++++++------------ app/models/task_mailer.rb | 4 ++-- app/views/task_mailer/task_cancelled.text.plain.rhtml | 2 +- app/views/task_mailer/task_finished.text.plain.rhtml | 2 +- db/migrate/017_create_tasks.rb | 2 -- test/unit/environment_test.rb | 7 +++++-- test/unit/task_mailer_test.rb | 1 + test/unit/task_test.rb | 4 ++++ 9 files changed, 35 insertions(+), 21 deletions(-) diff --git a/app/models/environment.rb b/app/models/environment.rb index b1afae4..414fe6e 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -141,7 +141,7 @@ class Environment < ActiveRecord::Base def default_hostname if self.domains(true).empty? - nil + 'localhost.localdomain' else self.domains.find(:first, :order => 'id').name end diff --git a/app/models/task.rb b/app/models/task.rb index 357554a..096f4f1 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -53,18 +53,6 @@ class Task < ActiveRecord::Base end end - protected - - # This method must be overrided in subclasses, and its implementation must do - # the job the task is intended to. This method will be called when the finish - # method is called. - # - # To cancel the finish of the task, you can throw an exception in perform. - # - # The implementation on Task class just does nothing. - def perform - end - # The message that will be sent to the requestor of the task when its # finished. def finish_message @@ -77,4 +65,24 @@ class Task < ActiveRecord::Base _("The task was cancelled at %s") % (self.end_date.to_s) end + # Returns the description of the task. + # + # This method +must+ be overriden in subclasses to return something + # meaningful for each kind of task + def description + _('Generic task') + end + + protected + + # This method must be overrided in subclasses, and its implementation must do + # the job the task is intended to. This method will be called when the finish + # method is called. + # + # To cancel the finish of the task, you can throw an exception in perform. + # + # The implementation on Task class just does nothing. + def perform + end + end diff --git a/app/models/task_mailer.rb b/app/models/task_mailer.rb index 4d5b51e..0100891 100644 --- a/app/models/task_mailer.rb +++ b/app/models/task_mailer.rb @@ -3,7 +3,7 @@ class TaskMailer < ActionMailer::Base def task_finished(task) recipients task.requestor.email from task.requestor.environment.contact_email - subject task + subject task.description body :requestor => task.requestor.name, :message => task.finish_message, :environment => task.requestor.environment.name, @@ -13,7 +13,7 @@ class TaskMailer < ActionMailer::Base def task_cancelled(task) recipients task.requestor.email from task.requestor.environment.contact_email - subject task + subject task.description body :requestor => task.requestor.name, :message => task.cancel_message, :environment => task.requestor.environment.name, diff --git a/app/views/task_mailer/task_cancelled.text.plain.rhtml b/app/views/task_mailer/task_cancelled.text.plain.rhtml index 743f634..e4a52c8 100644 --- a/app/views/task_mailer/task_cancelled.text.plain.rhtml +++ b/app/views/task_mailer/task_cancelled.text.plain.rhtml @@ -1,4 +1,4 @@ -<%= _('Dear %s,') % @requestor %>, +<%= _('Dear %s,') % @requestor %> <%= @message %> diff --git a/app/views/task_mailer/task_finished.text.plain.rhtml b/app/views/task_mailer/task_finished.text.plain.rhtml index 743f634..e4a52c8 100644 --- a/app/views/task_mailer/task_finished.text.plain.rhtml +++ b/app/views/task_mailer/task_finished.text.plain.rhtml @@ -1,4 +1,4 @@ -<%= _('Dear %s,') % @requestor %>, +<%= _('Dear %s,') % @requestor %> <%= @message %> diff --git a/db/migrate/017_create_tasks.rb b/db/migrate/017_create_tasks.rb index 5c045ae..6e5778e 100644 --- a/db/migrate/017_create_tasks.rb +++ b/db/migrate/017_create_tasks.rb @@ -1,8 +1,6 @@ class CreateTasks < ActiveRecord::Migration def self.up create_table :tasks do |t| - t.column :description, :string - t.column :data, :text t.column :status, :integer t.column :end_date, :date diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 7f60fd9..2328281 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -155,10 +155,13 @@ class EnvironmentTest < Test::Unit::TestCase should 'provide a default hostname' do env = Environment.create!(:name => 'test environment') - assert_nil env.default_hostname - env.domains << Domain.create(:name => 'example.com') assert_equal 'example.com', env.default_hostname end + should 'default to localhost.localdomain as hostname' do + env = Environment.create!(:name => 'test environment') + assert_equal 'localhost.localdomain', env.default_hostname + end + end diff --git a/test/unit/task_mailer_test.rb b/test/unit/task_mailer_test.rb index 9c2af7e..bd08fa0 100644 --- a/test/unit/task_mailer_test.rb +++ b/test/unit/task_mailer_test.rb @@ -20,6 +20,7 @@ class TaskMailerTest < Test::Unit::TestCase task = mock() task.expects(:finish_message).returns('the message') + task.expects(:description).returns('the task') requestor = mock() requestor.expects(:email).returns('requestor@example.com') diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb index 4c38132..9e0d7f8 100644 --- a/test/unit/task_test.rb +++ b/test/unit/task_test.rb @@ -76,4 +76,8 @@ class TaskTest < Test::Unit::TestCase end end + should 'provide a description method' do + assert_kind_of String, Task.new.description + end + end -- libgit2 0.21.2