summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-02-25 07:25:01 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-02-25 07:25:01 +0000
commit4baf32b166a667f26440e4f3d81cdbcedc64eaa4 (patch)
treefffed4d31974613745424e966ddfe7fc80825aff
parent0f68334f0bed0507bfb2157d99052a15511c5a2c (diff)
downloadredmine-4baf32b166a667f26440e4f3d81cdbcedc64eaa4.tar.gz
redmine-4baf32b166a667f26440e4f3d81cdbcedc64eaa4.zip
Fixing Plugin and Mailer default_url_options.
Both the plugin hooks and Mailer were setting default_url_options incorrectly and causing ActionContoller::UrlWritter to cache the settings on the module (mattr_accessor) causing several url generators to fail in either the plugin hooks or the Mailer. * Replaced Mailer's use of the default_url_options accessor with the proper class method * Replaced Hook's use of the default_url_options accessor with the proper class method on the ViewListener class * Added a test to reproduce the bugs in the Mailer when a hook is registered (thanks Chaoqun Zou) #2542 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2522 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/mailer.rb12
-rw-r--r--lib/redmine/hook.rb10
-rw-r--r--test/unit/lib/redmine/hook_test.rb20
3 files changed, 33 insertions, 9 deletions
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index 7560e53b5..8a472b343 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -23,6 +23,12 @@ class Mailer < ActionMailer::Base
include ActionController::UrlWriter
include Redmine::I18n
+ def self.default_url_options
+ h = Setting.host_name
+ h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
+ { :host => h, :protocol => Setting.protocol }
+ end
+
def issue_add(issue)
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue.id,
@@ -213,12 +219,6 @@ class Mailer < ActionMailer::Base
set_language_if_valid Setting.default_language
from Setting.mail_from
- # URL options
- h = Setting.host_name
- h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
- default_url_options[:host] = h
- default_url_options[:protocol] = Setting.protocol
-
# Common headers
headers 'X-Mailer' => 'Redmine',
'X-Redmine-Host' => Setting.host_name,
diff --git a/lib/redmine/hook.rb b/lib/redmine/hook.rb
index 2dedb78e7..7f4b6e07e 100644
--- a/lib/redmine/hook.rb
+++ b/lib/redmine/hook.rb
@@ -60,7 +60,6 @@ module Redmine
returning [] do |response|
hls = hook_listeners(hook)
if hls.any?
- default_url_options[:only_path] ||= true
hls.each {|listener| response << listener.send(hook, context)}
end
end
@@ -77,8 +76,9 @@ module Redmine
Redmine::Hook.add_listener(child)
super
end
+
end
-
+
# Listener class used for views hooks.
# Listeners that inherit this class will include various helpers by default.
class ViewListener < Listener
@@ -96,6 +96,12 @@ module Redmine
include ActionController::UrlWriter
include ApplicationHelper
+ # Default to creating links using only the path. Subclasses can
+ # change this default as needed
+ def self.default_url_options
+ {:only_path => true }
+ end
+
# Helper method to directly render a partial using the context:
#
# class MyHook < Redmine::Hook::ViewListener
diff --git a/test/unit/lib/redmine/hook_test.rb b/test/unit/lib/redmine/hook_test.rb
index 3e70c1c69..9313a36c7 100644
--- a/test/unit/lib/redmine/hook_test.rb
+++ b/test/unit/lib/redmine/hook_test.rb
@@ -19,6 +19,8 @@ require File.dirname(__FILE__) + '/../../../test_helper'
class Redmine::Hook::ManagerTest < Test::Unit::TestCase
+ fixtures :issues
+
# Some hooks that are manually registered in these tests
class TestHook < Redmine::Hook::ViewListener; end
@@ -64,7 +66,6 @@ class Redmine::Hook::ManagerTest < Test::Unit::TestCase
def teardown
@hook_module.clear_listeners
- @hook_module.default_url_options = { }
end
def test_clear_listeners
@@ -144,5 +145,22 @@ class Redmine::Hook::ManagerTest < Test::Unit::TestCase
assert_equal 'Test hook 1 listener. Test hook 2 listener.',
@view_hook_helper.call_hook(:view_layouts_base_html_head)
end
+
+ def test_call_hook_should_not_change_the_default_url_for_email_notifications
+ issue = Issue.find(1)
+
+ ActionMailer::Base.deliveries.clear
+ Mailer.deliver_issue_add(issue)
+ mail = ActionMailer::Base.deliveries.last
+
+ @hook_module.add_listener(TestLinkToHook)
+ @hook_helper.call_hook(:view_layouts_base_html_head)
+
+ ActionMailer::Base.deliveries.clear
+ Mailer.deliver_issue_add(issue)
+ mail2 = ActionMailer::Base.deliveries.last
+
+ assert_equal mail.body, mail2.body
+ end
end