aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/lib/rails/application.rb4
-rw-r--r--railties/lib/rails/generators/actions.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/routes.rb2
-rw-r--r--railties/test/application/initializer_test.rb150
-rw-r--r--railties/test/application/routing_test.rb14
-rw-r--r--railties/test/paths_test.rb3
7 files changed, 96 insertions, 85 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 695a1d7c87..e6f2d30429 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -47,6 +47,10 @@ module Rails
end
end
+ def routes
+ ActionController::Routing::Routes
+ end
+
def call(env)
new.call(env)
end
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 2efdf29127..f95b15acce 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -273,7 +273,7 @@ module Rails
#
def route(routing_code)
log :route, routing_code
- sentinel = "ActionController::Routing::Routes.draw do |map|"
+ sentinel = "routes.draw do |map|"
in_root do
inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 6f71f7005f..30272ed9b2 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -62,9 +62,9 @@ module Rails::Generators
empty_directory "config"
inside "config" do
- copy_file "routes.rb"
- template "application.rb"
- template "environment.rb"
+ template "routes.rb"
+ template "application.rb"
+ template "environment.rb"
directory "environments"
directory "initializers"
diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
index e28ff42bdd..ac916e9d90 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
@@ -1,4 +1,4 @@
-ActionController::Routing::Routes.draw do |map|
+<%= app_const %>.routes.draw do |map|
# The priority is based upon order of creation:
# first created -> highest priority.
diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb
index fa00d287ca..b3eff1deb9 100644
--- a/railties/test/application/initializer_test.rb
+++ b/railties/test/application/initializer_test.rb
@@ -6,30 +6,29 @@ module ApplicationTests
def setup
build_app
- FileUtils.rm_rf("#{app_path}/config/environments")
boot_rails
require "rails"
end
test "initializing an application adds the application paths to the load path" do
- Rails::Initializer.run do |config|
- config.root = app_path
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
- Rails.initialize!
+ require "#{app_path}/config/environment"
assert $:.include?("#{app_path}/app/models")
end
test "adding an unknown framework raises an error" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.frameworks << :action_foo
- end
+ RUBY
require "active_support/core_ext/load_error"
assert_raises MissingSourceFile do
- Rails.initialize!
+ require "#{app_path}/config/environment"
end
end
@@ -41,12 +40,12 @@ module ApplicationTests
module Zoo::ReptileHouse ; end
ZOO
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.eager_load_paths = "#{app_path}/lib"
- end
+ RUBY
- Rails.initialize!
+ require "#{app_path}/config/environment"
assert Zoo
end
@@ -54,41 +53,43 @@ module ApplicationTests
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 { |config| config.root = app_path }
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+ require "#{app_path}/config/environment"
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.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.frameworks = []
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
end
end
test "after_initialize block works correctly" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.after_initialize { $test_after_initialize_block1 = "success" }
config.after_initialize { $test_after_initialize_block2 = "congratulations" }
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
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.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
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
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal "success", $test_after_initialize_block1
assert_equal "congratulations", $test_after_initialize_block2
@@ -96,35 +97,40 @@ module ApplicationTests
# i18n
test "setting another default locale" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.i18n.default_locale = :de
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal :de, I18n.default_locale
end
test "no config locales dir present should return empty load path" do
FileUtils.rm_rf "#{app_path}/config/locales"
- Rails::Initializer.run do |c|
- c.root = app_path
- assert_equal [], c.i18n.load_path
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+ require "#{app_path}/config/environment"
+
+ assert_equal [], Rails.application.config.i18n.load_path
end
test "config locales dir present should be added to load path" do
- Rails::Initializer.run do |c|
- c.root = app_path
- assert_equal ["#{app_path}/config/locales/en.yml"], c.i18n.load_path
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+
+ require "#{app_path}/config/environment"
+ assert_equal ["#{app_path}/config/locales/en.yml"], Rails.application.config.i18n.load_path
end
test "config defaults should be added with config settings" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.i18n.load_path << "my/other/locale.yml"
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.i18n.load_path << "my/other/locale.yml"
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal [
"#{app_path}/config/locales/en.yml", "my/other/locale.yml"
@@ -133,29 +139,31 @@ module ApplicationTests
# DB middleware
test "database middleware doesn't initialize when session store is not active_record" do
- Rails::Initializer.run do |config|
- config.root = app_path
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
config.action_controller.session_store = :cookie_store
- end
- Rails.initialize!
+ RUBY
+ require "#{app_path}/config/environment"
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.root = app_path
- c.frameworks = []
- end
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.frameworks = []
+ RUBY
+ require "#{app_path}/config/environment"
+
assert_equal [], Rails.application.config.middleware
end
test "database middleware initializes when session store is active record" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.action_controller.session_store = :active_record_store
- end
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.action_controller.session_store = :active_record_store
+ RUBY
+ require "#{app_path}/config/environment"
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
@@ -163,33 +171,33 @@ module ApplicationTests
end
test "ensure database middleware doesn't use action_controller on initializing" do
- Rails::Initializer.run do |c|
- c.root = app_path
- c.frameworks -= [:action_controller]
- c.action_controller.session_store = :active_record_store
- end
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.frameworks -= [:action_controller]
+ config.action_controller.session_store = :active_record_store
+ RUBY
+ require "#{app_path}/config/environment"
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.root = app_path
- c.frameworks -= [:action_view]
- end
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ config.frameworks -= [:action_view]
+ RUBY
+ require "#{app_path}/config/environment"
assert_equal nil, ActionMailer::Base.template_root
assert_equal [], ActionController::Base.view_paths
end
test "Rails.root should be a Pathname" do
- Rails::Initializer.run do |c|
- c.root = app_path
- end
- Rails.initialize!
+ add_to_config <<-RUBY
+ config.root = "#{app_path}"
+ RUBY
+ require "#{app_path}/config/environment"
assert_instance_of Pathname, Rails.root
end
end
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index 1add941ee0..7b1df7f45d 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -29,7 +29,7 @@ module ApplicationTests
RUBY
app_file 'config/routes.rb', <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ AppTemplate::Application.routes.draw do |map|
match ':controller(/:action)'
end
RUBY
@@ -56,7 +56,7 @@ module ApplicationTests
RUBY
app_file 'config/routes.rb', <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ AppTemplate::Application.routes.draw do |map|
match ':controller(/:action)'
end
RUBY
@@ -88,7 +88,7 @@ module ApplicationTests
RUBY
app_file 'config/routes.rb', <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ AppTemplate::Application.routes.draw do |map|
match ':controller(/:action)'
end
RUBY
@@ -110,7 +110,7 @@ module ApplicationTests
RUBY
app_file 'config/routes.rb', <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ AppTemplate::Application.routes.draw do |map|
match 'foo', :to => 'foo#index'
end
RUBY
@@ -125,7 +125,7 @@ module ApplicationTests
RUBY
plugin.write 'config/routes.rb', <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ AppTemplate::Application.routes.draw do |map|
match 'bar', :to => 'bar#index'
end
RUBY
@@ -152,7 +152,7 @@ module ApplicationTests
RUBY
app_file 'config/routes.rb', <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ AppTemplate::Application.routes.draw do |map|
match 'foo', :to => 'foo#bar'
end
RUBY
@@ -161,7 +161,7 @@ module ApplicationTests
assert_equal 'bar', last_response.body
app_file 'config/routes.rb', <<-RUBY
- ActionController::Routing::Routes.draw do |map|
+ AppTemplate::Application.routes.draw do |map|
match 'foo', :to => 'foo#baz'
end
RUBY
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index c724799d64..d60d6177f6 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -2,7 +2,6 @@ require 'abstract_unit'
require 'rails/paths'
class PathsTest < ActiveSupport::TestCase
-
def setup
@root = Rails::Application::Root.new("/foo/bar")
end
@@ -228,4 +227,4 @@ class PathsTest < ActiveSupport::TestCase
@root.app.eager_load!
assert_equal ["/foo/bar/app"], @root.load_paths
end
-end \ No newline at end of file
+end