All assertions pass, but I’m getting an error:
1) Error:
test_should_perform_user_login(SessionsControllerTest):
NameError: undefined local variable or method `create' for StoriesController:Class
Here’s the code for the test:
def test_should_perform_user_login
post :create, :login => 'patrick', :password => 'sekrit'
assert_redirected_to stories_path
assert_equal users(:patrick).id, session[:user_id]
assert_equal users(:patrick), assigns(:current_user)
end
Here is where I define the create method in `sessions_controller.rb:
def create
@current_user = User.find_by_login_and_password(params[:login], params[:password])
if @current_user
session[:user_id] = @current_user.id
if session[:return_to]
redirect_to session[:return_to]
session[:return_to] = nil
else
redirect_to stories_path
end
else
render :action => 'new'
end
end
does this help?
I’m reading the book, ‘Simply Rails 2‘.
Biggest error fixed.
This comes from the
before_filtercall where you left a:(colon) off of the method symbols array.The next error was in
application.rb; its error was:There’s an extra underscore between the
redirect_tomethod and its argument,new_session_path.Next was a bogus selector in the stores test. Last I’m leaving as an exercise for the reader 🙂 (Hint: there are two problems.)