@@ -0,0 +1,22 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | class DocumentObserver < ActiveRecord::Observer | |
|
19 | def after_create(document) | |
|
20 | Mailer.deliver_document_added(document) if Setting.notified_events.include?('document_added') | |
|
21 | end | |
|
22 | end |
@@ -0,0 +1,22 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | class IssueObserver < ActiveRecord::Observer | |
|
19 | def after_create(issue) | |
|
20 | Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added') | |
|
21 | end | |
|
22 | end |
@@ -0,0 +1,22 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | class JournalObserver < ActiveRecord::Observer | |
|
19 | def after_create(journal) | |
|
20 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
|
21 | end | |
|
22 | end |
@@ -0,0 +1,22 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | class NewsObserver < ActiveRecord::Observer | |
|
19 | def after_create(news) | |
|
20 | Mailer.deliver_news_added(news) if Setting.notified_events.include?('news_added') | |
|
21 | end | |
|
22 | end |
@@ -48,7 +48,6 class DocumentsController < ApplicationController | |||
|
48 | 48 | if request.post? and @document.save |
|
49 | 49 | attach_files(@document, params[:attachments]) |
|
50 | 50 | flash[:notice] = l(:notice_successful_create) |
|
51 | Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added') | |
|
52 | 51 | redirect_to :action => 'index', :project_id => @project |
|
53 | 52 | end |
|
54 | 53 | end |
@@ -146,7 +146,6 class IssuesController < ApplicationController | |||
|
146 | 146 | if @issue.save |
|
147 | 147 | attach_files(@issue, params[:attachments]) |
|
148 | 148 | flash[:notice] = l(:notice_successful_create) |
|
149 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') | |
|
150 | 149 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
151 | 150 | redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } : |
|
152 | 151 | { :action => 'show', :id => @issue }) |
@@ -193,7 +192,6 class IssuesController < ApplicationController | |||
|
193 | 192 | if !journal.new_record? |
|
194 | 193 | # Only send notification if something was actually changed |
|
195 | 194 | flash[:notice] = l(:notice_successful_update) |
|
196 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
|
197 | 195 | end |
|
198 | 196 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) |
|
199 | 197 | redirect_to(params[:back_to] || {:action => 'show', :id => @issue}) |
@@ -247,10 +245,7 class IssuesController < ApplicationController | |||
|
247 | 245 | issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty? |
|
248 | 246 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
249 | 247 | # Don't save any change to the issue if the user is not authorized to apply the requested status |
|
250 |
|
|
|
251 | # Send notification for each issue (if changed) | |
|
252 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') | |
|
253 | else | |
|
248 | unless (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save | |
|
254 | 249 | # Keep unsaved issue ids to display them in flash error |
|
255 | 250 | unsaved_issue_ids << issue.id |
|
256 | 251 | end |
@@ -45,7 +45,6 class NewsController < ApplicationController | |||
|
45 | 45 | @news.attributes = params[:news] |
|
46 | 46 | if @news.save |
|
47 | 47 | flash[:notice] = l(:notice_successful_create) |
|
48 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') | |
|
49 | 48 | redirect_to :controller => 'news', :action => 'index', :project_id => @project |
|
50 | 49 | end |
|
51 | 50 | end |
@@ -113,7 +113,6 class Changeset < ActiveRecord::Base | |||
|
113 | 113 | issue.status = fix_status |
|
114 | 114 | issue.done_ratio = done_ratio if done_ratio |
|
115 | 115 | issue.save |
|
116 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
|
117 | 116 | end |
|
118 | 117 | end |
|
119 | 118 | referenced_issues += target_issues |
@@ -110,13 +110,11 class MailHandler < ActionMailer::Base | |||
|
110 | 110 | end |
|
111 | 111 | h |
|
112 | 112 | end |
|
113 | # add To and Cc as watchers before saving so the watchers can reply to Redmine | |
|
114 | add_watchers(issue) | |
|
113 | 115 | issue.save! |
|
114 | 116 | add_attachments(issue) |
|
115 | 117 | logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info |
|
116 | # add To and Cc as watchers | |
|
117 | add_watchers(issue) | |
|
118 | # send notification after adding watchers so that they can reply to Redmine | |
|
119 | Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added') | |
|
120 | 118 | issue |
|
121 | 119 | end |
|
122 | 120 | |
@@ -148,7 +146,6 class MailHandler < ActionMailer::Base | |||
|
148 | 146 | end |
|
149 | 147 | issue.save! |
|
150 | 148 | logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info |
|
151 | Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated') | |
|
152 | 149 | journal |
|
153 | 150 | end |
|
154 | 151 |
@@ -36,7 +36,7 Rails::Initializer.run do |config| | |||
|
36 | 36 | |
|
37 | 37 | # Activate observers that should always be running |
|
38 | 38 | # config.active_record.observers = :cacher, :garbage_collector |
|
39 | config.active_record.observers = :message_observer | |
|
39 | config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer | |
|
40 | 40 | |
|
41 | 41 | # Make Active Record use UTC-base instead of local time |
|
42 | 42 | # config.active_record.default_timezone = :utc |
@@ -66,6 +66,8 class DocumentsControllerTest < Test::Unit::TestCase | |||
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_new_with_one_attachment |
|
69 | ActionMailer::Base.deliveries.clear | |
|
70 | Setting.notified_events << 'document_added' | |
|
69 | 71 | @request.session[:user_id] = 2 |
|
70 | 72 | set_tmp_attachments_directory |
|
71 | 73 | |
@@ -82,6 +84,7 class DocumentsControllerTest < Test::Unit::TestCase | |||
|
82 | 84 | assert_equal Enumeration.find(2), document.category |
|
83 | 85 | assert_equal 1, document.attachments.size |
|
84 | 86 | assert_equal 'testfile.txt', document.attachments.first.filename |
|
87 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
85 | 88 | end |
|
86 | 89 | |
|
87 | 90 | def test_edit_routing |
@@ -503,6 +503,21 class IssuesControllerTest < Test::Unit::TestCase | |||
|
503 | 503 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
504 | 504 | end |
|
505 | 505 | |
|
506 | def test_post_new_should_send_a_notification | |
|
507 | ActionMailer::Base.deliveries.clear | |
|
508 | @request.session[:user_id] = 2 | |
|
509 | post :new, :project_id => 1, | |
|
510 | :issue => {:tracker_id => 3, | |
|
511 | :subject => 'This is the test_new issue', | |
|
512 | :description => 'This is the description', | |
|
513 | :priority_id => 5, | |
|
514 | :estimated_hours => '', | |
|
515 | :custom_field_values => {'2' => 'Value for field 2'}} | |
|
516 | assert_redirected_to :action => 'show' | |
|
517 | ||
|
518 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
519 | end | |
|
520 | ||
|
506 | 521 | def test_post_should_preserve_fields_values_on_validation_failure |
|
507 | 522 | @request.session[:user_id] = 2 |
|
508 | 523 | post :new, :project_id => 1, |
@@ -761,6 +776,20 class IssuesControllerTest < Test::Unit::TestCase | |||
|
761 | 776 | assert ActionMailer::Base.deliveries.empty? |
|
762 | 777 | end |
|
763 | 778 | |
|
779 | def test_post_edit_should_send_a_notification | |
|
780 | @request.session[:user_id] = 2 | |
|
781 | ActionMailer::Base.deliveries.clear | |
|
782 | issue = Issue.find(1) | |
|
783 | old_subject = issue.subject | |
|
784 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
|
785 | ||
|
786 | post :edit, :id => 1, :issue => {:subject => new_subject, | |
|
787 | :priority_id => '6', | |
|
788 | :category_id => '1' # no change | |
|
789 | } | |
|
790 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
791 | end | |
|
792 | ||
|
764 | 793 | def test_post_edit_with_invalid_spent_time |
|
765 | 794 | @request.session[:user_id] = 2 |
|
766 | 795 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
@@ -797,6 +826,22 class IssuesControllerTest < Test::Unit::TestCase | |||
|
797 | 826 | assert_equal 1, journal.details.size |
|
798 | 827 | end |
|
799 | 828 | |
|
829 | def test_bullk_edit_should_send_a_notification | |
|
830 | @request.session[:user_id] = 2 | |
|
831 | ActionMailer::Base.deliveries.clear | |
|
832 | post(:bulk_edit, | |
|
833 | { | |
|
834 | :ids => [1, 2], | |
|
835 | :priority_id => 7, | |
|
836 | :assigned_to_id => '', | |
|
837 | :custom_field_values => {'2' => ''}, | |
|
838 | :notes => 'Bulk editing' | |
|
839 | }) | |
|
840 | ||
|
841 | assert_response 302 | |
|
842 | assert_equal 2, ActionMailer::Base.deliveries.size | |
|
843 | end | |
|
844 | ||
|
800 | 845 | def test_bulk_edit_custom_field |
|
801 | 846 | @request.session[:user_id] = 2 |
|
802 | 847 | # update issues priority |
@@ -112,6 +112,9 class NewsControllerTest < Test::Unit::TestCase | |||
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def test_post_new |
|
115 | ActionMailer::Base.deliveries.clear | |
|
116 | Setting.notified_events << 'news_added' | |
|
117 | ||
|
115 | 118 | @request.session[:user_id] = 2 |
|
116 | 119 | post :new, :project_id => 1, :news => { :title => 'NewsControllerTest', |
|
117 | 120 | :description => 'This is the description', |
@@ -123,6 +126,7 class NewsControllerTest < Test::Unit::TestCase | |||
|
123 | 126 | assert_equal 'This is the description', news.description |
|
124 | 127 | assert_equal User.find(2), news.author |
|
125 | 128 | assert_equal Project.find(1), news.project |
|
129 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
126 | 130 | end |
|
127 | 131 | |
|
128 | 132 | def test_edit_routing |
@@ -24,6 +24,7 class ChangesetTest < Test::Unit::TestCase | |||
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def test_ref_keywords_any |
|
27 | ActionMailer::Base.deliveries.clear | |
|
27 | 28 | Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id |
|
28 | 29 | Setting.commit_fix_done_ratio = '90' |
|
29 | 30 | Setting.commit_ref_keywords = '*' |
@@ -38,6 +39,7 class ChangesetTest < Test::Unit::TestCase | |||
|
38 | 39 | fixed = Issue.find(1) |
|
39 | 40 | assert fixed.closed? |
|
40 | 41 | assert_equal 90, fixed.done_ratio |
|
42 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
41 | 43 | end |
|
42 | 44 | |
|
43 | 45 | def test_ref_keywords_any_line_start |
@@ -25,6 +25,15 class DocumentTest < Test::Unit::TestCase | |||
|
25 | 25 | assert doc.save |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | def test_create_should_send_email_notification | |
|
29 | ActionMailer::Base.deliveries.clear | |
|
30 | Setting.notified_events << 'document_added' | |
|
31 | doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation')) | |
|
32 | ||
|
33 | assert doc.save | |
|
34 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
35 | end | |
|
36 | ||
|
28 | 37 | def test_create_with_default_category |
|
29 | 38 | # Sets a default category |
|
30 | 39 | e = Enumeration.find_by_name('Technical documentation') |
@@ -241,4 +241,12 class IssueTest < Test::Unit::TestCase | |||
|
241 | 241 | assert !Issue.new(:due_date => nil).overdue? |
|
242 | 242 | assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue? |
|
243 | 243 | end |
|
244 | ||
|
245 | def test_create_should_send_email_notification | |
|
246 | ActionMailer::Base.deliveries.clear | |
|
247 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.priorities.first, :subject => 'test_create', :estimated_hours => '1:30') | |
|
248 | ||
|
249 | assert issue.save | |
|
250 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
251 | end | |
|
244 | 252 | end |
@@ -36,4 +36,15 class JournalTest < Test::Unit::TestCase | |||
|
36 | 36 | assert_kind_of IssueStatus, status |
|
37 | 37 | assert_equal 2, status.id |
|
38 | 38 | end |
|
39 | ||
|
40 | def test_create_should_send_email_notification | |
|
41 | ActionMailer::Base.deliveries.clear | |
|
42 | issue = Issue.find(:first) | |
|
43 | user = User.find(:first) | |
|
44 | journal = issue.init_journal(user, issue) | |
|
45 | ||
|
46 | assert journal.save | |
|
47 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
48 | end | |
|
49 | ||
|
39 | 50 | end |
@@ -134,6 +134,14 class MailHandlerTest < Test::Unit::TestCase | |||
|
134 | 134 | assert_equal false, submit_email('ticket_without_from_header.eml') |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | def test_add_issue_should_send_email_notification | |
|
138 | ActionMailer::Base.deliveries.clear | |
|
139 | # This email contains: 'Project: onlinestore' | |
|
140 | issue = submit_email('ticket_on_given_project.eml') | |
|
141 | assert issue.is_a?(Issue) | |
|
142 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
143 | end | |
|
144 | ||
|
137 | 145 | def test_add_issue_note |
|
138 | 146 | journal = submit_email('ticket_reply.eml') |
|
139 | 147 | assert journal.is_a?(Journal) |
@@ -153,6 +161,13 class MailHandlerTest < Test::Unit::TestCase | |||
|
153 | 161 | assert_equal IssueStatus.find_by_name("Resolved"), issue.status |
|
154 | 162 | end |
|
155 | 163 | |
|
164 | def test_add_issue_note_should_send_email_notification | |
|
165 | ActionMailer::Base.deliveries.clear | |
|
166 | journal = submit_email('ticket_reply.eml') | |
|
167 | assert journal.is_a?(Journal) | |
|
168 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
169 | end | |
|
170 | ||
|
156 | 171 | def test_reply_to_a_message |
|
157 | 172 | m = submit_email('message_reply.eml') |
|
158 | 173 | assert m.is_a?(Message) |
@@ -20,9 +20,23 require File.dirname(__FILE__) + '/../test_helper' | |||
|
20 | 20 | class NewsTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects, :users, :roles, :members, :enabled_modules, :news |
|
22 | 22 | |
|
23 | def valid_news | |
|
24 | { :title => 'Test news', :description => 'Lorem ipsum etc', :author => User.find(:first) } | |
|
25 | end | |
|
26 | ||
|
27 | ||
|
23 | 28 | def setup |
|
24 | 29 | end |
|
25 | 30 | |
|
31 | def test_create_should_send_email_notification | |
|
32 | ActionMailer::Base.deliveries.clear | |
|
33 | Setting.notified_events << 'news_added' | |
|
34 | news = Project.find(:first).news.new(valid_news) | |
|
35 | ||
|
36 | assert news.save | |
|
37 | assert_equal 1, ActionMailer::Base.deliveries.size | |
|
38 | end | |
|
39 | ||
|
26 | 40 | def test_should_include_news_for_projects_with_news_enabled |
|
27 | 41 | project = projects(:projects_001) |
|
28 | 42 | assert project.enabled_modules.any?{ |em| em.name == 'news' } |
@@ -37,7 +51,7 class NewsTest < Test::Unit::TestCase | |||
|
37 | 51 | assert ! project.enabled_modules.any?{ |em| em.name == 'news' } |
|
38 | 52 | |
|
39 | 53 | # Add a piece of news to the project |
|
40 | news = project.news.create(:title => 'Test news', :description => 'This should not be returned by News.latest') | |
|
54 | news = project.news.create(valid_news) | |
|
41 | 55 | |
|
42 | 56 | # News.latest should not return that new piece of news |
|
43 | 57 | assert News.latest.include?(news) == false |
@@ -50,14 +64,14 class NewsTest < Test::Unit::TestCase | |||
|
50 | 64 | |
|
51 | 65 | def test_should_limit_the_amount_of_returned_news |
|
52 | 66 | # Make sure we have a bunch of news stories |
|
53 |
10.times { projects(:projects_001).news.create( |
|
|
67 | 10.times { projects(:projects_001).news.create(valid_news) } | |
|
54 | 68 | assert_equal 2, News.latest(users(:users_002), 2).size |
|
55 | 69 | assert_equal 6, News.latest(users(:users_002), 6).size |
|
56 | 70 | end |
|
57 | 71 | |
|
58 | 72 | def test_should_return_5_news_stories_by_default |
|
59 | 73 | # Make sure we have a bunch of news stories |
|
60 |
10.times { projects(:projects_001).news.create( |
|
|
74 | 10.times { projects(:projects_001).news.create(valid_news) } | |
|
61 | 75 | assert_equal 5, News.latest(users(:users_004)).size |
|
62 | 76 | end |
|
63 | 77 | end |
General Comments 0
You need to be logged in to leave comments.
Login now