From ac0943b0e0f500a734795676b196d5bde79f0da2 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Sun, 27 Feb 2011 18:50:17 -0300 Subject: [PATCH] Added tests for subject of emails sent --- app/models/email_activation.rb | 4 ---- app/models/task_mailer.rb | 2 +- test/unit/approve_article_test.rb | 8 ++++++++ test/unit/change_password_test.rb | 20 +++++++++++--------- test/unit/email_activation_test.rb | 10 ++++++---- test/unit/enterprise_activation_test.rb | 10 +++------- test/unit/invite_friend_test.rb | 14 ++++++++++++-- test/unit/invite_member_test.rb | 11 +++++++++++ test/unit/task_mailer_test.rb | 2 ++ 9 files changed, 54 insertions(+), 27 deletions(-) diff --git a/app/models/email_activation.rb b/app/models/email_activation.rb index 295f502..0526124 100644 --- a/app/models/email_activation.rb +++ b/app/models/email_activation.rb @@ -27,10 +27,6 @@ class EmailActivation < Task {:type => :profile_image, :profile => requestor, :url => requestor.url} end - def target_notification_description - _("%{requestor} wants to activate the following email: %{subject}.") % {:requestor => requestor.name, :subject => subject } - end - def perform person.user.enable_email! end diff --git a/app/models/task_mailer.rb b/app/models/task_mailer.rb index 31eddca..076adca 100644 --- a/app/models/task_mailer.rb +++ b/app/models/task_mailer.rb @@ -32,7 +32,7 @@ class TaskMailer < ActionMailer::Base recipients task.friend_email from self.class.generate_from(task) - subject '[%s] %s' % [ task.requestor.environment.name, task.information ] + subject '[%s] %s' % [ task.requestor.environment.name, task.target_notification_description ] body :message => msg end diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb index fee663a..6e9d8d8 100644 --- a/test/unit/approve_article_test.rb +++ b/test/unit/approve_article_test.rb @@ -362,6 +362,14 @@ class ApproveArticleTest < ActiveSupport::TestCase assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, email.subject) end + should 'deliver target finished message' do + task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) + + email = TaskMailer.deliver_task_finished(task) + + assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, email.subject) + end + should 'approve an event' do event = fast_create(Event, :profile_id => profile.id, :name => 'Event test', :slug => 'event-test', :abstract => 'Lead of article', :body => 'This is my event') task = ApproveArticle.create!(:name => 'Event test', :article => event, :target => community, :requestor => profile) diff --git a/test/unit/change_password_test.rb b/test/unit/change_password_test.rb index 4f3ee24..b722d4c 100644 --- a/test/unit/change_password_test.rb +++ b/test/unit/change_password_test.rb @@ -133,18 +133,20 @@ class ChangePasswordTest < Test::Unit::TestCase end should 'have target notification description' do - person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person + person = fast_create(Person, :identifier => 'testuser') - change = ChangePassword.new - change.login = 'testuser' - change.email = 'test@example.com' - change.environment_id = Environment.default.id - change.save! - change.password = 'newpass' - change.password_confirmation = 'newpass' - change.finish + change = ChangePassword.create(:login => 'testuser', :email => 'test@example.com', :environment_id => Environment.default.id) assert_match(/#{change.requestor.name} wants to change its password/, change.target_notification_description) end + should 'deliver task created message' do + person = fast_create(Person, :identifier => 'testuser') + + task = ChangePassword.create(:login => 'testuser', :email => 'test@example.com', :environment_id => Environment.default.id) + + email = TaskMailer.deliver_task_created(task) + assert_match(/#{task.requestor.name} wants to change its password/, email.subject) + end + end diff --git a/test/unit/email_activation_test.rb b/test/unit/email_activation_test.rb index bafa88a..4ea7c8d 100644 --- a/test/unit/email_activation_test.rb +++ b/test/unit/email_activation_test.rb @@ -49,11 +49,13 @@ class EmailActivationTest < Test::Unit::TestCase assert !anothertask.save end - should 'have target notification description' do - ze = create_user('zezinho', :environment_id => Environment.default.id) - task = EmailActivation.new(:requestor => ze.person, :target => Environment.default) + should 'deliver activation email notification' do + user = create_user('testuser', :environment_id => Environment.default.id) + + task = EmailActivation.new(:requestor => user.person, :target => Environment.default) - assert_match(/#{task.requestor.name} wants to activate the following email: #{task.subject}/, task.target_notification_description) + email = User::Mailer.deliver_activation_email_notify(user) + assert_match(/Welcome to #{task.requestor.environment.name} mail!/, email.subject) end end diff --git a/test/unit/enterprise_activation_test.rb b/test/unit/enterprise_activation_test.rb index 0d006a8..cb9a124 100644 --- a/test/unit/enterprise_activation_test.rb +++ b/test/unit/enterprise_activation_test.rb @@ -65,15 +65,11 @@ class EnterpriseActivationTest < ActiveSupport::TestCase end should 'have target notification description' do - ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :enabled => false) - t = EnterpriseActivation.create!(:enterprise => ent) - - person = profiles(:ze) - t.requestor = person + ent = fast_create(Enterprise, :enabled => false) + task = EnterpriseActivation.create!(:enterprise => ent, :requestor => profiles(:ze)) - assert_match(/#{t.requestor.name} wants to activate enterprise #{ent.name}/, t.target_notification_description) + assert_match(/#{task.requestor.name} wants to activate enterprise #{ent.name}/, task.target_notification_description) end - end diff --git a/test/unit/invite_friend_test.rb b/test/unit/invite_friend_test.rb index e00f208..2445acf 100644 --- a/test/unit/invite_friend_test.rb +++ b/test/unit/invite_friend_test.rb @@ -121,11 +121,21 @@ class InviteFriendTest < ActiveSupport::TestCase end should 'have target notification description' do - p = create_user('testuser1').person + person = create_user('testuser1').person - task = InviteFriend.create!(:person => p, :friend_email => 'test@test.com', :message => '') + task = InviteFriend.create!(:person => person, :friend_email => 'test@test.com', :message => '') assert_match(/#{task.requestor.name} wants to be your friend./, task.target_notification_description) end + should 'deliver invitation notification' do + person = create_user('testuser1').person + + task = InviteFriend.create!(:person => person, :friend_email => 'test@test.com', :message => '') + + email = TaskMailer.deliver_invitation_notification(task) + + assert_match(/#{task.requestor.name} wants to be your friend./, email.subject) + end + end diff --git a/test/unit/invite_member_test.rb b/test/unit/invite_member_test.rb index 9dfbaab..3ea4cff 100644 --- a/test/unit/invite_member_test.rb +++ b/test/unit/invite_member_test.rb @@ -104,5 +104,16 @@ class InviteMemberTest < ActiveSupport::TestCase assert_match(/#{task.requestor.name} invited you to join #{community.name}/, task.target_notification_description) end + should 'deliver invitation notification' do + person = create_user('testuser1').person + community = fast_create(Community) + + task = InviteMember.create!(:person => person, :friend_email => 'test@test.com', :message => '', :community_id => community.id) + + email = TaskMailer.deliver_invitation_notification(task) + + assert_match(/#{task.requestor.name} invited you to join #{community.name}/, email.subject) + end + end diff --git a/test/unit/task_mailer_test.rb b/test/unit/task_mailer_test.rb index 9d3637f..08d8af6 100644 --- a/test/unit/task_mailer_test.rb +++ b/test/unit/task_mailer_test.rb @@ -129,6 +129,8 @@ class TaskMailerTest < Test::Unit::TestCase mail = TaskMailer.create_invitation_notification(task) + assert_match(/#{task.target_notification_description}/, mail.subject) + assert_equal "Hello friend name, my name invite you, please follow this link: http://example.com/account/signup?invitation_code=123456", mail.body TaskMailer.deliver(mail) -- libgit2 0.21.2