aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxed.co>2017-02-21 12:49:25 +0000
committerAndrew White <andrew.white@unboxed.co>2017-02-21 15:30:47 +0000
commitc116eaf2217abbc83ad76ac09c4fb89e033e1cdd (patch)
tree36ccb62c9606f2d016b29a7895d2de013a4134d0 /railties
parent81a6761af2b20183c78853caa4daea4ccf6b4cb7 (diff)
downloadrails-c116eaf2217abbc83ad76ac09c4fb89e033e1cdd.tar.gz
rails-c116eaf2217abbc83ad76ac09c4fb89e033e1cdd.tar.bz2
rails-c116eaf2217abbc83ad76ac09c4fb89e033e1cdd.zip
Prefer remove_method over undef_method
Using `undef_method` means that when a route is removed any other implementations of that method in the ancestor chain are inaccessible so instead use `remove_method` which restores access to the ancestor.
Diffstat (limited to 'railties')
-rw-r--r--railties/test/application/routing_test.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb
index 6c34c72564..1132e7fb55 100644
--- a/railties/test/application/routing_test.rb
+++ b/railties/test/application/routing_test.rb
@@ -618,5 +618,63 @@ module ApplicationTests
get "/yazilar"
assert_equal 200, last_response.status
end
+
+ test "reloading routes removes methods and doesn't undefine them" do
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ get '/url', to: 'url#index'
+ end
+ RUBY
+
+ app_file "app/models/url_helpers.rb", <<-RUBY
+ module UrlHelpers
+ def foo_path
+ "/foo"
+ end
+ end
+ RUBY
+
+ app_file "app/models/context.rb", <<-RUBY
+ class Context
+ include UrlHelpers
+ include Rails.application.routes.url_helpers
+ end
+ RUBY
+
+ controller "url", <<-RUBY
+ class UrlController < ApplicationController
+ def index
+ context = Context.new
+ render plain: context.foo_path
+ end
+ end
+ RUBY
+
+ get "/url"
+ assert_equal "/foo", last_response.body
+
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ get '/url', to: 'url#index'
+ get '/bar', to: 'foo#index', as: 'foo'
+ end
+ RUBY
+
+ Rails.application.reload_routes!
+
+ get "/url"
+ assert_equal "/bar", last_response.body
+
+ app_file "config/routes.rb", <<-RUBY
+ Rails.application.routes.draw do
+ get '/url', to: 'url#index'
+ end
+ RUBY
+
+ Rails.application.reload_routes!
+
+ get "/url"
+ assert_equal "/foo", last_response.body
+ end
end
end