OSDN Git Service

update activegroonga 2.1.1
[tdcgexplorer/nimono.git] / vendor / plugins / rails_upgrade / test / new_configuration_generator_test.rb
1 require 'test_helper'
2 require 'new_configuration_generator'
3
4 # Stub out methods on upgrader class
5 module Rails
6   module Upgrading
7     class NewConfigurationGenerator
8       attr_writer :environment_code
9       
10       def has_environment?
11         true
12       end
13       
14       def environment_code
15         @environment_code
16       end
17       
18       def app_name
19         "my_application"
20       end
21     end
22   end
23 end
24
25 class NewConfigurationGeneratorTest < ActiveSupport::TestCase
26   FRAME = "# Put this in config/application.rb
27 require File.expand_path('../boot', __FILE__)
28
29 module MyApplication
30   class Application < Rails::Application
31 %s
32   end
33 end"
34
35   CONFIG = "  config.what_have_you = 'thing'
36   config.action_controller = 'what'"
37
38   CODE = "require 'w/e'
39
40 this_happens_before_the(code)
41 more_before_the_code!
42
43 Rails::Initializer.run do |config|
44 %s
45 end
46
47 this_is_after_the_code
48 "
49
50   def test_raises_error_with_no_code
51     generator = Rails::Upgrading::NewConfigurationGenerator.new
52     generator.environment_code = ""
53     
54     assert_raises(RuntimeError) { generator.generate_new_application_rb }
55   end
56   
57   def test_generates_with_code
58     generator = Rails::Upgrading::NewConfigurationGenerator.new
59     generator.environment_code = CODE % [CONFIG]
60     
61     assert_equal FRAME % [generator.indent(CONFIG)], generator.generate_new_application_rb
62   end
63 end