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
|
||||
9
test/fixtures/posts.yml
vendored
Normal file
9
test/fixtures/posts.yml
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
title: MyString
|
||||
body: MyText
|
||||
|
||||
two:
|
||||
title: MyString
|
||||
body: MyText
|
||||
7
test/models/post_test.rb
Normal file
7
test/models/post_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
43
test/system/posts_test.rb
Normal file
43
test/system/posts_test.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class PostsTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@post = posts(:one)
|
||||
end
|
||||
|
||||
test "visiting the index" do
|
||||
visit posts_url
|
||||
assert_selector "h1", text: "Posts"
|
||||
end
|
||||
|
||||
test "should create post" do
|
||||
visit posts_url
|
||||
click_on "New post"
|
||||
|
||||
fill_in "Body", with: @post.body
|
||||
fill_in "Title", with: @post.title
|
||||
click_on "Create Post"
|
||||
|
||||
assert_text "Post was successfully created"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should update Post" do
|
||||
visit post_url(@post)
|
||||
click_on "Edit this post", match: :first
|
||||
|
||||
fill_in "Body", with: @post.body
|
||||
fill_in "Title", with: @post.title
|
||||
click_on "Update Post"
|
||||
|
||||
assert_text "Post was successfully updated"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should destroy Post" do
|
||||
visit post_url(@post)
|
||||
click_on "Destroy this post", match: :first
|
||||
|
||||
assert_text "Post was successfully destroyed"
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue