aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-04-28 14:27:08 -0700
committerPiotr Sarnacki <drogus@gmail.com>2012-04-28 14:38:12 -0700
commit5a2fdaa27796502daf0fb2314e599b76049296d4 (patch)
tree7d9598ee7eb3a389a70f03e1c249ba7377eb2627
parentd9239fd4c9e35f93e6594b1d95af85e772fc2b26 (diff)
downloadrails-5a2fdaa27796502daf0fb2314e599b76049296d4.tar.gz
rails-5a2fdaa27796502daf0fb2314e599b76049296d4.tar.bz2
rails-5a2fdaa27796502daf0fb2314e599b76049296d4.zip
Fix Engine#routes to not call draw_paths multiple times
-rw-r--r--railties/lib/rails/engine.rb6
-rw-r--r--railties/test/unit/engine_test.rb10
2 files changed, 14 insertions, 2 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index d81f9cf7ff..d4f632702c 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -486,8 +486,10 @@ module Rails
end
def routes
- @routes ||= ActionDispatch::Routing::RouteSet.new
- @routes.draw_paths.concat paths["config/routes"].paths
+ @routes ||= ActionDispatch::Routing::RouteSet.new.tap do |routes|
+ routes.draw_paths.concat paths["config/routes"].paths
+ end
+
@routes.append(&Proc.new) if block_given?
@routes
end
diff --git a/railties/test/unit/engine_test.rb b/railties/test/unit/engine_test.rb
index 977f46ecea..02d40d97f6 100644
--- a/railties/test/unit/engine_test.rb
+++ b/railties/test/unit/engine_test.rb
@@ -12,5 +12,15 @@ module Unit
assert !engine.routes?
end
+
+ it "does not add more paths to routes on each call" do
+ engine = Class.new(Rails::Engine)
+
+ engine.routes
+ length = engine.routes.draw_paths.length
+
+ engine.routes
+ assert_equal length, engine.routes.draw_paths.length
+ end
end
end