aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-09-26 00:17:06 +0200
committerPiotr Sarnacki <drogus@gmail.com>2010-09-30 09:47:05 +0200
commitec5d846ac6137e60d81257041e4fde82c0480b32 (patch)
tree4a0fb0b3eb176c908c68b8f01e3b3697a6522133 /railties/test
parent22b11a41cc764bc0f7b0c0f518a5289230428597 (diff)
downloadrails-ec5d846ac6137e60d81257041e4fde82c0480b32.tar.gz
rails-ec5d846ac6137e60d81257041e4fde82c0480b32.tar.bz2
rails-ec5d846ac6137e60d81257041e4fde82c0480b32.zip
Properly reload routes defined in class definition
Sometimes it's easier to define routes inside Engine or Application class definition (e.g. one file applications). The problem with such case is that if there is a plugin that has config/routes.rb file, it will trigger routes reload on application. Since routes definition for application is not in config/routes.rb file routes_reloader will fail to reload application's routes properly. With this commit you can pass routes definition as a block to routes method, which will allow to properly reload it: class MyApp::Application < Rails::Application routes do resources :users end end
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/railties/engine_test.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 17bffe05e1..2b9d728b0c 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -663,5 +663,45 @@ module RailtiesTest
assert_equal AppTemplate._railtie, AppTemplate::Engine
end
+
+ test "properly reload routes" do
+ # when routes are inside application class definition
+ # they should not be reloaded when engine's routes
+ # file has changed
+ add_to_config <<-RUBY
+ routes do
+ mount lambda{|env| [200, {}, ["foo"]]} => "/foo"
+ mount Bukkits::Engine => "/bukkits"
+ end
+ RUBY
+
+ FileUtils.rm(File.join(app_path, "config/routes.rb"))
+
+ @plugin.write "config/routes.rb", <<-RUBY
+ Bukkits::Engine.routes.draw do
+ mount lambda{|env| [200, {}, ["bar"]]} => "/bar"
+ end
+ RUBY
+
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ module Bukkits
+ class Engine < ::Rails::Engine
+ namespace(Bukkits)
+ end
+ end
+ RUBY
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ boot_rails
+
+ require "#{rails_root}/config/environment"
+ get "/foo"
+ assert_equal "foo", last_response.body
+
+ get "/bukkits/bar"
+ assert_equal "bar", last_response.body
+ end
end
end