diff options
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/generators_test.rb | 89 | ||||
-rw-r--r-- | railties/test/application/initializer_test.rb | 132 | ||||
-rw-r--r-- | railties/test/application/plugins_test.rb | 11 |
3 files changed, 227 insertions, 5 deletions
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb new file mode 100644 index 0000000000..0d6eb4147a --- /dev/null +++ b/railties/test/application/generators_test.rb @@ -0,0 +1,89 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class GeneratorsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + require "rails/generators" + build_app + boot_rails + end + + test "generators default values" do + Rails::Initializer.run do |c| + assert_equal(true, c.generators.colorize_logging) + assert_equal({}, c.generators.aliases) + assert_equal({}, c.generators.options) + end + end + + test "generators set rails options" do + Rails::Initializer.run do |c| + c.generators.orm = :datamapper + c.generators.test_framework = :rspec + expected = { :rails => { :orm => :datamapper, :test_framework => :rspec } } + assert_equal(expected, c.generators.options) + end + end + + test "generators set rails aliases" do + Rails::Initializer.run do |c| + c.generators.aliases = { :rails => { :test_framework => "-w" } } + expected = { :rails => { :test_framework => "-w" } } + assert_equal expected, c.generators.aliases + end + end + + test "generators aliases and options on initialization" do + Rails::Initializer.run do |c| + c.generators.rails :aliases => { :test_framework => "-w" } + c.generators.orm :datamapper + c.generators.test_framework :rspec + end + + assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] + assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] + end + + test "generators no color on initialization" do + Rails::Initializer.run do |c| + c.generators.colorize_logging = false + end + + assert_equal Thor::Base.shell, Thor::Shell::Basic + end + + test "generators with hashes for options and aliases" do + Rails::Initializer.run do |c| + c.generators do |g| + g.orm :datamapper, :migration => false + g.plugin :aliases => { :generator => "-g" }, + :generator => true + end + + expected = { + :rails => { :orm => :datamapper }, + :plugin => { :generator => true }, + :datamapper => { :migration => false } + } + + assert_equal expected, c.generators.options + assert_equal({ :plugin => { :generator => "-g" } }, c.generators.aliases) + end + end + + test "generators with hashes are deep merged" do + Rails::Initializer.run do |c| + c.generators do |g| + g.orm :datamapper, :migration => false + g.plugin :aliases => { :generator => "-g" }, + :generator => true + end + end + + assert Rails::Generators.aliases.size >= 1 + assert Rails::Generators.options.size >= 1 + end + end +end
\ No newline at end of file diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index c57ed08fdc..f46bf2b656 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -55,6 +55,59 @@ module ApplicationTests assert Zoo end + test "load environment with global" do + app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'" + assert_nil $initialize_test_set_from_env + Rails::Initializer.run { } + assert_equal "success", $initialize_test_set_from_env + end + + test "action_controller load paths set only if action controller in use" do + assert_nothing_raised NameError do + Rails::Initializer.run do |config| + config.frameworks = [] + end + end + end + + test "action_pack is added to the load path if action_controller is required" do + Rails::Initializer.run do |config| + config.frameworks = [:action_controller] + end + + assert $:.include?("#{framework_path}/actionpack/lib") + end + + test "action_pack is added to the load path if action_view is required" do + Rails::Initializer.run do |config| + config.frameworks = [:action_view] + end + + assert $:.include?("#{framework_path}/actionpack/lib") + end + + test "after_initialize block works correctly" do + Rails::Initializer.run do |config| + config.after_initialize { $test_after_initialize_block1 = "success" } + config.after_initialize { $test_after_initialize_block2 = "congratulations" } + end + + assert_equal "success", $test_after_initialize_block1 + assert_equal "congratulations", $test_after_initialize_block2 + end + + test "after_initialize block works correctly when no block is passed" do + Rails::Initializer.run do |config| + config.after_initialize { $test_after_initialize_block1 = "success" } + config.after_initialize # don't pass a block, this is what we're testing! + config.after_initialize { $test_after_initialize_block2 = "congratulations" } + end + + assert_equal "success", $test_after_initialize_block1 + assert_equal "congratulations", $test_after_initialize_block2 + end + + # i18n test "setting another default locale" do Rails::Initializer.run do |config| config.i18n.default_locale = :de @@ -62,11 +115,80 @@ module ApplicationTests assert_equal :de, I18n.default_locale end - test "load environment with global" do - app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'" - assert_nil $initialize_test_set_from_env - Rails::Initializer.run { } - assert_equal "success", $initialize_test_set_from_env + test "no config locales dir present should return empty load path" do + FileUtils.rm_rf "#{app_path}/config/locales" + Rails::Initializer.run do |c| + assert_equal [], c.i18n.load_path + end + end + + test "config locales dir present should be added to load path" do + Rails::Initializer.run do |c| + assert_equal ["#{app_path}/config/locales/en.yml"], c.i18n.load_path + end + end + + test "config defaults should be added with config settings" do + Rails::Initializer.run do |c| + c.i18n.load_path << "my/other/locale.yml" + end + + assert_equal [ + "#{app_path}/config/locales/en.yml", "my/other/locale.yml" + ], Rails.application.config.i18n.load_path + end + + # DB middleware + test "database middleware doesn't initialize when session store is not active_record" do + Rails::Initializer.run do |config| + config.action_controller.session_store = :cookie_store + end + + assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) + end + + test "database middleware doesn't initialize when activerecord is not in frameworks" do + Rails::Initializer.run do |c| + c.frameworks = [] + end + assert_equal [], Rails.application.config.middleware + end + + test "database middleware initializes when session store is active record" do + Rails::Initializer.run do |c| + c.action_controller.session_store = :active_record_store + end + + expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] + middleware = Rails.application.config.middleware.map { |m| m.klass } + assert_equal expects, middleware & expects + end + + test "ensure database middleware doesn't use action_controller on initializing" do + Rails::Initializer.run do |c| + c.frameworks -= [:action_controller] + c.action_controller.session_store = :active_record_store + end + + assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) + end + + # Pathview test + test "load view paths doesn't perform anything when action_view not in frameworks" do + Rails::Initializer.run do |c| + c.frameworks -= [:action_view] + end + assert_equal nil, ActionMailer::Base.template_root + assert_equal [], ActionController::Base.view_paths + end + + # Rails root test + test "Rails.root == RAILS_ROOT" do + assert_equal RAILS_ROOT, Rails.root.to_s + end + + test "Rails.root should be a Pathname" do + assert_instance_of Pathname, Rails.root end end end
\ No newline at end of file diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb index 2a433ea016..81e7f4d88c 100644 --- a/railties/test/application/plugins_test.rb +++ b/railties/test/application/plugins_test.rb @@ -23,6 +23,17 @@ module ApplicationTests ], Rails.application.config.loaded_plugins, @failure_tip end + test "no plugins are loaded if the configuration has an empty plugin list" do + Rails::Initializer.run { |c| c.plugins = [] } + assert_plugins [], Rails.application.config.loaded_plugins + end + + test "only the specified plugins are located in the order listed" do + plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] + Rails::Initializer.run { |c| c.plugins = plugin_names } + assert_plugins plugin_names, Rails.application.config.loaded_plugins + end + test "all plugins loaded after all" do Rails::Initializer.run do |config| config.plugins = [:stubby, :all, :acts_as_chunky_bacon] |