Commit 81c3ad5ae6127922c75b5fe6dd70d2b0c0e3e9cb

Authored by Joenio Costa
1 parent cde206df

Check if environments table exists before try to load Environment.default_hostname

(ActionItem1808)
config/initializers/exception_notification.rb
1 unless NOOSFERO_CONF['exception_recipients'].blank? 1 unless NOOSFERO_CONF['exception_recipients'].blank?
2 require 'exception_notification.rb' 2 require 'exception_notification.rb'
3 - ExceptionNotifier.sender_address = "noreply@#{Environment.default.default_hostname}" 3 + ExceptionNotifier.sender_address = "noreply@#{Noosfero.default_hostname}"
4 ExceptionNotifier.email_prefix = "[Noosfero ERROR] " 4 ExceptionNotifier.email_prefix = "[Noosfero ERROR] "
5 ExceptionNotifier.exception_recipients = NOOSFERO_CONF['exception_recipients'] 5 ExceptionNotifier.exception_recipients = NOOSFERO_CONF['exception_recipients']
6 ActionController::Base.send :include, ExceptionNotifiable 6 ActionController::Base.send :include, ExceptionNotifiable
lib/noosfero.rb
@@ -39,6 +39,10 @@ module Noosfero @@ -39,6 +39,10 @@ module Noosfero
39 '[a-z0-9][a-z0-9~.]*([_-][a-z0-9~.]+)*' 39 '[a-z0-9][a-z0-9~.]*([_-][a-z0-9~.]+)*'
40 end 40 end
41 41
  42 + def self.default_hostname
  43 + Environment.table_exists? && Environment.default ? Environment.default.default_hostname : 'localhost'
  44 + end
  45 +
42 private 46 private
43 47
44 def self.controllers_in_directory(dir) 48 def self.controllers_in_directory(dir)
test/unit/noosfero_test.rb
@@ -69,4 +69,19 @@ class NoosferoTest < Test::Unit::TestCase @@ -69,4 +69,19 @@ class NoosferoTest < Test::Unit::TestCase
69 end 69 end
70 end 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 end 87 end