Skip to content

Commit

Permalink
Fix Engine#routes to not call draw_paths multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
drogus committed Apr 28, 2012
1 parent d9239fd commit 5a2fdaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions railties/lib/rails/engine.rb
Expand Up @@ -486,8 +486,10 @@ def env_config
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
Expand Down
10 changes: 10 additions & 0 deletions railties/test/unit/engine_test.rb
Expand Up @@ -12,5 +12,15 @@ def initialize(*args)

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

0 comments on commit 5a2fdaa

Please sign in to comment.