Created
June 28, 2022 03:57
-
-
Save itsmeurbi/046774a75c4285bbbd5698e0e8075dc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class PostsControllerTest < ActionDispatch::IntegrationTest | |
test '#index returns a list of all available posts' do | |
get posts_path | |
assert_response :success | |
end | |
test '#new returns a posts form' do | |
get new_post_path | |
assert_response :success | |
end | |
test '#create stores a post record' do | |
post posts_path, params: { post: { title: 'My post', content: 'Lorem impsum' } } | |
assert_redirected_to posts_path | |
assert_equal 'Post created!', flash[:notice] | |
end | |
test '#show returns a post' do | |
post = Post.create(title: 'My post', content: 'Lorm impsum') | |
get post_path(post) | |
assert_response :success | |
end | |
test '#edit returns a form for given post' do | |
post = Post.create(title: 'My post', content: 'Lorm impsum') | |
get edit_post_path(post) | |
assert_response :success | |
end | |
test '#update changes attribute to given post' do | |
post = Post.create(title: 'My post', content: 'Lorm impsum') | |
patch post_path(post), params: { post: { title: 'Updated poast' } } | |
assert_redirected_to posts_path | |
assert_equal 'Post updated!', flash[:notice] | |
end | |
test '#destroy gets rid of given post' do | |
post = Post.create(title: 'My post', content: 'Lorm impsum') | |
delete post_path(post) | |
assert_redirected_to posts_path | |
assert_equal 'Post deleted!', flash[:notice] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment