Commit 7e431234d84417bdb32e42bd052f16a2f09d4a6f
1 parent
629998e7
Exists in
master
and in
22 other branches
Fixed subject of emails notifications
(ActionItem1829)
Showing
16 changed files
with
212 additions
and
58 deletions
Show diff stats
app/models/add_friend.rb
@@ -23,8 +23,12 @@ class AddFriend < Task | @@ -23,8 +23,12 @@ class AddFriend < Task | ||
23 | :manage_friends | 23 | :manage_friends |
24 | end | 24 | end |
25 | 25 | ||
26 | + def target_notification_description | ||
27 | + _('%{requestor} wants to be your friend.') % {:requestor => requestor.name} | ||
28 | + end | ||
29 | + | ||
26 | def target_notification_message | 30 | def target_notification_message |
27 | - _('%{requestor} wants to be your friend.') % {:requestor => requestor.name} + "\n\n" + | 31 | + target_notification_description + "\n\n" + |
28 | _('You need to login to %{system} in order to accept %{requestor} as your friend.') % { :system => target.environment.name, :requestor => requestor.name } | 32 | _('You need to login to %{system} in order to accept %{requestor} as your friend.') % { :system => target.environment.name, :requestor => requestor.name } |
29 | end | 33 | end |
30 | 34 |
app/models/add_member.rb
@@ -35,8 +35,12 @@ class AddMember < Task | @@ -35,8 +35,12 @@ class AddMember < Task | ||
35 | :manage_memberships | 35 | :manage_memberships |
36 | end | 36 | end |
37 | 37 | ||
38 | + def target_notification_description | ||
39 | + _('%{requestor} wants to be a member of this community.') % {:requestor => requestor.name} | ||
40 | + end | ||
41 | + | ||
38 | def target_notification_message | 42 | def target_notification_message |
39 | - _('%{requestor} wants to be a member of this community.') % {:requestor => requestor.name} + "\n\n" + | 43 | + target_notification_description + "\n\n" + |
40 | _('You will need login to %{system} in order to accept or reject %{requestor} as a member of %{organization}.') % { :system => target.environment.name, :requestor => requestor.name, :organization => organization.name } | 44 | _('You will need login to %{system} in order to accept or reject %{requestor} as a member of %{organization}.') % { :system => target.environment.name, :requestor => requestor.name, :organization => organization.name } |
41 | end | 45 | end |
42 | 46 |
app/models/approve_article.rb
@@ -117,9 +117,13 @@ class ApproveArticle < Task | @@ -117,9 +117,13 @@ class ApproveArticle < Task | ||
117 | article.blank? | 117 | article.blank? |
118 | end | 118 | end |
119 | 119 | ||
120 | + def target_notification_description | ||
121 | + _('%{requestor} wants to publish the article: %{article}.') % {:requestor => requestor.name, :article => article.name} | ||
122 | + end | ||
123 | + | ||
120 | def target_notification_message | 124 | def target_notification_message |
121 | return nil if target.organization? && !target.moderated_articles? | 125 | return nil if target.organization? && !target.moderated_articles? |
122 | - _('%{requestor} wants to publish the article: %{article}.') % {:requestor => requestor.name, :article => article.name} + "\n\n" | 126 | + target_notification_description + "\n\n" + |
123 | _('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name } | 127 | _('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name } |
124 | end | 128 | end |
125 | 129 |
app/models/create_community.rb
@@ -88,6 +88,10 @@ class CreateCommunity < Task | @@ -88,6 +88,10 @@ class CreateCommunity < Task | ||
88 | self.status == Task::Status::FINISHED | 88 | self.status == Task::Status::FINISHED |
89 | end | 89 | end |
90 | 90 | ||
91 | + def target_notification_description | ||
92 | + _('%{requestor} wants to create community %{subject}') % {:requestor => requestor.name, :subject => subject} | ||
93 | + end | ||
94 | + | ||
91 | def target_notification_message | 95 | def target_notification_message |
92 | _("User \"%{user}\" just requested to create community %{community}. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.requestor.name, :community => self.name } | 96 | _("User \"%{user}\" just requested to create community %{community}. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.requestor.name, :community => self.name } |
93 | end | 97 | end |
app/models/create_enterprise.rb
@@ -210,6 +210,10 @@ class CreateEnterprise < Task | @@ -210,6 +210,10 @@ class CreateEnterprise < Task | ||
210 | msg | 210 | msg |
211 | end | 211 | end |
212 | 212 | ||
213 | + def target_notification_description | ||
214 | + _('%{requestor} wants to create enterprise %{subject}.') % {:requestor => requestor.name, :subject => subject} | ||
215 | + end | ||
216 | + | ||
213 | def permission | 217 | def permission |
214 | :validate_enterprise | 218 | :validate_enterprise |
215 | end | 219 | end |
app/models/suggest_article.rb
@@ -56,9 +56,13 @@ class SuggestArticle < Task | @@ -56,9 +56,13 @@ class SuggestArticle < Task | ||
56 | result = {:type => :defined_image, :src => '/images/icons-app/article-minor.png', :name => article_name} | 56 | result = {:type => :defined_image, :src => '/images/icons-app/article-minor.png', :name => article_name} |
57 | end | 57 | end |
58 | 58 | ||
59 | - def target_notification_message | 59 | + def target_notification_description |
60 | _('%{sender} suggested the publication of the article: %{article}.') % | 60 | _('%{sender} suggested the publication of the article: %{article}.') % |
61 | - {:sender => sender, :article => article_name} + "\n\n" + | 61 | + {:sender => sender, :article => article_name} |
62 | + end | ||
63 | + | ||
64 | + def target_notification_message | ||
65 | + target_notification_description + "\n\n" + | ||
62 | _('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name } | 66 | _('You need to login on %{system} in order to approve or reject this article.') % { :system => target.environment.name } |
63 | end | 67 | end |
64 | 68 |
app/models/task.rb
@@ -186,6 +186,10 @@ class Task < ActiveRecord::Base | @@ -186,6 +186,10 @@ class Task < ActiveRecord::Base | ||
186 | raise NotImplementedError, "#{self} does not implement #target_notification_message" | 186 | raise NotImplementedError, "#{self} does not implement #target_notification_message" |
187 | end | 187 | end |
188 | 188 | ||
189 | + def target_notification_description | ||
190 | + '' | ||
191 | + end | ||
192 | + | ||
189 | # What permission is required to perform task? | 193 | # What permission is required to perform task? |
190 | def permission | 194 | def permission |
191 | :perform_task | 195 | :perform_task |
app/models/task_mailer.rb
@@ -17,7 +17,7 @@ class TaskMailer < ActionMailer::Base | @@ -17,7 +17,7 @@ class TaskMailer < ActionMailer::Base | ||
17 | url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.url.merge(:controller => 'tasks', :action => 'index')) | 17 | url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.url.merge(:controller => 'tasks', :action => 'index')) |
18 | 18 | ||
19 | from self.class.generate_from(task) | 19 | from self.class.generate_from(task) |
20 | - subject '[%s] %s' % [task.environment.name, task.information] | 20 | + subject '[%s] %s' % [task.environment.name, task.target_notification_description] |
21 | body :target => task.target.name, | 21 | body :target => task.target.name, |
22 | :message => msg, | 22 | :message => msg, |
23 | :environment => task.environment.name, | 23 | :environment => task.environment.name, |
test/unit/add_friend_test.rb
@@ -2,31 +2,32 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -2,31 +2,32 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
2 | 2 | ||
3 | class AddFriendTest < ActiveSupport::TestCase | 3 | class AddFriendTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | + def setup | ||
6 | + @person1 = create_user('testuser1').person | ||
7 | + @person2 = create_user('testuser2').person | ||
8 | + end | ||
9 | + attr_reader :person1, :person2 | ||
10 | + | ||
5 | should 'be a task' do | 11 | should 'be a task' do |
6 | ok { AddFriend.new.kind_of?(Task) } | 12 | ok { AddFriend.new.kind_of?(Task) } |
7 | end | 13 | end |
8 | 14 | ||
9 | should 'actually create friendships (two way) when confirmed' do | 15 | should 'actually create friendships (two way) when confirmed' do |
10 | - p1 = create_user('testuser1').person | ||
11 | - p2 = create_user('testuser2').person | ||
12 | 16 | ||
13 | - task = fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id, :target_type => 'Person') | 17 | + task = fast_create(AddFriend, :requestor_id => person1.id, :target_id => person2.id, :target_type => 'Person') |
14 | 18 | ||
15 | assert_difference Friendship, :count, 2 do | 19 | assert_difference Friendship, :count, 2 do |
16 | task.finish | 20 | task.finish |
17 | end | 21 | end |
18 | - p1.friends.reload | ||
19 | - p2.friends.reload | 22 | + person1.friends.reload |
23 | + person2.friends.reload | ||
20 | 24 | ||
21 | - ok('p1 should have p2 as friend') { p1.friends.include?(p2) } | ||
22 | - ok('p2 should have p1 as friend') { p2.friends.include?(p1) } | 25 | + ok('person1 should have person2 as friend') { person1.friends.include?(person2) } |
26 | + ok('person2 should have person1 as friend') { person2.friends.include?(person1) } | ||
23 | end | 27 | end |
24 | 28 | ||
25 | should 'put friendships in the right groups' do | 29 | should 'put friendships in the right groups' do |
26 | - p1 = create_user('testuser1').person | ||
27 | - p2 = create_user('testuser2').person | ||
28 | - | ||
29 | - task = fast_create(AddFriend, :requestor_id => p1, :target_id => p2.id, :target_type => 'Person') | 30 | + task = fast_create(AddFriend, :requestor_id => person1, :target_id => person2.id, :target_type => 'Person') |
30 | task.group_for_person = 'friend1' | 31 | task.group_for_person = 'friend1' |
31 | task.group_for_friend = 'friend2' | 32 | task.group_for_friend = 'friend2' |
32 | assert task.save | 33 | assert task.save |
@@ -35,8 +36,8 @@ class AddFriendTest < ActiveSupport::TestCase | @@ -35,8 +36,8 @@ class AddFriendTest < ActiveSupport::TestCase | ||
35 | task.finish | 36 | task.finish |
36 | end | 37 | end |
37 | 38 | ||
38 | - ok('p1 should list p2 as friend1') { p1.friendships.first.group == 'friend1' } | ||
39 | - ok('p2 should have p1 as friend2') { p2.friendships.first.group == 'friend2' } | 39 | + ok('person1 should list person2 as friend1') { person1.friendships.first.group == 'friend1' } |
40 | + ok('person2 should have person1 as friend2') { person2.friendships.first.group == 'friend2' } | ||
40 | end | 41 | end |
41 | 42 | ||
42 | should 'require requestor (person adding other as friend)' do | 43 | should 'require requestor (person adding other as friend)' do |
@@ -63,12 +64,9 @@ class AddFriendTest < ActiveSupport::TestCase | @@ -63,12 +64,9 @@ class AddFriendTest < ActiveSupport::TestCase | ||
63 | end | 64 | end |
64 | 65 | ||
65 | should 'send e-mails' do | 66 | should 'send e-mails' do |
66 | - p1 = create_user('testuser1').person | ||
67 | - p2 = create_user('testuser2').person | ||
68 | - | ||
69 | TaskMailer.expects(:deliver_target_notification).at_least_once | 67 | TaskMailer.expects(:deliver_target_notification).at_least_once |
70 | 68 | ||
71 | - task = AddFriend.create!(:person => p1, :friend => p2) | 69 | + task = AddFriend.create!(:person => person1, :friend => person2) |
72 | end | 70 | end |
73 | 71 | ||
74 | should 'has permission to manage friends' do | 72 | should 'has permission to manage friends' do |
@@ -77,18 +75,14 @@ class AddFriendTest < ActiveSupport::TestCase | @@ -77,18 +75,14 @@ class AddFriendTest < ActiveSupport::TestCase | ||
77 | end | 75 | end |
78 | 76 | ||
79 | should 'not add friend twice' do | 77 | should 'not add friend twice' do |
80 | - p1 = create_user('testuser1').person | ||
81 | - p2 = create_user('testuser2').person | ||
82 | - fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id) | 78 | + fast_create(AddFriend, :requestor_id => person1.id, :target_id => person2.id) |
83 | assert_raise ActiveRecord::RecordInvalid do | 79 | assert_raise ActiveRecord::RecordInvalid do |
84 | - AddFriend.create!(:person => p1, :friend => p2) | 80 | + AddFriend.create!(:person => person1, :friend => person2) |
85 | end | 81 | end |
86 | end | 82 | end |
87 | 83 | ||
88 | should 'override target notification message method from Task' do | 84 | should 'override target notification message method from Task' do |
89 | - p1 = create_user('testuser1').person | ||
90 | - p2 = create_user('testuser2').person | ||
91 | - task = AddFriend.new(:person => p1, :friend => p2) | 85 | + task = AddFriend.new(:person => person1, :friend => person2) |
92 | assert_nothing_raised NotImplementedError do | 86 | assert_nothing_raised NotImplementedError do |
93 | task.target_notification_message | 87 | task.target_notification_message |
94 | end | 88 | end |
@@ -122,5 +116,23 @@ class AddFriendTest < ActiveSupport::TestCase | @@ -122,5 +116,23 @@ class AddFriendTest < ActiveSupport::TestCase | ||
122 | assert !task.errors[:group_for_friend] | 116 | assert !task.errors[:group_for_friend] |
123 | end | 117 | end |
124 | 118 | ||
119 | + should 'have target notification message if is organization and not moderated' do | ||
120 | + task = AddFriend.new(:person => person1, :friend => person2) | ||
121 | + | ||
122 | + assert_match(/wants to be your friend.*[\n]*.*to accept/, task.target_notification_message) | ||
123 | + end | ||
124 | + | ||
125 | + should 'have target notification description' do | ||
126 | + task = AddFriend.new(:person => person1, :friend => person2) | ||
127 | + | ||
128 | + assert_match(/#{task.requestor.name} wants to be your friend/, task.target_notification_description) | ||
129 | + end | ||
130 | + | ||
131 | + should 'deliver target notification message' do | ||
132 | + task = AddFriend.new(:person => person1, :friend => person2) | ||
133 | + | ||
134 | + email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | ||
135 | + assert_match(/#{task.requestor.name} wants to be your friend/, email.subject) | ||
136 | + end | ||
125 | 137 | ||
126 | end | 138 | end |
test/unit/add_member_test.rb
@@ -2,19 +2,24 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -2,19 +2,24 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
2 | 2 | ||
3 | class AddMemberTest < ActiveSupport::TestCase | 3 | class AddMemberTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | + def setup | ||
6 | + @person = fast_create(Person) | ||
7 | + @community = fast_create(Community) | ||
8 | + end | ||
9 | + attr_reader :person, :community | ||
10 | + | ||
11 | + | ||
5 | should 'be a task' do | 12 | should 'be a task' do |
6 | ok { AddMember.new.kind_of?(Task) } | 13 | ok { AddMember.new.kind_of?(Task) } |
7 | end | 14 | end |
8 | 15 | ||
9 | should 'actually add memberships when confirmed' do | 16 | should 'actually add memberships when confirmed' do |
10 | - p = create_user('testuser1').person | ||
11 | - c = fast_create(Community, :name => 'closed community') | ||
12 | - c.update_attribute(:closed, true) | 17 | + community.update_attribute(:closed, true) |
13 | TaskMailer.stubs(:deliver_target_notification) | 18 | TaskMailer.stubs(:deliver_target_notification) |
14 | - task = fast_create(AddMember, :requestor_id => p.id, :target_id => c.id, :target_type => 'Community') | 19 | + task = fast_create(AddMember, :requestor_id => person.id, :target_id => community.id, :target_type => 'Community') |
15 | task.finish | 20 | task.finish |
16 | 21 | ||
17 | - assert_equal [p], c.members | 22 | + assert_equal [person], community.members |
18 | end | 23 | end |
19 | 24 | ||
20 | should 'require requestor' do | 25 | should 'require requestor' do |
@@ -40,13 +45,11 @@ class AddMemberTest < ActiveSupport::TestCase | @@ -40,13 +45,11 @@ class AddMemberTest < ActiveSupport::TestCase | ||
40 | end | 45 | end |
41 | 46 | ||
42 | should 'send e-mails' do | 47 | should 'send e-mails' do |
43 | - p = create_user('testuser1').person | ||
44 | - c = fast_create(Community, :name => 'closed community') | ||
45 | - c.update_attribute(:closed, true) | 48 | + community.update_attribute(:closed, true) |
46 | 49 | ||
47 | TaskMailer.expects(:deliver_target_notification).at_least_once | 50 | TaskMailer.expects(:deliver_target_notification).at_least_once |
48 | 51 | ||
49 | - task = AddMember.create!(:person => p, :organization => c) | 52 | + task = AddMember.create!(:person => person, :organization => community) |
50 | end | 53 | end |
51 | 54 | ||
52 | should 'has permission to manage members' do | 55 | should 'has permission to manage members' do |
@@ -55,47 +58,56 @@ class AddMemberTest < ActiveSupport::TestCase | @@ -55,47 +58,56 @@ class AddMemberTest < ActiveSupport::TestCase | ||
55 | end | 58 | end |
56 | 59 | ||
57 | should 'have roles' do | 60 | should 'have roles' do |
58 | - p = create_user('testuser1').person | ||
59 | - c = fast_create(Community, :name => 'community_test') | ||
60 | TaskMailer.stubs(:deliver_target_notification) | 61 | TaskMailer.stubs(:deliver_target_notification) |
61 | - task = AddMember.create!(:roles => [1,2,3], :person => p, :organization => c) | 62 | + task = AddMember.create!(:roles => [1,2,3], :person => person, :organization => community) |
62 | assert_equal [1,2,3], task.roles | 63 | assert_equal [1,2,3], task.roles |
63 | end | 64 | end |
64 | 65 | ||
65 | should 'put member with the right roles' do | 66 | should 'put member with the right roles' do |
66 | - p = create_user('testuser1').person | ||
67 | - c = fast_create(Community, :name => 'community_test') | ||
68 | - | ||
69 | - roles = [Profile::Roles.member(c.environment.id), Profile::Roles.admin(c.environment.id)] | 67 | + roles = [Profile::Roles.member(community.environment.id), Profile::Roles.admin(community.environment.id)] |
70 | TaskMailer.stubs(:deliver_target_notification) | 68 | TaskMailer.stubs(:deliver_target_notification) |
71 | - task = AddMember.create!(:roles => roles.map(&:id), :person => p, :organization => c) | 69 | + task = AddMember.create!(:roles => roles.map(&:id), :person => person, :organization => community) |
72 | task.finish | 70 | task.finish |
73 | 71 | ||
74 | - current_roles = p.find_roles(c).map(&:role) | 72 | + current_roles = person.find_roles(community).map(&:role) |
75 | assert_includes current_roles, roles[0] | 73 | assert_includes current_roles, roles[0] |
76 | assert_includes current_roles, roles[1] | 74 | assert_includes current_roles, roles[1] |
77 | end | 75 | end |
78 | 76 | ||
79 | should 'override target notification message method from Task' do | 77 | should 'override target notification message method from Task' do |
80 | - p1 = create_user('testuser1').person | ||
81 | - p2 = create_user('testuser2').person | ||
82 | - task = AddFriend.new(:person => p1, :friend => p2) | 78 | + task = AddMember.new(:person => person, :organization => community) |
83 | assert_nothing_raised NotImplementedError do | 79 | assert_nothing_raised NotImplementedError do |
84 | task.target_notification_message | 80 | task.target_notification_message |
85 | end | 81 | end |
86 | end | 82 | end |
87 | 83 | ||
88 | should 'ignore roles with id zero' do | 84 | should 'ignore roles with id zero' do |
89 | - p = create_user('testuser1').person | ||
90 | - c = fast_create(Community, :name => 'community_test') | ||
91 | - | ||
92 | - role = Profile::Roles.member(c.environment.id) | 85 | + role = Profile::Roles.member(community.environment.id) |
93 | TaskMailer.stubs(:deliver_target_notification) | 86 | TaskMailer.stubs(:deliver_target_notification) |
94 | - task = AddMember.create!(:roles => ["0", role.id, nil], :person => p, :organization => c) | 87 | + task = AddMember.create!(:roles => ["0", role.id, nil], :person => person, :organization => community) |
95 | task.finish | 88 | task.finish |
96 | 89 | ||
97 | - current_roles = p.find_roles(c).map(&:role) | 90 | + current_roles = person.find_roles(community).map(&:role) |
98 | assert_includes current_roles, role | 91 | assert_includes current_roles, role |
99 | end | 92 | end |
100 | 93 | ||
94 | + should 'have target notification message' do | ||
95 | + task = AddMember.new(:person => person, :organization => community) | ||
96 | + | ||
97 | + assert_match(/#{person.name} wants to be a member of this community.*[\n]*.*to accept or reject/, task.target_notification_message) | ||
98 | + end | ||
99 | + | ||
100 | + should 'have target notification description' do | ||
101 | + task = AddMember.new(:person => person, :organization => community) | ||
102 | + | ||
103 | + assert_match(/#{task.requestor.name} wants to be a member of this community/, task.target_notification_description) | ||
104 | + end | ||
105 | + | ||
106 | + should 'deliver target notification message' do | ||
107 | + task = AddMember.new(:person => person, :organization => community) | ||
108 | + | ||
109 | + email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | ||
110 | + assert_match(/#{task.requestor.name} wants to be a member of this community/, email.subject) | ||
111 | + end | ||
112 | + | ||
101 | end | 113 | end |
test/unit/approve_article_test.rb
@@ -330,5 +330,36 @@ class ApproveArticleTest < ActiveSupport::TestCase | @@ -330,5 +330,36 @@ class ApproveArticleTest < ActiveSupport::TestCase | ||
330 | assert_equal article.is_trackable?, article.class.last.is_trackable? | 330 | assert_equal article.is_trackable?, article.class.last.is_trackable? |
331 | end | 331 | end |
332 | 332 | ||
333 | + should 'not have target notification message if it is not a moderated oganization' do | ||
334 | + community.moderated_articles = false; community.save | ||
335 | + task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) | ||
336 | + | ||
337 | + assert_nil task.target_notification_message | ||
338 | + end | ||
339 | + | ||
340 | + should 'have target notification message if is organization and not moderated' do | ||
341 | + task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) | ||
342 | + | ||
343 | + community.expects(:moderated_articles?).returns(['true']) | ||
344 | + | ||
345 | + assert_match(/wants to publish the article.*[\n]*.*to approve or reject/, task.target_notification_message) | ||
346 | + end | ||
347 | + | ||
348 | + should 'have target notification description' do | ||
349 | + community.moderated_articles = false; community.save | ||
350 | + task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) | ||
351 | + | ||
352 | + assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, task.target_notification_description) | ||
353 | + end | ||
354 | + | ||
355 | + should 'deliver target notification message' do | ||
356 | + task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) | ||
357 | + | ||
358 | + community.expects(:notification_emails).returns(['target@example.com']) | ||
359 | + community.expects(:moderated_articles?).returns(['true']) | ||
360 | + | ||
361 | + email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | ||
362 | + assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, email.subject) | ||
363 | + end | ||
333 | 364 | ||
334 | end | 365 | end |
test/unit/create_community_test.rb
@@ -83,4 +83,23 @@ class CreateCommunityTest < Test::Unit::TestCase | @@ -83,4 +83,23 @@ class CreateCommunityTest < Test::Unit::TestCase | ||
83 | assert_equal 'rails.png', Community['my-new-community'].image.filename | 83 | assert_equal 'rails.png', Community['my-new-community'].image.filename |
84 | end | 84 | end |
85 | 85 | ||
86 | + should 'have target notification message' do | ||
87 | + task = CreateCommunity.new(:name => 'community test', :target => Environment.default, :requestor => person) | ||
88 | + | ||
89 | + assert_match(/requested to create community.*to approve or reject/, task.target_notification_message) | ||
90 | + end | ||
91 | + | ||
92 | + should 'have target notification description' do | ||
93 | + task = CreateCommunity.new(:name => 'community test', :target => Environment.default, :requestor => person) | ||
94 | + | ||
95 | + assert_match(/#{task.requestor.name} wants to create community #{task.subject}/, task.target_notification_description) | ||
96 | + end | ||
97 | + | ||
98 | + should 'deliver target notification message' do | ||
99 | + task = CreateCommunity.new(:name => 'community test', :target => Environment.default, :requestor => person) | ||
100 | + | ||
101 | + email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | ||
102 | + assert_match(/#{task.requestor.name} wants to create community #{task.subject}/, email.subject) | ||
103 | + end | ||
104 | + | ||
86 | end | 105 | end |
test/unit/create_enterprise_test.rb
@@ -2,6 +2,11 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -2,6 +2,11 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
2 | 2 | ||
3 | class CreateEnterpriseTest < Test::Unit::TestCase | 3 | class CreateEnterpriseTest < Test::Unit::TestCase |
4 | 4 | ||
5 | + def setup | ||
6 | + @person = fast_create(Person) | ||
7 | + end | ||
8 | + attr_reader :person | ||
9 | + | ||
5 | should 'provide needed data' do | 10 | should 'provide needed data' do |
6 | task = CreateEnterprise.new | 11 | task = CreateEnterprise.new |
7 | 12 | ||
@@ -253,4 +258,25 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -253,4 +258,25 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
253 | t = CreateEnterprise.new | 258 | t = CreateEnterprise.new |
254 | assert_equal :validate_enterprise, t.permission | 259 | assert_equal :validate_enterprise, t.permission |
255 | end | 260 | end |
261 | + | ||
262 | + should 'have target notification message' do | ||
263 | + task = CreateEnterprise.new(:name => 'My enterprise', :requestor => person, :target => Environment.default) | ||
264 | + | ||
265 | + assert_match(/#{task.name}.*requested to enter #{person.environment}.*approve or reject/, task.target_notification_message) | ||
266 | + end | ||
267 | + | ||
268 | + should 'have target notification description' do | ||
269 | + task = CreateEnterprise.new(:name => 'My enterprise', :requestor => person, :target => Environment.default) | ||
270 | + | ||
271 | + assert_match(/#{task.requestor.name} wants to create enterprise #{task.subject}/, task.target_notification_description) | ||
272 | + end | ||
273 | + | ||
274 | + should 'deliver target notification message' do | ||
275 | + task = CreateEnterprise.new(:name => 'My enterprise', :requestor => person, :target => Environment.default) | ||
276 | + | ||
277 | + email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | ||
278 | + | ||
279 | + assert_match(/#{task.requestor.name} wants to create enterprise #{task.subject}/, email.subject) | ||
280 | + end | ||
281 | + | ||
256 | end | 282 | end |
test/unit/suggest_article_test.rb
@@ -134,4 +134,25 @@ class SuggestArticleTest < ActiveSupport::TestCase | @@ -134,4 +134,25 @@ class SuggestArticleTest < ActiveSupport::TestCase | ||
134 | assert_equal 'some name', article.author_name | 134 | assert_equal 'some name', article.author_name |
135 | end | 135 | end |
136 | 136 | ||
137 | + should 'have target notification message' do | ||
138 | + task = build(SuggestArticle, :target => @profile, :article_name => 'suggested article', :name => 'johndoe') | ||
139 | + | ||
140 | + assert_match(/#{task.name}.*suggested the publication of the article: #{task.subject}.*[\n]*.*to approve or reject/, task.target_notification_message) | ||
141 | + end | ||
142 | + | ||
143 | + should 'have target notification description' do | ||
144 | + task = build(SuggestArticle,:target => @profile, :article_name => 'suggested article', :name => 'johndoe') | ||
145 | + | ||
146 | + assert_match(/#{task.name}.*suggested the publication of the article: #{task.subject}/, task.target_notification_description) | ||
147 | + end | ||
148 | + | ||
149 | + should 'deliver target notification message' do | ||
150 | + task = build(SuggestArticle, :target => @profile, :article_name => 'suggested article', :name => 'johndoe', :email => 'johndoe@example.com') | ||
151 | + | ||
152 | + email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | ||
153 | + | ||
154 | + assert_match(/#{task.name}.*suggested the publication of the article: #{task.subject}/, email.subject) | ||
155 | + end | ||
156 | + | ||
157 | + | ||
137 | end | 158 | end |
test/unit/task_mailer_test.rb
@@ -85,7 +85,7 @@ class TaskMailerTest < Test::Unit::TestCase | @@ -85,7 +85,7 @@ class TaskMailerTest < Test::Unit::TestCase | ||
85 | 85 | ||
86 | should 'be able to send a "target notification" message' do | 86 | should 'be able to send a "target notification" message' do |
87 | task = Task.new | 87 | task = Task.new |
88 | - task.expects(:information).returns('the task') | 88 | + task.expects(:target_notification_description).returns('the task') |
89 | 89 | ||
90 | target = mock() | 90 | target = mock() |
91 | target.expects(:notification_emails).returns(['target@example.com']) | 91 | target.expects(:notification_emails).returns(['target@example.com']) |
test/unit/task_test.rb
@@ -232,6 +232,11 @@ class TaskTest < Test::Unit::TestCase | @@ -232,6 +232,11 @@ class TaskTest < Test::Unit::TestCase | ||
232 | assert_equal task.environment, nil | 232 | assert_equal task.environment, nil |
233 | end | 233 | end |
234 | 234 | ||
235 | + should 'have blank string on target_notification_description in Task base class' do | ||
236 | + task = Task.new | ||
237 | + assert_equal '', task.target_notification_description | ||
238 | + end | ||
239 | + | ||
235 | protected | 240 | protected |
236 | 241 | ||
237 | def sample_user | 242 | def sample_user |