aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application/finisher.rb7
-rw-r--r--railties/lib/rails/commands/console.rb2
-rw-r--r--railties/lib/rails/generators/generated_attribute.rb1
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile3
-rw-r--r--railties/test/application/rackup_test.rb7
-rw-r--r--railties/test/application/routing_test.rb17
-rw-r--r--railties/test/generators/generated_attribute_test.rb12
-rw-r--r--railties/test/generators/model_generator_test.rb6
-rw-r--r--railties/test/generators/scaffold_generator_test.rb6
9 files changed, 52 insertions, 9 deletions
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 855467227b..8fd2aa0bce 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -46,6 +46,13 @@ module Rails
ActiveSupport.run_load_hooks(:after_initialize, self)
end
+ # Force routes to be loaded just at the end and add it to to_prepare callbacks
+ initializer :set_routes_reloader do |app|
+ reloader = lambda { app.routes_reloader.execute_if_updated }
+ reloader.call
+ ActionDispatch::Callbacks.to_prepare(&reloader)
+ end
+
# Disable dependency loading during request cycle
initializer :disable_dependency_loading do
if config.cache_classes && !config.dependency_loading
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb
index 834a120c01..de2f190ad5 100644
--- a/railties/lib/rails/commands/console.rb
+++ b/railties/lib/rails/commands/console.rb
@@ -48,5 +48,5 @@ end
# Has to set the RAILS_ENV before config/application is required
if ARGV.first && !ARGV.first.index("-") && env = ARGV.pop # has to pop the env ARGV so IRB doesn't freak
- ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env
+ ENV['RAILS_ENV'] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
end
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb
index 3b9fff2f4a..64273e4ca4 100644
--- a/railties/lib/rails/generators/generated_attribute.rb
+++ b/railties/lib/rails/generators/generated_attribute.rb
@@ -6,6 +6,7 @@ module Rails
attr_accessor :name, :type
def initialize(name, type)
+ raise Thor::Error, "Missing type for attribute '#{name}'.\nExample: '#{name}:string' where string is the type." if type.blank?
@name, @type = name, type.to_sym
end
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index 3a8a63a2f9..d553c09484 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -23,8 +23,9 @@ gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= req
# Deploy with Capistrano
# gem 'capistrano'
-# To use debugger
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
+# gem 'ruby-debug19'
# Bundle the extra gems:
# gem 'bj'
diff --git a/railties/test/application/rackup_test.rb b/railties/test/application/rackup_test.rb
index 863950c04f..b0a9925890 100644
--- a/railties/test/application/rackup_test.rb
+++ b/railties/test/application/rackup_test.rb
@@ -31,13 +31,6 @@ module ApplicationTests
assert_kind_of Rails::Application, Rails.application
end
- # Passenger still uses AC::Dispatcher, so we need to
- # keep it working for now
- test "deprecated ActionController::Dispatcher still works" do
- rackup
- assert_kind_of Rails::Application, ActionController::Dispatcher.new
- end
-
test "the config object is available on the application object" do
rackup
assert_equal 'UTC', Rails.application.config.time_zone
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index febc53bac9..53bb7868da 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -215,6 +215,23 @@ module ApplicationTests
end
end
+ test 'routes are loaded just after initialization' do
+ require "#{app_path}/config/application"
+
+ ActiveSupport.on_load(:after_initialize) do
+ ::InitializeRackApp = lambda { |env| [200, {}, ["InitializeRackApp"]] }
+ end
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match 'foo', :to => ::InitializeRackApp
+ end
+ RUBY
+
+ get '/foo'
+ assert_equal "InitializeRackApp", last_response.body
+ end
+
test 'resource routing with irrigular inflection' do
app_file 'config/initializers/inflection.rb', <<-RUBY
ActiveSupport::Inflector.inflections do |inflect|
diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb
index de7e4de2a6..272e179fe3 100644
--- a/railties/test/generators/generated_attribute_test.rb
+++ b/railties/test/generators/generated_attribute_test.rb
@@ -108,4 +108,16 @@ class GeneratedAttributeTest < Rails::Generators::TestCase
)
end
end
+
+ def test_nil_type_raises_exception
+ assert_raise Thor::Error do
+ create_generated_attribute(nil, 'title')
+ end
+ end
+
+ def test_missing_type_raises_exception
+ assert_raise Thor::Error do
+ create_generated_attribute(:'', 'title')
+ end
+ end
end
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index ef415a4fed..f4a9a152c9 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -11,6 +11,12 @@ class ModelGeneratorTest < Rails::Generators::TestCase
assert_match /TestUnit options:/, content
end
+ def test_model_with_missing_attribute_type
+ content = capture(:stderr) { run_generator ["post", "title:string", "body"] }
+ assert_match /Missing type for attribute 'body'/, content
+ assert_match /Example: 'body:string' where string is the type/, content
+ end
+
def test_invokes_default_orm
run_generator
assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index f12445ae35..446bed3269 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -231,4 +231,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/
end
+
+ def test_scaffold_generator_outputs_error_message_on_missing_attribute_type
+ content = capture(:stderr) { run_generator ["post", "title:string", "body"]}
+ assert_match /Missing type for attribute 'body'/, content
+ assert_match /Example: 'body:string' where string is the type/, content
+ end
end