This project is archived and is in readonly mode.

#3605 ✓resolved
Sam Ruby

"root" doesn't work as advertised in new routing DSL

Reported by Sam Ruby | December 21st, 2009 @ 08:21 PM | in 3.0.2

# The following produces No route matches {:controller=>"welcome"}
ruby script/generate controller welcome index
sed -i -e 's/# root/root/' config/routes.rb
sed -i -e 's/assert true/get root_path/' test/functional/welcome_controller_test.rb
rake db:migrate
rake test:functionals

# Adding an action produces: No route matches {:controller=>"welcome", :action=>"/"}
sed -i -e 's/welcome/welcome#index/' config/routes.rb
rake test:functionals

Comments and changes to this ticket

  • DHH

    DHH December 22nd, 2009 @ 12:56 AM

    • State changed from “open” to “resolved”

    Fixed the documentation instead. Allowing the :to to use a string to signify the controller would clash with the regular use of :to that uses a symbol for an action.

  • Sam Ruby

    Sam Ruby December 22nd, 2009 @ 03:26 AM

    • State changed from “resolved” to “open”
    • Assigned user changed from “josh” to “DHH”

    Sorry to reopen this on you, but the last two lines of the script above shows that adding #index doesn't work either. I'm flexible on what the syntax is, but I would like to have one that works.

  • DHH

    DHH December 22nd, 2009 @ 05:51 AM

    • State changed from “open” to “resolved”

    Works for me. Added a test to the suite testing root specifically and that works too. Think it must be something in your test script.

  • Sam Ruby

    Sam Ruby December 22nd, 2009 @ 12:18 PM

    My ENTIRE script is posted at the top of this ticket. Now that you have committed a change to the generated routes.rb, the last two lines are not necessary.

    It can be 100% reproduced with an new and otherwise completely empty project.

    In words, the script is as follows:

    1) Generate a controller named welcome with a single action, named index.
    2) Uncomment out the root line in config/routes.rb
    3) Change "assert true" to "get root_path" in test/functional/welcome_controller_test.rb
    4) Execute "rake db:migrate"
    5) Execute "rake test:functionals"

    If there is something wrong in that five step test script above, please tell me what it might be. Otherwise, I suspect that something about the unit test environment doesn't match how Rails is actually run.

    A complete set of output is included below:

    $ rake test:functionals
    (in /home/rubys/tmp/testapp)
    DEPRECATION WARNING: ActiveSupport::DeprecatedCallbacks has been deprecated in favor of ActiveSupport::Callbacks. (called from included at /home/rubys/tmp/testapp/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:7)
    Loaded suite /usr/lib/ruby/1.8/rake/rake_test_loader
    Started
    E
    Finished in 0.108231 seconds.
    
      1) Error:
    test_the_truth(WelcomeControllerTest):
    ActionController::RoutingError: No route matches {:controller=>"welcome", :action=>"/"}
        /test/functional/welcome_controller_test.rb:6:in `test_the_truth'
    
    1 tests, 0 assertions, 0 failures, 1 errors
    rake aborted!
    Command failed with status (1): [/usr/bin/ruby1.8 -I"/home/rubys/tmp/testap...]
    
    (See full trace by running task with --trace)
    

    I will seek somebody else to reproduce this, and if they can, will ask them to reopen the ticket.

  • DHH

    DHH December 22nd, 2009 @ 03:31 PM

    Your functional test is the problem. You can't use paths for the get there. That's what you do in integration tests. In functional, you'd do get :index.

    I've verified that root :to => "welcome#index" works fine in the browser as well.

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages