##// END OF EJS Templates
Slight changes to ease Rails 2.2 support....
Jean-Philippe Lang -
r2232:260373aed71e
parent child
Show More
@@ -0,0 +1,38
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 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 module Redmine
19 module Utils
20 class << self
21 # Returns the relative root url of the application
22 def relative_url_root
23 ActionController::Base.respond_to?('relative_url_root') ?
24 ActionController::Base.relative_url_root.to_s :
25 ActionController::AbstractRequest.relative_url_root.to_s
26 end
27
28 # Sets the relative root url of the application
29 def relative_url_root=(arg)
30 if ActionController::Base.respond_to?('relative_url_root=')
31 ActionController::Base.relative_url_root=arg
32 else
33 ActionController::AbstractRequest.relative_url_root=arg
34 end
35 end
36 end
37 end
38 end
@@ -41,7 +41,7 class SettingsController < ApplicationController
41 @deliveries = ActionMailer::Base.perform_deliveries
41 @deliveries = ActionMailer::Base.perform_deliveries
42
42
43 @guessed_host_and_path = request.host_with_port
43 @guessed_host_and_path = request.host_with_port
44 @guessed_host_and_path << ('/'+ request.relative_url_root.gsub(%r{^\/}, '')) unless request.relative_url_root.blank?
44 @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
45 end
45 end
46
46
47 def plugin
47 def plugin
@@ -191,7 +191,7 class Mailer < ActionMailer::Base
191
191
192 # URL options
192 # URL options
193 h = Setting.host_name
193 h = Setting.host_name
194 h = h.to_s.gsub(%r{\/.*$}, '') unless ActionController::AbstractRequest.relative_url_root.blank?
194 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
195 default_url_options[:host] = h
195 default_url_options[:host] = h
196 default_url_options[:protocol] = Setting.protocol
196 default_url_options[:protocol] = Setting.protocol
197
197
@@ -226,7 +226,7 class Mailer < ActionMailer::Base
226
226
227 # Renders a message with the corresponding layout
227 # Renders a message with the corresponding layout
228 def render_message(method_name, body)
228 def render_message(method_name, body)
229 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
229 layout = method_name.to_s.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
230 body[:content_for_layout] = render(:file => method_name, :body => body)
230 body[:content_for_layout] = render(:file => method_name, :body => body)
231 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
231 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
232 end
232 end
@@ -21,8 +21,7 module Redmine
21 module Helper
21 module Helper
22 def wikitoolbar_for(field_id)
22 def wikitoolbar_for(field_id)
23 # Is there a simple way to link to a public resource?
23 # Is there a simple way to link to a public resource?
24 prefix = (ActionController::Base.respond_to?(:relative_url_root) ? ActionController::Base.relative_url_root : ActionController::AbstractRequest.relative_url_root)
24 url = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"
25 url = "#{prefix}/help/wiki_syntax.html"
26
25
27 help_link = l(:setting_text_formatting) + ': ' +
26 help_link = l(:setting_text_formatting) + ': ' +
28 link_to(l(:label_help), url,
27 link_to(l(:label_help), url,
@@ -40,11 +40,11 class MailerTest < Test::Unit::TestCase
40 end
40 end
41
41
42 def test_generated_links_with_prefix
42 def test_generated_links_with_prefix
43 relative_url_root = ActionController::AbstractRequest.relative_url_root
43 relative_url_root = Redmine::Utils.relative_url_root
44 ActionMailer::Base.deliveries.clear
44 ActionMailer::Base.deliveries.clear
45 Setting.host_name = 'mydomain.foo/rdm'
45 Setting.host_name = 'mydomain.foo/rdm'
46 Setting.protocol = 'http'
46 Setting.protocol = 'http'
47 ActionController::AbstractRequest.relative_url_root = '/rdm'
47 Redmine::Utils.relative_url_root = '/rdm'
48
48
49 journal = Journal.find(2)
49 journal = Journal.find(2)
50 assert Mailer.deliver_issue_edit(journal)
50 assert Mailer.deliver_issue_edit(journal)
@@ -60,15 +60,15 class MailerTest < Test::Unit::TestCase
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 &amp; #3">r2</a>')
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 &amp; #3">r2</a>')
61 ensure
61 ensure
62 # restore it
62 # restore it
63 ActionController::AbstractRequest.relative_url_root = relative_url_root
63 Redmine::Utils.relative_url_root = relative_url_root
64 end
64 end
65
65
66 def test_generated_links_with_prefix_and_no_relative_url_root
66 def test_generated_links_with_prefix_and_no_relative_url_root
67 relative_url_root = ActionController::AbstractRequest.relative_url_root
67 relative_url_root = Redmine::Utils.relative_url_root
68 ActionMailer::Base.deliveries.clear
68 ActionMailer::Base.deliveries.clear
69 Setting.host_name = 'mydomain.foo/rdm'
69 Setting.host_name = 'mydomain.foo/rdm'
70 Setting.protocol = 'http'
70 Setting.protocol = 'http'
71 ActionController::AbstractRequest.relative_url_root = nil
71 Redmine::Utils.relative_url_root = nil
72
72
73 journal = Journal.find(2)
73 journal = Journal.find(2)
74 assert Mailer.deliver_issue_edit(journal)
74 assert Mailer.deliver_issue_edit(journal)
@@ -84,7 +84,7 class MailerTest < Test::Unit::TestCase
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 &amp; #3">r2</a>')
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 &amp; #3">r2</a>')
85 ensure
85 ensure
86 # restore it
86 # restore it
87 ActionController::AbstractRequest.relative_url_root = relative_url_root
87 Redmine::Utils.relative_url_root = relative_url_root
88 end
88 end
89
89
90 def test_plain_text_mail
90 def test_plain_text_mail
General Comments 0
You need to be logged in to leave comments. Login now