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