Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'test_helper'
- class PostsControllerTest < ActionDispatch::IntegrationTest
- include Devise::Test::IntegrationHelpers
- setup do
- @post = posts(:one)
- @user = users(:one)
- end
- test "should get index" do
- get posts_url
- assert_response :success
- end
- test "should not get new" do
- get new_post_url
- assert_response :redirect
- end
- test "should not create post" do
- assert_difference('Post.count', 0) do
- post posts_url, params: { post: { body: 'Body', title: 'Title' } }
- end
- assert_redirected_to new_user_session_path
- end
- test "should show post" do
- get post_url(@post)
- assert_response :success
- end
- test "should not get edit" do
- get edit_post_url(@post)
- assert_response :redirect
- end
- test "should not update post" do
- patch post_url(@post), params: { post: { body: @post.body, title: @post.title } }
- assert_redirected_to new_user_session_path
- end
- test "should not destroy post" do
- assert_difference('Post.count', 0) do
- delete post_url(@post)
- end
- assert_redirected_to new_user_session_path
- end
- test "should get index auth" do
- sign_in @user
- get posts_url
- assert_response :success
- end
- test "should get new auth" do
- sign_in @user
- get new_post_url
- assert_response :success
- end
- test "should create post auth" do
- sign_in @user
- assert_difference('Post.count') do
- post posts_url, params: { post: { body: 'Body', title: 'Title' } }
- end
- assert_redirected_to post_url(Post.last)
- end
- test "should show post auth" do
- get post_url(@post)
- assert_response :success
- end
- test "should get edit auth" do
- sign_in @user
- get edit_post_url(@post)
- assert_response :success
- end
- test "should update post auth" do
- sign_in @user
- patch post_url(@post), params: { post: { body: @post.body, title: @post.title } }
- assert_redirected_to post_url(@post)
- end
- test "should destroy post auth" do
- sign_in @user
- assert_difference('Post.count', -1) do
- delete post_url(@post)
- end
- assert_redirected_to posts_url
- end
- test "should not destroy post auth" do
- sign_in @user
- assert_difference('Post.count', 0) do
- delete post_url(posts(:three))
- end
- assert_redirected_to root_path
- end
- test "should not get edit auth" do
- sign_in @user
- get edit_post_url(posts(:three))
- assert_response :redirect
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement