Skip to content

Instantly share code, notes, and snippets.

@itsmeurbi
Created June 28, 2022 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsmeurbi/e55e310b958bd7f1246ebc66a2638586 to your computer and use it in GitHub Desktop.
Save itsmeurbi/e55e310b958bd7f1246ebc66a2638586 to your computer and use it in GitHub Desktop.
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
test 'it is not valid without a post' do
comment = Comment.new
refute comment.valid?
assert_equal ['must exist'], comment.errors.messages[:post]
end
test 'it is not valid without content' do
comment = Comment.new
refute comment.valid?
assert_equal ["can't be blank"], comment.errors.messages[:content]
end
test 'it is valid with a post and content' do
post = Post.new(title: 'My post', content: 'My new blog post')
comment = Comment.new(post: post, content: 'Nice post!')
assert comment.valid?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment