summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-11-08 13:25:45 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-11-08 13:25:45 +0000
commit077723c90a97e517b3726a0d9c66e36c0cd18d2f (patch)
tree03a9814a879b3d5aafedeac98fa6e12fc23655ef
parent81eee10d5b000d4eb74dbe900a92e033a7ec56e9 (diff)
downloadredmine-077723c90a97e517b3726a0d9c66e36c0cd18d2f.tar.gz
redmine-077723c90a97e517b3726a0d9c66e36c0cd18d2f.zip
Do not use @:skip_relative_url_root@ to generate urls in Mailer (#2122).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@1992 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/mailer.rb8
-rw-r--r--test/unit/mailer_test.rb48
2 files changed, 54 insertions, 2 deletions
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index 070f7e570..397807d16 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -183,9 +183,13 @@ class Mailer < ActionMailer::Base
super
set_language_if_valid Setting.default_language
from Setting.mail_from
- default_url_options[:host] = Setting.host_name
+
+ # URL options
+ h = Setting.host_name
+ h = h.to_s.gsub(%r{\/.*$}, '') unless ActionController::AbstractRequest.relative_url_root.blank?
+ default_url_options[:host] = h
default_url_options[:protocol] = Setting.protocol
- default_url_options[:skip_relative_url_root] = true
+
# Common headers
headers 'X-Mailer' => 'Redmine',
'X-Redmine-Host' => Setting.host_name,
diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb
index e3a21a576..1fd43af5d 100644
--- a/test/unit/mailer_test.rb
+++ b/test/unit/mailer_test.rb
@@ -38,6 +38,54 @@ class MailerTest < Test::Unit::TestCase
# link to a changeset
assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
end
+
+ def test_generated_links_with_prefix
+ relative_url_root = ActionController::AbstractRequest.relative_url_root
+ ActionMailer::Base.deliveries.clear
+ Setting.host_name = 'mydomain.foo/rdm'
+ Setting.protocol = 'http'
+ ActionController::AbstractRequest.relative_url_root = '/rdm'
+
+ journal = Journal.find(2)
+ assert Mailer.deliver_issue_edit(journal)
+
+ mail = ActionMailer::Base.deliveries.last
+ assert_kind_of TMail::Mail, mail
+ # link to the main ticket
+ assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>')
+
+ # link to a referenced ticket
+ assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
+ # link to a changeset
+ 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 &amp; #3">r2</a>')
+ ensure
+ # restore it
+ ActionController::AbstractRequest.relative_url_root = relative_url_root
+ end
+
+ def test_generated_links_with_prefix_and_no_relative_url_root
+ relative_url_root = ActionController::AbstractRequest.relative_url_root
+ ActionMailer::Base.deliveries.clear
+ Setting.host_name = 'mydomain.foo/rdm'
+ Setting.protocol = 'http'
+ ActionController::AbstractRequest.relative_url_root = nil
+
+ journal = Journal.find(2)
+ assert Mailer.deliver_issue_edit(journal)
+
+ mail = ActionMailer::Base.deliveries.last
+ assert_kind_of TMail::Mail, mail
+ # link to the main ticket
+ assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>')
+
+ # link to a referenced ticket
+ assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
+ # link to a changeset
+ 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 &amp; #3">r2</a>')
+ ensure
+ # restore it
+ ActionController::AbstractRequest.relative_url_root = relative_url_root
+ end
def test_plain_text_mail
Setting.plain_text_mail = 1