From 76836ef7db8d0b1e40492c9a62f7c637718d813d Mon Sep 17 00:00:00 2001 From: eileencodes Date: Sat, 2 May 2015 10:26:22 -0400 Subject: [PATCH] Use `def before_setup` instead of `setup do` `setup do` creates unnecessary allocations of proc objects in test callbacks. This prevents that from happening and results in faster code. Originally I had done this as `def setup` and all Railties tests passed. See 044f9ab. Later it was reported there was an issue with this that caused routes in tests to be nil because devs don't generally call `super` in their test setups. Because of that I reverted the commit until I could find a suitble replacement. `before_setup` esentially does the same thing but without the requirement that applications call `super` in their test setups. --- railties/lib/rails/test_help.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 5cf44e63319..a83e39faee6 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -27,13 +27,15 @@ if defined?(ActiveRecord::Base) end class ActionController::TestCase - setup do + def before_setup @routes = Rails.application.routes + super end end class ActionDispatch::IntegrationTest - setup do + def before_setup @routes = Rails.application.routes + super end end