aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/initializer_test.rb
blob: 4c25ad8a0ab5002751a73e9d87e797b35acd37e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$:.unshift File.dirname(__FILE__) + "/../lib"
$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"

require 'test/unit'
require 'active_support'
require 'initializer'

class InitializerTest < Test::Unit::TestCase
  class ConfigurationMock < Rails::Configuration
    def initialize(envpath)
      super()
      @envpath = envpath
    end
    
    def environment_path
      @envpath
    end
  end

  def setup
    Object.const_set(:RAILS_ROOT, "") rescue nil
  end
  
  def teardown
    Object.remove_const(:RAILS_ROOT) rescue nil
  end
  
  def test_load_environment_with_constant
    config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb")
    Rails::Initializer.run(:load_environment, config)
    assert Object.const_defined?(:SET_FROM_ENV)
    assert_equal "success", SET_FROM_ENV
  ensure
    Object.remove_const(:SET_FROM_ENV) rescue nil
  end
end