I have this error, when I'am testing my controller
ActionView::Template::Error: undefined method `full_name' for nil:NilClass
My tests:
class PostsControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@post = Post.create!(title: "my title", content: "bla bla bla")
user = User.create!(email: "example@mail.com", first_name: "name", last_name: "surename",
password: "password", password_confirmation: "password")
sign_in user
end
test "should show post" do
get :show, id: @post
assert_response :success
end
full_name method in model:
def full_name
"#{first_name} #{last_name}"
end
and my view:
Wrote by
= @post.user.full_name
Thanks for help
Aucun commentaire:
Enregistrer un commentaire