aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-12-13 11:23:21 +0100
committerJosé Valim <jose.valim@gmail.com>2011-12-13 11:23:21 +0100
commit80256abb39332dd49996b909d6f0413a15291a90 (patch)
treefb0492e9ba488746a31d7fcc26873daf5099fb32 /railties
parent1f5b9bbdb377c1b0e29650a103bf53526ceefdd5 (diff)
downloadrails-80256abb39332dd49996b909d6f0413a15291a90.tar.gz
rails-80256abb39332dd49996b909d6f0413a15291a90.tar.bz2
rails-80256abb39332dd49996b909d6f0413a15291a90.zip
FileUpdateChecker should be able to handle deleted files.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application.rb2
-rw-r--r--railties/lib/rails/application/finisher.rb7
-rw-r--r--railties/lib/rails/application/routes_reloader.rb15
-rw-r--r--railties/test/application/loading_test.rb32
4 files changed, 47 insertions, 9 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 75f2b9a3bd..22689cc278 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -124,7 +124,7 @@ module Rails
dirs[path.to_s] = [:rb]
end
- files << dirs
+ [files, dirs]
end
# Initialize the application passing the given group. By default, the
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 064723c1e0..2ce2980b97 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -64,10 +64,9 @@ module Rails
# routes added in the hook are still loaded.
initializer :set_routes_reloader_hook do
reloader = routes_reloader
- hook = lambda { reloader.execute_if_updated }
- hook.call
+ reloader.execute_if_updated
self.reloaders << reloader
- ActionDispatch::Reloader.to_prepare(&hook)
+ ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated }
end
# Set app reload just after the finisher hook to ensure
@@ -79,7 +78,7 @@ module Rails
end
if config.reload_classes_only_on_change
- reloader = config.file_watcher.new(watchable_args, true, &callback)
+ reloader = config.file_watcher.new(*watchable_args, &callback)
self.reloaders << reloader
# We need to set a to_prepare callback regardless of the reloader result, i.e.
# models should be reloaded if any of the reloaders (i18n, routes) were updated.
diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb
index e080481976..ef7e733ce4 100644
--- a/railties/lib/rails/application/routes_reloader.rb
+++ b/railties/lib/rails/application/routes_reloader.rb
@@ -4,11 +4,10 @@ module Rails
class Application
class RoutesReloader
attr_reader :route_sets, :paths
- delegate :execute_if_updated, :updated?, :to => :@updater
+ delegate :execute_if_updated, :execute, :updated?, :to => :updater
- def initialize(updater=ActiveSupport::FileUpdateChecker)
+ def initialize
@paths = []
- @updater = updater.new(paths) { reload! }
@route_sets = []
end
@@ -20,7 +19,15 @@ module Rails
revert
end
- protected
+ private
+
+ def updater
+ @updater ||= begin
+ updater = ActiveSupport::FileUpdateChecker.new(paths) { reload! }
+ updater.execute
+ updater
+ end
+ end
def clear!
route_sets.each do |routes|
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index 5fb04cb3b3..9c77f6210a 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -175,6 +175,38 @@ class LoadingTest < Test::Unit::TestCase
assert_equal "1", last_response.body
end
+ test "added files also trigger reloading" do
+ add_to_config <<-RUBY
+ config.cache_classes = false
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ $counter = 0
+ AppTemplate::Application.routes.draw do
+ match '/c', :to => lambda { |env| User; [200, {"Content-Type" => "text/plain"}, [$counter.to_s]] }
+ end
+ RUBY
+
+ app_file "app/models/user.rb", <<-MODEL
+ class User
+ $counter += 1
+ end
+ MODEL
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ require "#{rails_root}/config/environment"
+
+ get "/c"
+ assert_equal "1", last_response.body
+
+ app_file "db/schema.rb", ""
+
+ get "/c"
+ assert_equal "2", last_response.body
+ end
+
protected
def setup_ar!