@@ -183,9 +183,13 class Mailer < ActionMailer::Base | |||||
183 | super |
|
183 | super | |
184 | set_language_if_valid Setting.default_language |
|
184 | set_language_if_valid Setting.default_language | |
185 | from Setting.mail_from |
|
185 | from Setting.mail_from | |
186 | default_url_options[:host] = Setting.host_name |
|
186 | ||
|
187 | # URL options | |||
|
188 | h = Setting.host_name | |||
|
189 | h = h.to_s.gsub(%r{\/.*$}, '') unless ActionController::AbstractRequest.relative_url_root.blank? | |||
|
190 | default_url_options[:host] = h | |||
187 | default_url_options[:protocol] = Setting.protocol |
|
191 | default_url_options[:protocol] = Setting.protocol | |
188 | default_url_options[:skip_relative_url_root] = true |
|
192 | ||
189 | # Common headers |
|
193 | # Common headers | |
190 | headers 'X-Mailer' => 'Redmine', |
|
194 | headers 'X-Mailer' => 'Redmine', | |
191 | 'X-Redmine-Host' => Setting.host_name, |
|
195 | 'X-Redmine-Host' => Setting.host_name, |
@@ -39,6 +39,54 class MailerTest < Test::Unit::TestCase | |||||
39 | assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') |
|
39 | assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
|
42 | def test_generated_links_with_prefix | |||
|
43 | relative_url_root = ActionController::AbstractRequest.relative_url_root | |||
|
44 | ActionMailer::Base.deliveries.clear | |||
|
45 | Setting.host_name = 'mydomain.foo/rdm' | |||
|
46 | Setting.protocol = 'http' | |||
|
47 | ActionController::AbstractRequest.relative_url_root = '/rdm' | |||
|
48 | ||||
|
49 | journal = Journal.find(2) | |||
|
50 | assert Mailer.deliver_issue_edit(journal) | |||
|
51 | ||||
|
52 | mail = ActionMailer::Base.deliveries.last | |||
|
53 | assert_kind_of TMail::Mail, mail | |||
|
54 | # link to the main ticket | |||
|
55 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>') | |||
|
56 | ||||
|
57 | # link to a referenced ticket | |||
|
58 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') | |||
|
59 | # link to a changeset | |||
|
60 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') | |||
|
61 | ensure | |||
|
62 | # restore it | |||
|
63 | ActionController::AbstractRequest.relative_url_root = relative_url_root | |||
|
64 | end | |||
|
65 | ||||
|
66 | def test_generated_links_with_prefix_and_no_relative_url_root | |||
|
67 | relative_url_root = ActionController::AbstractRequest.relative_url_root | |||
|
68 | ActionMailer::Base.deliveries.clear | |||
|
69 | Setting.host_name = 'mydomain.foo/rdm' | |||
|
70 | Setting.protocol = 'http' | |||
|
71 | ActionController::AbstractRequest.relative_url_root = nil | |||
|
72 | ||||
|
73 | journal = Journal.find(2) | |||
|
74 | assert Mailer.deliver_issue_edit(journal) | |||
|
75 | ||||
|
76 | mail = ActionMailer::Base.deliveries.last | |||
|
77 | assert_kind_of TMail::Mail, mail | |||
|
78 | # link to the main ticket | |||
|
79 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>') | |||
|
80 | ||||
|
81 | # link to a referenced ticket | |||
|
82 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') | |||
|
83 | # link to a changeset | |||
|
84 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') | |||
|
85 | ensure | |||
|
86 | # restore it | |||
|
87 | ActionController::AbstractRequest.relative_url_root = relative_url_root | |||
|
88 | end | |||
|
89 | ||||
42 | def test_plain_text_mail |
|
90 | def test_plain_text_mail | |
43 | Setting.plain_text_mail = 1 |
|
91 | Setting.plain_text_mail = 1 | |
44 | journal = Journal.find(2) |
|
92 | journal = Journal.find(2) |
General Comments 0
You need to be logged in to leave comments.
Login now