Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 2.50 KB | None | 0 0
  1. require 'test_helper'
  2.  
  3. class PostsControllerTest < ActionDispatch::IntegrationTest
  4.   include Devise::Test::IntegrationHelpers
  5.   setup do
  6.     @post = posts(:one)
  7.     @user = users(:one)
  8.   end
  9.  
  10.   test "should get index" do
  11.     get posts_url
  12.     assert_response :success
  13.   end
  14.  
  15.   test "should not get new" do
  16.     get new_post_url
  17.     assert_response :redirect
  18.   end
  19.  
  20.   test "should not create post" do
  21.     assert_difference('Post.count', 0) do
  22.       post posts_url, params: { post: { body: 'Body', title: 'Title' } }
  23.     end
  24.  
  25.     assert_redirected_to new_user_session_path
  26.   end
  27.  
  28.   test "should show post" do
  29.     get post_url(@post)
  30.     assert_response :success
  31.   end
  32.  
  33.   test "should not get edit" do
  34.     get edit_post_url(@post)
  35.     assert_response :redirect
  36.   end
  37.  
  38.   test "should not update post" do
  39.     patch post_url(@post), params: { post: { body: @post.body, title: @post.title } }
  40.     assert_redirected_to new_user_session_path
  41.   end
  42.  
  43.   test "should not destroy post" do
  44.     assert_difference('Post.count', 0) do
  45.       delete post_url(@post)
  46.     end
  47.  
  48.     assert_redirected_to new_user_session_path
  49.   end
  50.  
  51.   test "should get index auth" do
  52.     sign_in @user
  53.     get posts_url
  54.     assert_response :success
  55.   end
  56.  
  57.   test "should get new auth" do
  58.     sign_in @user
  59.     get new_post_url
  60.     assert_response :success
  61.   end
  62.  
  63.   test "should create post auth" do
  64.     sign_in @user
  65.     assert_difference('Post.count') do
  66.       post posts_url, params: { post: { body: 'Body', title: 'Title' } }
  67.     end
  68.  
  69.     assert_redirected_to post_url(Post.last)
  70.   end
  71.  
  72.   test "should show post auth" do
  73.     get post_url(@post)
  74.     assert_response :success
  75.   end
  76.  
  77.   test "should get edit auth" do
  78.     sign_in @user
  79.     get edit_post_url(@post)
  80.     assert_response :success
  81.   end
  82.  
  83.   test "should update post auth" do
  84.     sign_in @user
  85.     patch post_url(@post), params: { post: { body: @post.body, title: @post.title } }
  86.     assert_redirected_to post_url(@post)
  87.   end
  88.  
  89.   test "should destroy post auth" do
  90.     sign_in @user
  91.     assert_difference('Post.count', -1) do
  92.       delete post_url(@post)
  93.     end
  94.  
  95.     assert_redirected_to posts_url
  96.   end
  97.  
  98.   test "should not destroy post auth" do
  99.     sign_in @user
  100.     assert_difference('Post.count', 0) do
  101.       delete post_url(posts(:three))
  102.     end
  103.     assert_redirected_to root_path
  104.   end
  105.  
  106.   test "should not get edit auth" do
  107.     sign_in @user
  108.     get edit_post_url(posts(:three))
  109.     assert_response :redirect
  110.   end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement