Commit 81c3ad5ae6127922c75b5fe6dd70d2b0c0e3e9cb
1 parent
cde206df
Exists in
master
and in
29 other branches
Check if environments table exists before try to load Environment.default_hostname
(ActionItem1808)
Showing
3 changed files
with
20 additions
and
1 deletions
Show diff stats
config/initializers/exception_notification.rb
1 | 1 | unless NOOSFERO_CONF['exception_recipients'].blank? |
2 | 2 | require 'exception_notification.rb' |
3 | - ExceptionNotifier.sender_address = "noreply@#{Environment.default.default_hostname}" | |
3 | + ExceptionNotifier.sender_address = "noreply@#{Noosfero.default_hostname}" | |
4 | 4 | ExceptionNotifier.email_prefix = "[Noosfero ERROR] " |
5 | 5 | ExceptionNotifier.exception_recipients = NOOSFERO_CONF['exception_recipients'] |
6 | 6 | ActionController::Base.send :include, ExceptionNotifiable | ... | ... |
lib/noosfero.rb
... | ... | @@ -39,6 +39,10 @@ module Noosfero |
39 | 39 | '[a-z0-9][a-z0-9~.]*([_-][a-z0-9~.]+)*' |
40 | 40 | end |
41 | 41 | |
42 | + def self.default_hostname | |
43 | + Environment.table_exists? && Environment.default ? Environment.default.default_hostname : 'localhost' | |
44 | + end | |
45 | + | |
42 | 46 | private |
43 | 47 | |
44 | 48 | def self.controllers_in_directory(dir) | ... | ... |
test/unit/noosfero_test.rb
... | ... | @@ -69,4 +69,19 @@ class NoosferoTest < Test::Unit::TestCase |
69 | 69 | end |
70 | 70 | end |
71 | 71 | |
72 | + should "use default hostname of default environment as hostname of Noosfero instance" do | |
73 | + Environment.default.domains << Domain.new(:name => 'thisisdefaulthostname.com', :is_default => true) | |
74 | + assert_equal 'thisisdefaulthostname.com', Noosfero.default_hostname | |
75 | + end | |
76 | + | |
77 | + should "use 'localhost' as default hostname of Noosfero instance when has no environments in database" do | |
78 | + Environment.stubs(:default).returns(nil) | |
79 | + assert_equal 'localhost', Noosfero.default_hostname | |
80 | + end | |
81 | + | |
82 | + should "use 'localhost' as default hostname of Noosfero instance when environments table doesn't exists" do | |
83 | + Environment.stubs(:table_exists?).returns(false) | |
84 | + assert_equal 'localhost', Noosfero.default_hostname | |
85 | + end | |
86 | + | |
72 | 87 | end | ... | ... |