dimanche 3 juillet 2016

Rails 4 -No route matches, route is defined. Only occurs in testing

So I am following Michael Hartl's Rails tutorial and I am on chapter 5 (http://ift.tt/1rhPuhm).

When I run the final test that he adds for the sign up link:

class UsersControllerTest < ActionDispatch::IntegrationTest

  test "should get new" do
    get signup_path
    assert_response :success
  end
end

I get this error when I run the test:

ERROR["test_should_get_new", UsersControllerTest, 2016-07-01 17:48:25 +0100]
 test_should_get_new#UsersControllerTest (1467391705.83s)
ActionController::UrlGenerationError:         ActionController::UrlGenerationError: No route matches {:action=>"/signup", :controller=>"users"}
            test/controllers/users_controller_test.rb:6:in `block in <class:UsersControllerTest>'
        test/controllers/users_controller_test.rb:6:in `block in <class:UsersControllerTest>'

Here is the routes file:

Rails.application.routes.draw do

  root 'static_pages#home'
  get '/signup', to: 'users#new'
  get '/help', to: 'static_pages#help'
  get '/about', to: 'static_pages#about'
  get '/contact', to: 'static_pages#contact'

end

I have used the signup_path helper in the views as a link and they work fine.

Why is test trying to access an action called "/signup" when I have defined in the routes that "signup" should become the new action in the users controller?

Aucun commentaire:

Enregistrer un commentaire