[Rails] Using @current_user in tests
I am still trying to run this test
setup do
@comment = comments(:hello)
@comment.commenter = "cleb"
@comment.body = "hello"
@comment.user_id = 1
@cuser = User.find_by_id(session[:user_id])
end
test "should create comment" do
assert_difference('Comment.count') do
post :create, :comment => @comment.attributes, :user_id => 2
end
assert_redirected_to comment_path(assigns(:comment))
end
I get this error
test_should_create_comment(CommentsControllerTest):
NoMethodError: undefined method `login' for nil:NilClass
This is from comments.controller
def create
@cuser = @current_user
@user = User.find(params[:user_id])
@user.comments.create(:user_id => @user.id, :commenter =>
@cuser.login, :body => params[:comment][:body])
respond_to do |format|
format.js
format.html {redirect_to user_path}
end
end
How do I give the controller the required @current_user ?
(Derived from @current_user = User.find_by_id(session[:user_id])
What am I doing wrong?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home