##// END OF EJS Templates
Override @#url_for@ in AM to force generation of absolute links (#10251)....
Etienne Massip -
r8902:7056649a4be9
parent child
Show More
@@ -30,6 +30,11 class Mailer < ActionMailer::Base
30 30 { :host => h, :protocol => Setting.protocol }
31 31 end
32 32
33 def url_for(options)
34 options[:only_path] = false if options.is_a?(Hash)
35 super options
36 end
37
33 38 # Builds a tmail object used to email recipients of the added issue.
34 39 #
35 40 # Example:
@@ -12,4 +12,4
12 12 <% end %>
13 13 </ul>
14 14
15 <%= textilizable(issue, :description, :only_path => false) %>
15 <%= textilizable(issue, :description) %>
@@ -1,3 +1,3
1 1 <%= link_to(h(@document.title), @document_url) %> (<%=h @document.category.name %>)<br />
2 2 <br />
3 <%= textilizable(@document, :description, :only_path => false) %>
3 <%= textilizable(@document, :description) %>
@@ -6,6 +6,6
6 6 <% end %>
7 7 </ul>
8 8
9 <%= textilizable(@journal, :notes, :only_path => false) %>
9 <%= textilizable(@journal, :notes) %>
10 10 <hr />
11 11 <%= render :partial => "issue.html.erb", :locals => { :issue => @issue, :issue_url => @issue_url } %>
@@ -1,4 +1,4
1 1 <h1><%=h @message.board.project.name %> - <%=h @message.board.name %>: <%= link_to(h(@message.subject), @message_url) %></h1>
2 2 <em><%=h @message.author %></em>
3 3
4 <%= textilizable(@message, :content, :only_path => false) %>
4 <%= textilizable(@message, :content) %>
@@ -1,4 +1,4
1 1 <h1><%= link_to(h(@news.title), @news_url) %></h1>
2 2 <em><%=h @news.author.name %></em>
3 3
4 <%= textilizable(@news, :description, :only_path => false) %>
4 <%= textilizable(@news, :description) %>
@@ -2,4 +2,4
2 2
3 3 <p><%= l(:text_user_wrote, :value => h(@comment.author)) %></p>
4 4
5 <%= textilizable @comment, :comments, :only_path => false %>
5 <%= textilizable @comment, :comments %>
@@ -2,7 +2,7
2 2
3 3 <ul>
4 4 <% @issues.each do |issue| -%>
5 <li><%=h issue.project %> - <%=link_to(h("#{issue.tracker} ##{issue.id}"), :controller => 'issues', :action => 'show', :id => issue, :only_path => false)%>: <%=h issue.subject %></li>
5 <li><%=h issue.project %> - <%=link_to(h("#{issue.tracker} ##{issue.id}"), :controller => 'issues', :action => 'show', :id => issue)%>: <%=h issue.subject %></li>
6 6 <% end -%>
7 7 </ul>
8 8
@@ -34,3 +34,10 journal_details_005:
34 34 value: New value
35 35 prop_key: 2
36 36 journal_id: 3
37 journal_details_006:
38 old_value: nil
39 property: attachment
40 id: 6
41 value: 060719210727_picture.jpg
42 prop_key: 4
43 journal_id: 3
@@ -1,5 +1,5
1 1 ---
2 journals_001:
2 journals_001:
3 3 created_on: <%= 2.days.ago.to_date.to_s(:db) %>
4 4 notes: "Journal notes"
5 5 id: 1
@@ -13,21 +13,21 journals_002:
13 13 journalized_type: Issue
14 14 user_id: 2
15 15 journalized_id: 1
16 journals_003:
16 journals_003:
17 17 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
18 notes: "A comment with inline image: !picture.jpg!"
18 notes: "A comment with inline image: !picture.jpg! and a reference to #1 and r2."
19 19 id: 3
20 20 journalized_type: Issue
21 21 user_id: 2
22 22 journalized_id: 2
23 journals_004:
23 journals_004:
24 24 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
25 25 notes: "A comment with a private version."
26 26 id: 4
27 27 journalized_type: Issue
28 28 user_id: 1
29 29 journalized_id: 6
30 journals_005:
30 journals_005:
31 31 id: 5
32 32 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
33 33 notes: "A comment on a private issue."
@@ -36,60 +36,80 class MailerTest < ActiveSupport::TestCase
36 36 end
37 37
38 38 def test_generated_links_in_emails
39 Setting.default_language = 'en'
39 40 Setting.host_name = 'mydomain.foo'
40 41 Setting.protocol = 'https'
41 42
42 journal = Journal.find(2)
43 journal = Journal.find(3)
43 44 assert Mailer.deliver_issue_edit(journal)
44 45
45 mail = ActionMailer::Base.deliveries.last
46 mail = last_email
46 47 assert_not_nil mail
47 48
48 49 assert_select_email do
49 50 # link to the main ticket
50 assert_select "a[href=?]",
51 "https://mydomain.foo/issues/1#change-2",
52 :text => "Bug #1: Can't print recipes"
51 assert_select 'a[href=?]',
52 'https://mydomain.foo/issues/2#change-3',
53 :text => 'Feature request #2: Add ingredients categories'
53 54 # link to a referenced ticket
54 assert_select "a[href=?][title=?]",
55 "https://mydomain.foo/issues/2",
56 "Add ingredients categories (Assigned)",
57 :text => "#2"
55 assert_select 'a[href=?][title=?]',
56 'https://mydomain.foo/issues/1',
57 'Can\'t print recipes (New)',
58 :text => '#1'
58 59 # link to a changeset
59 assert_select "a[href=?][title=?]",
60 "https://mydomain.foo/projects/ecookbook/repository/revisions/2",
61 "This commit fixes #1, #2 and references #1 &amp; #3",
62 :text => "r2"
60 assert_select 'a[href=?][title=?]',
61 'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
62 'This commit fixes #1, #2 and references #1 &amp; #3',
63 :text => 'r2'
64 # link to a description diff
65 assert_select 'a[href=?][title=?]',
66 'https://mydomain.foo/journals/diff/3?detail_id=4',
67 'View differences',
68 :text => 'diff'
69 # link to an attachment
70 assert_select 'a[href=?]',
71 'https://mydomain.foo/attachments/download/4/source.rb',
72 :text => 'source.rb'
63 73 end
64 74 end
65 75
66 76 def test_generated_links_with_prefix
77 Setting.default_language = 'en'
67 78 relative_url_root = Redmine::Utils.relative_url_root
68 79 Setting.host_name = 'mydomain.foo/rdm'
69 80 Setting.protocol = 'http'
70 81 Redmine::Utils.relative_url_root = '/rdm'
71 82
72 journal = Journal.find(2)
83 journal = Journal.find(3)
73 84 assert Mailer.deliver_issue_edit(journal)
74 85
75 mail = ActionMailer::Base.deliveries.last
86 mail = last_email
76 87 assert_not_nil mail
77 88
78 89 assert_select_email do
79 90 # link to the main ticket
80 assert_select "a[href=?]",
81 "http://mydomain.foo/rdm/issues/1#change-2",
82 :text => "Bug #1: Can't print recipes"
91 assert_select 'a[href=?]',
92 'http://mydomain.foo/rdm/issues/2#change-3',
93 :text => 'Feature request #2: Add ingredients categories'
83 94 # link to a referenced ticket
84 assert_select "a[href=?][title=?]",
85 "http://mydomain.foo/rdm/issues/2",
86 "Add ingredients categories (Assigned)",
87 :text => "#2"
95 assert_select 'a[href=?][title=?]',
96 'http://mydomain.foo/rdm/issues/1',
97 'Can\'t print recipes (New)',
98 :text => '#1'
88 99 # link to a changeset
89 assert_select "a[href=?][title=?]",
90 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
91 "This commit fixes #1, #2 and references #1 &amp; #3",
92 :text => "r2"
100 assert_select 'a[href=?][title=?]',
101 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
102 'This commit fixes #1, #2 and references #1 &amp; #3',
103 :text => 'r2'
104 # link to a description diff
105 assert_select 'a[href=?][title=?]',
106 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
107 'View differences',
108 :text => 'diff'
109 # link to an attachment
110 assert_select 'a[href=?]',
111 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
112 :text => 'source.rb'
93 113 end
94 114 ensure
95 115 # restore it
@@ -97,32 +117,42 class MailerTest < ActiveSupport::TestCase
97 117 end
98 118
99 119 def test_generated_links_with_prefix_and_no_relative_url_root
120 Setting.default_language = 'en'
100 121 relative_url_root = Redmine::Utils.relative_url_root
101 122 Setting.host_name = 'mydomain.foo/rdm'
102 123 Setting.protocol = 'http'
103 124 Redmine::Utils.relative_url_root = nil
104 125
105 journal = Journal.find(2)
126 journal = Journal.find(3)
106 127 assert Mailer.deliver_issue_edit(journal)
107 128
108 mail = ActionMailer::Base.deliveries.last
129 mail = last_email
109 130 assert_not_nil mail
110 131
111 132 assert_select_email do
112 133 # link to the main ticket
113 assert_select "a[href=?]",
114 "http://mydomain.foo/rdm/issues/1#change-2",
115 :text => "Bug #1: Can't print recipes"
134 assert_select 'a[href=?]',
135 'http://mydomain.foo/rdm/issues/2#change-3',
136 :text => 'Feature request #2: Add ingredients categories'
116 137 # link to a referenced ticket
117 assert_select "a[href=?][title=?]",
118 "http://mydomain.foo/rdm/issues/2",
119 "Add ingredients categories (Assigned)",
120 :text => "#2"
138 assert_select 'a[href=?][title=?]',
139 'http://mydomain.foo/rdm/issues/1',
140 'Can\'t print recipes (New)',
141 :text => '#1'
121 142 # link to a changeset
122 assert_select "a[href=?][title=?]",
123 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
124 "This commit fixes #1, #2 and references #1 &amp; #3",
125 :text => "r2"
143 assert_select 'a[href=?][title=?]',
144 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
145 'This commit fixes #1, #2 and references #1 &amp; #3',
146 :text => 'r2'
147 # link to a description diff
148 assert_select 'a[href=?][title=?]',
149 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
150 'View differences',
151 :text => 'diff'
152 # link to an attachment
153 assert_select 'a[href=?]',
154 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
155 :text => 'source.rb'
126 156 end
127 157 ensure
128 158 # restore it
@@ -132,7 +162,7 class MailerTest < ActiveSupport::TestCase
132 162 def test_email_headers
133 163 issue = Issue.find(1)
134 164 Mailer.deliver_issue_add(issue)
135 mail = ActionMailer::Base.deliveries.last
165 mail = last_email
136 166 assert_not_nil mail
137 167 assert_equal 'OOF', mail.header_string('X-Auto-Response-Suppress')
138 168 assert_equal 'auto-generated', mail.header_string('Auto-Submitted')
@@ -141,8 +171,7 class MailerTest < ActiveSupport::TestCase
141 171 def test_email_headers_should_include_sender
142 172 issue = Issue.find(1)
143 173 Mailer.deliver_issue_add(issue)
144 mail = ActionMailer::Base.deliveries.last
145 assert_not_nil mail
174 mail = last_email
146 175 assert_equal issue.author.login, mail.header_string('X-Redmine-Sender')
147 176 end
148 177
@@ -150,7 +179,7 class MailerTest < ActiveSupport::TestCase
150 179 Setting.plain_text_mail = 1
151 180 journal = Journal.find(2)
152 181 Mailer.deliver_issue_edit(journal)
153 mail = ActionMailer::Base.deliveries.last
182 mail = last_email
154 183 assert_equal "text/plain", mail.content_type
155 184 assert_equal 0, mail.parts.size
156 185 assert !mail.encoded.include?('href')
@@ -160,7 +189,7 class MailerTest < ActiveSupport::TestCase
160 189 Setting.plain_text_mail = 0
161 190 journal = Journal.find(2)
162 191 Mailer.deliver_issue_edit(journal)
163 mail = ActionMailer::Base.deliveries.last
192 mail = last_email
164 193 assert_equal 2, mail.parts.size
165 194 assert mail.encoded.include?('href')
166 195 end
@@ -169,8 +198,7 class MailerTest < ActiveSupport::TestCase
169 198 with_settings :mail_from => 'redmine@example.net' do
170 199 Mailer.deliver_test(User.find(1))
171 200 end
172 mail = ActionMailer::Base.deliveries.last
173 assert_not_nil mail
201 mail = last_email
174 202 assert_equal 'redmine@example.net', mail.from_addrs.first.address
175 203 end
176 204
@@ -178,8 +206,7 class MailerTest < ActiveSupport::TestCase
178 206 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
179 207 Mailer.deliver_test(User.find(1))
180 208 end
181 mail = ActionMailer::Base.deliveries.last
182 assert_not_nil mail
209 mail = last_email
183 210 assert_equal 'redmine@example.net', mail.from_addrs.first.address
184 211 assert_equal 'Redmine app', mail.from_addrs.first.name
185 212 end
@@ -208,8 +235,7 class MailerTest < ActiveSupport::TestCase
208 235 def test_issue_add_message_id
209 236 issue = Issue.find(1)
210 237 Mailer.deliver_issue_add(issue)
211 mail = ActionMailer::Base.deliveries.last
212 assert_not_nil mail
238 mail = last_email
213 239 assert_equal Mailer.message_id_for(issue), mail.message_id
214 240 assert_nil mail.references
215 241 end
@@ -217,8 +243,7 class MailerTest < ActiveSupport::TestCase
217 243 def test_issue_edit_message_id
218 244 journal = Journal.find(1)
219 245 Mailer.deliver_issue_edit(journal)
220 mail = ActionMailer::Base.deliveries.last
221 assert_not_nil mail
246 mail = last_email
222 247 assert_equal Mailer.message_id_for(journal), mail.message_id
223 248 assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s
224 249 assert_select_email do
@@ -231,8 +256,7 class MailerTest < ActiveSupport::TestCase
231 256 def test_message_posted_message_id
232 257 message = Message.find(1)
233 258 Mailer.deliver_message_posted(message)
234 mail = ActionMailer::Base.deliveries.last
235 assert_not_nil mail
259 mail = last_email
236 260 assert_equal Mailer.message_id_for(message), mail.message_id
237 261 assert_nil mail.references
238 262 assert_select_email do
@@ -246,8 +270,7 class MailerTest < ActiveSupport::TestCase
246 270 def test_reply_posted_message_id
247 271 message = Message.find(3)
248 272 Mailer.deliver_message_posted(message)
249 mail = ActionMailer::Base.deliveries.last
250 assert_not_nil mail
273 mail = last_email
251 274 assert_equal Mailer.message_id_for(message), mail.message_id
252 275 assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s
253 276 assert_select_email do
@@ -425,7 +448,7 class MailerTest < ActiveSupport::TestCase
425 448 token.reload
426 449 ActionMailer::Base.deliveries.clear
427 450 assert Mailer.deliver_register(token)
428 mail = ActionMailer::Base.deliveries.last
451 mail = last_email
429 452 assert_select_email do
430 453 assert_select "a[href=?]",
431 454 "https://redmine.foo/account/activate?token=#{token.value}",
@@ -445,7 +468,7 class MailerTest < ActiveSupport::TestCase
445 468 def test_reminders
446 469 Mailer.reminders(:days => 42)
447 470 assert_equal 1, ActionMailer::Base.deliveries.size
448 mail = ActionMailer::Base.deliveries.last
471 mail = last_email
449 472 assert mail.bcc.include?('dlopper@somenet.foo')
450 473 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
451 474 assert_equal '1 issue(s) due in the next 42 days', mail.subject
@@ -460,7 +483,7 class MailerTest < ActiveSupport::TestCase
460 483
461 484 Mailer.reminders(:days => 42)
462 485 assert_equal 1, ActionMailer::Base.deliveries.size
463 mail = ActionMailer::Base.deliveries.last
486 mail = last_email
464 487 assert mail.bcc.include?('dlopper@somenet.foo')
465 488 assert !mail.body.include?('Closed issue')
466 489 end
@@ -471,7 +494,7 class MailerTest < ActiveSupport::TestCase
471 494 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
472 495 Mailer.reminders(:days => 42, :users => ['3'])
473 496 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
474 mail = ActionMailer::Base.deliveries.last
497 mail = last_email
475 498 assert mail.bcc.include?('dlopper@somenet.foo')
476 499 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
477 500 end
@@ -490,7 +513,7 class MailerTest < ActiveSupport::TestCase
490 513 user = User.find(1)
491 514 user.language = 'fr'
492 515 Mailer.deliver_account_activated(user)
493 mail = ActionMailer::Base.deliveries.last
516 mail = last_email
494 517 assert mail.body.include?('Votre compte')
495 518
496 519 assert_equal :it, current_language
General Comments 0
You need to be logged in to leave comments. Login now