require 'test_helper'

class CommentsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @post = posts(:one)
    @comment = comments(:one)
  end

  test 'should get index' do
    get comments_url(post_id: @post)
    assert_response :success
  end

  test 'should get new' do
    get new_comment_url(post_id: @post)
    assert_response :success
  end

  test 'should create comment' do
    assert_difference('Comment.count') do
      post comments_url(post_id: @post), params: {
        comment: { body: @comment.body }
      }
    end

    assert_redirected_to comment_path(Comment.last)
  end

  test 'should show comment' do
    get comment_url(@comment)
    assert_response :success
  end

  test 'should get edit' do
    get edit_comment_url(@comment)
    assert_response :success
  end

  test 'should update comment' do
    patch comment_url(@comment), params: {
      comment: { body: @comment.body }
    }
    assert_redirected_to comment_path(@comment)
  end

  test 'should destroy comment' do
    assert_difference('Comment.count', -1) do
      delete comment_url(@comment)
    end

    assert_redirected_to comments_path
  end
end
