From 481256d48763676d08b68285e4d883cb4057fef9 Mon Sep 17 00:00:00 2001 From: Keilla Menezes Date: Thu, 24 Feb 2011 16:50:45 -0300 Subject: [PATCH] Method target_notification_description for tasks --- app/models/change_password.rb | 4 ++++ app/models/email_activation.rb | 4 ++++ app/models/enterprise_activation.rb | 4 ++++ app/models/invite_friend.rb | 4 ++++ app/models/invite_member.rb | 4 ++++ app/models/task_mailer.rb | 2 +- test/unit/change_password_test.rb | 15 +++++++++++++++ test/unit/email_activation_test.rb | 7 +++++++ test/unit/enterprise_activation_test.rb | 11 +++++++++++ test/unit/invite_friend_test.rb | 8 ++++++++ test/unit/invite_member_test.rb | 9 +++++++++ test/unit/task_mailer_test.rb | 6 +++--- 12 files changed, 74 insertions(+), 4 deletions(-) diff --git a/app/models/change_password.rb b/app/models/change_password.rb index 934eaf3..131a714 100644 --- a/app/models/change_password.rb +++ b/app/models/change_password.rb @@ -78,6 +78,10 @@ class ChangePassword < Task user.force_change_password!(self.password, self.password_confirmation) end + def target_notification_description + _('%{requestor} wants to change its password.') % {:requestor => requestor.name} + end + # overriding messages def task_cancelled_message diff --git a/app/models/email_activation.rb b/app/models/email_activation.rb index 0526124..295f502 100644 --- a/app/models/email_activation.rb +++ b/app/models/email_activation.rb @@ -27,6 +27,10 @@ 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/enterprise_activation.rb b/app/models/enterprise_activation.rb index 99d3e6f..d676639 100644 --- a/app/models/enterprise_activation.rb +++ b/app/models/enterprise_activation.rb @@ -36,4 +36,8 @@ class EnterpriseActivation < Task {:type => :profile_image, :profile => requestor, :url => requestor.url} end + def target_notification_description + _('%{requestor} wants to activate enterprise %{enterprise}.') % {:requestor => requestor.name, :enterprise => enterprise.name} + end + end diff --git a/app/models/invite_friend.rb b/app/models/invite_friend.rb index 0e401ec..b82ada7 100644 --- a/app/models/invite_friend.rb +++ b/app/models/invite_friend.rb @@ -23,6 +23,10 @@ class InviteFriend < Invitation {:type => :profile_image, :profile => requestor, :url => requestor.url} end + def target_notification_description + _('%{requestor} wants to be your friend.') % {:requestor => requestor.name} + end + def permission :manage_friends end diff --git a/app/models/invite_member.rb b/app/models/invite_member.rb index c3214ed..5f9fefe 100644 --- a/app/models/invite_member.rb +++ b/app/models/invite_member.rb @@ -35,6 +35,10 @@ class InviteMember < Invitation {:type => :profile_image, :profile => community, :url => community.url} end + def target_notification_description + _('%{requestor} invited you to join %{community}.') % {:requestor => requestor.name, :community => community.name} + end + def expanded_message super.gsub //, community.name end diff --git a/app/models/task_mailer.rb b/app/models/task_mailer.rb index 693f4a2..31eddca 100644 --- a/app/models/task_mailer.rb +++ b/app/models/task_mailer.rb @@ -52,7 +52,7 @@ class TaskMailer < ActionMailer::Base recipients task.requestor.notification_emails 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 :requestor => task.requestor.name, :message => text, :environment => task.requestor.environment.name, diff --git a/test/unit/change_password_test.rb b/test/unit/change_password_test.rb index a11ffef..4f3ee24 100644 --- a/test/unit/change_password_test.rb +++ b/test/unit/change_password_test.rb @@ -132,4 +132,19 @@ class ChangePasswordTest < Test::Unit::TestCase assert_equal c2.requestor, p2 end + should 'have target notification description' do + person = create_user('testuser', :password => 'test', :password_confirmation => 'test', :email => 'test@example.com').person + + 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 + + assert_match(/#{change.requestor.name} wants to change its password/, change.target_notification_description) + end + end diff --git a/test/unit/email_activation_test.rb b/test/unit/email_activation_test.rb index 9f3f7b5..bafa88a 100644 --- a/test/unit/email_activation_test.rb +++ b/test/unit/email_activation_test.rb @@ -49,4 +49,11 @@ 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) + + assert_match(/#{task.requestor.name} wants to activate the following email: #{task.subject}/, task.target_notification_description) + end + end diff --git a/test/unit/enterprise_activation_test.rb b/test/unit/enterprise_activation_test.rb index d5f9ba4..0d006a8 100644 --- a/test/unit/enterprise_activation_test.rb +++ b/test/unit/enterprise_activation_test.rb @@ -64,5 +64,16 @@ class EnterpriseActivationTest < ActiveSupport::TestCase t.finish 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 + + assert_match(/#{t.requestor.name} wants to activate enterprise #{ent.name}/, t.target_notification_description) + end + + end diff --git a/test/unit/invite_friend_test.rb b/test/unit/invite_friend_test.rb index 32d21a5..e00f208 100644 --- a/test/unit/invite_friend_test.rb +++ b/test/unit/invite_friend_test.rb @@ -120,4 +120,12 @@ class InviteFriendTest < ActiveSupport::TestCase assert !task2.save end + should 'have target notification description' do + p = create_user('testuser1').person + + task = InviteFriend.create!(:person => p, :friend_email => 'test@test.com', :message => '') + + assert_match(/#{task.requestor.name} wants to be your friend./, task.target_notification_description) + end + end diff --git a/test/unit/invite_member_test.rb b/test/unit/invite_member_test.rb index d0ef5d5..9dfbaab 100644 --- a/test/unit/invite_member_test.rb +++ b/test/unit/invite_member_test.rb @@ -95,5 +95,14 @@ class InviteMemberTest < ActiveSupport::TestCase assert !task2.save end + should 'have target notification description' do + p = create_user('testuser1').person + community = fast_create(Community) + + task = InviteMember.create!(:person => p, :friend_email => 'test@test.com', :message => '', :community_id => community.id) + + assert_match(/#{task.requestor.name} invited you to join #{community.name}/, task.target_notification_description) + end + end diff --git a/test/unit/task_mailer_test.rb b/test/unit/task_mailer_test.rb index ebed475..9d3637f 100644 --- a/test/unit/task_mailer_test.rb +++ b/test/unit/task_mailer_test.rb @@ -17,7 +17,7 @@ class TaskMailerTest < Test::Unit::TestCase task = Task.new task.expects(:task_finished_message).returns('the message') - task.expects(:information).returns('the task') + task.expects(:target_notification_description).returns('the task') requestor = mock() requestor.expects(:notification_emails).returns(['requestor@example.com']) @@ -40,7 +40,7 @@ class TaskMailerTest < Test::Unit::TestCase task = Task.new task.expects(:task_cancelled_message).returns('the message') - task.expects(:information).returns('the task') + task.expects(:target_notification_description).returns('the task') requestor = mock() requestor.expects(:notification_emails).returns(['requestor@example.com']) @@ -64,7 +64,7 @@ class TaskMailerTest < Test::Unit::TestCase task = Task.new task.expects(:task_created_message).returns('the message') - task.expects(:information).returns('the task') + task.expects(:target_notification_description).returns('the task') requestor = mock() requestor.expects(:notification_emails).returns(['requestor@example.com']) -- libgit2 0.21.2