Commit 32f88e655612ac6a1b15cf241e3689cf2852c2f6

Authored by Antonio Terceiro
1 parent 174636fa

Remove Evil™ manipulation of constants

test/test_helper.rb
@@ -277,16 +277,4 @@ class ActionController::IntegrationTest @@ -277,16 +277,4 @@ class ActionController::IntegrationTest
277 277
278 end 278 end
279 279
280 -def with_constants(constants, &block)  
281 - old_constants = Hash.new  
282 - constants.each do |constant, val|  
283 - old_constants[constant] = Object.const_get(constant)  
284 - silence_stderr{ Object.const_set(constant, val) }  
285 - end  
286 - block.call  
287 - old_constants.each do |constant, val|  
288 - silence_stderr{ Object.const_set(constant, val) }  
289 - end  
290 -end  
291 -  
292 Profile 280 Profile
test/unit/application_helper_test.rb
@@ -472,13 +472,13 @@ class ApplicationHelperTest < ActionView::TestCase @@ -472,13 +472,13 @@ class ApplicationHelperTest < ActionView::TestCase
472 profile = mock 472 profile = mock
473 profile.stubs(:theme).returns('some-theme') 473 profile.stubs(:theme).returns('some-theme')
474 stubs(:profile).returns(profile) 474 stubs(:profile).returns(profile)
475 - with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do  
476 - assert_equal gravatar_default, 'crazyvatar'  
477 - end 475 +
  476 + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar')
  477 + assert_equal gravatar_default, 'crazyvatar'
  478 +
478 stubs(:theme_option).returns('gravatar' => 'nicevatar') 479 stubs(:theme_option).returns('gravatar' => 'nicevatar')
479 - with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do  
480 - assert_equal gravatar_default, 'nicevatar'  
481 - end 480 + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar')
  481 + assert_equal gravatar_default, 'nicevatar'
482 end 482 end
483 483
484 should 'use theme passed via param when in development mode' do 484 should 'use theme passed via param when in development mode' do
test/unit/google_maps_test.rb
@@ -3,13 +3,12 @@ require File.dirname(__FILE__) + '/../test_helper' @@ -3,13 +3,12 @@ require File.dirname(__FILE__) + '/../test_helper'
3 class GoogleMapsTest < ActiveSupport::TestCase 3 class GoogleMapsTest < ActiveSupport::TestCase
4 4
5 should 'provide initial_zoom setting' do 5 should 'provide initial_zoom setting' do
6 - with_constants :NOOSFERO_CONF => {'googlemaps_initial_zoom' => 2} do  
7 - assert_equal 2, GoogleMaps.initial_zoom  
8 - end 6 + NOOSFERO_CONF.stubs(:[]).with('googlemaps_initial_zoom').returns(2)
  7 + assert_equal 2, GoogleMaps.initial_zoom
9 end 8 end
10 9
11 should 'use 4 as default initial_zoom' do 10 should 'use 4 as default initial_zoom' do
12 - GoogleMaps.stubs(:config).returns({}) 11 + NOOSFERO_CONF.stubs(:[]).with('googlemaps_initial_zoom').returns(nil)
13 assert_equal 4, GoogleMaps.initial_zoom 12 assert_equal 4, GoogleMaps.initial_zoom
14 end 13 end
15 14
test/unit/mail_conf_test.rb
@@ -3,22 +3,22 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -3,22 +3,22 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 class MailConfTest < ActiveSupport::TestCase 3 class MailConfTest < ActiveSupport::TestCase
4 4
5 should 'enable if told to' do 5 should 'enable if told to' do
6 - NOOSFERO_CONF['mail_enabled'] = true 6 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(true)
7 assert_equal true, MailConf.enabled? 7 assert_equal true, MailConf.enabled?
8 end 8 end
9 9
10 should 'disable if told to' do 10 should 'disable if told to' do
11 - NOOSFERO_CONF['mail_enabled'] = false 11 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(false)
12 assert_equal false, MailConf.enabled? 12 assert_equal false, MailConf.enabled?
13 end 13 end
14 14
15 should 'disable by default' do 15 should 'disable by default' do
16 - NOOSFERO_CONF['mail_enabled'] = nil 16 + NOOSFERO_CONF.stubs(:[]).with('mail_enabled').returns(nil)
17 assert_equal false, MailConf.enabled? 17 assert_equal false, MailConf.enabled?
18 end 18 end
19 19
20 should 'provide webmail url preference' do 20 should 'provide webmail url preference' do
21 - NOOSFERO_CONF['webmail_url'] = 'http://some.url/webmail/%s/%s' 21 + NOOSFERO_CONF.stubs(:[]).with('webmail_url').returns('http://some.url/webmail/%s/%s')
22 assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com') 22 assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com')
23 end 23 end
24 24