Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Michael Hartl Rails Tutorial chapter 7 error Action not found in UsersController

I'm following Michael Hartl's Rails Tutorial at the moment and I've managed to 7.22 without any major hitches. However I'm stumped by the output from the testing which says:

Failures:

  1) UserPages signup with invalid information should not create a user
     Failure/Error: expect{click_button submit }.not_to change(User, :count)
     AbstractController::ActionNotFound:
       The action 'create' could not be found for UsersController
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:29:in `block (5 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:29:in `block (4 levels) in <top (required)>'

  2) UserPages signup with valid information should create a user
     Failure/Error: expect{click_button submit}.to change(User, :count).by(1)
     AbstractController::ActionNotFound:
       The action 'create' could not be found for UsersController
     # (eval):2:in `click_button'
     # ./spec/requests/user_pages_spec.rb:42:in `block (5 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:42:in `block (4 levels) in <top (required)>'

Finished in 0.7718 seconds
6 examples, 2 failures

I've added the following to my users controllers page as instructed by the tutorial:

class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

end

but it still doesn't seem to work. I've tried adding a create method but that just throws back a missing template error...

In case it helps here's the output of the rake routes command:

~/dev/rails/sample_app$ rake routes
    users GET    /users(.:format)          users#index
          POST   /users(.:format)          users#create
 new_user GET    /users/new(.:format)      users#new
edit_user GET    /users/:id/edit(.:format) users#edit
     user GET    /users/:id(.:format)      users#show
          PUT    /users/:id(.:format)      users#update
          DELETE /users/:id(.:format)      users#destroy
     root        /                         static_pages#home
   signup        /signup(.:format)         users#new
     help        /help(.:format)           static_pages#help
    about        /about(.:format)          static_pages#about
  contact        /contact(.:format)        static_pages#contact

In response to a comment, the tests which are failing are:

   describe "signup" do

      before{ visit signup_path }
      let(:submit) {"Create my account"}

      describe "with invalid information" do
        it "should not create a user" do
          expect{click_button submit }.not_to change(User, :count)
        end
      end

      describe "with valid information" do
        before do
          fill_in "Name", with: "Example User"
          fill_in "Email", with: "[email protected]"
          fill_in "Password", with: "foobar"
          fill_in "Confirmation", with: "foobar"
        end

        it "should create a user" do
          expect{click_button submit}.to change(User, :count).by(1)
        end
      end
    end

Thanks in advance for any advice!

like image 501
TangoKilo Avatar asked Jun 04 '12 16:06

TangoKilo


2 Answers

The tests shouldn't be passing at that point. Keep following the tutorial and you'll see how it works.

like image 86
mhartl Avatar answered Oct 17 '22 18:10

mhartl


I struggled with the same thing for about a half hour before goggling the error code and coming directly here. @mhartl is obviously correct and there is no typo in the tutorial, it is just that it is a little confusing when he says that the "tests for the signup page" should be working again. He mentioned nothing about submissions from the signup page (which should be the two tests that are failing at this point in the tutorial).

like image 29
Daniel Kuntz Avatar answered Oct 17 '22 18:10

Daniel Kuntz