Add posts test
This commit is contained in:
parent
0df07c478a
commit
76229c8cc5
17 changed files with 278 additions and 0 deletions
48
test/controllers/posts_controller_test.rb
Normal file
48
test/controllers/posts_controller_test.rb
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
require "test_helper"
|
||||
|
||||
class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@post = posts(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get posts_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_post_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create post" do
|
||||
assert_difference("Post.count") do
|
||||
post posts_url, params: { post: { body: @post.body, title: @post.title } }
|
||||
end
|
||||
|
||||
assert_redirected_to post_url(Post.last)
|
||||
end
|
||||
|
||||
test "should show post" do
|
||||
get post_url(@post)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_post_url(@post)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update post" do
|
||||
patch post_url(@post), params: { post: { body: @post.body, title: @post.title } }
|
||||
assert_redirected_to post_url(@post)
|
||||
end
|
||||
|
||||
test "should destroy post" do
|
||||
assert_difference("Post.count", -1) do
|
||||
delete post_url(@post)
|
||||
end
|
||||
|
||||
assert_redirected_to posts_url
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue