jeudi 7 juillet 2016

Debug test method in rails

I am finishing up Michael Hartl's rails tutorial and am stuck here http://ift.tt/29oEcrr

Error in test/controllers/users_controller_test.rb caused by:

def setup
  @user = users(:michael)
  @other_user = users(:archer)
end

test "should redirect following when not logged in" do
  get following_user_path(@user)
  assert_redirected_to login_url
end

Error message:

      1) Error:
    UsersControllerTest#test_should_redirect_following_when_not_logged_in:
    ActionController::UrlGenerationError: No route matches {:action=>"/users/762146111/following", :controller=>"users"}
      test/controllers/users_controller_test.rb:62:in `block in <class:UsersControllerTest>'

The @user in the setup is pulled from test/fixtures/users.yml:

michael:
  name: Michael Example
  email: michael@example.com
  password_digest: <%= User.digest('password') %>
  admin: true
  activated: true
  activated_at: <%= Time.zone.now %>

I'm not sure why the error shows the route the test is attempting to hit as /users/762146111/following. 762146111 is where the user id should be which i assume should be 1. I have tried to do rake db:migrate:reset followed by rake db:seed but the id remains the same. I have also tried adding debugger into the method above the assertion but I am having trouble installing the sudo gem install ruby-debug. byebug also just runs through the tests without a breakpoint.

Any insight or ideas is greatly appreciated

Aucun commentaire:

Enregistrer un commentaire