<commit_before>require 'test_helper'

class CommentsControllerTest < ActionController::TestCase
  setup do
    @post = create :post

    @request.env['HTTP_AUTHORIZATION'] =
      ActionController::HttpAuthentication::
      Basic.encode_credentials("dhhh", "secret")
  end

  test "should create comment" do
    attrs = attributes_for :comment

    post :create, comment: attrs, post_id: @post.id
    assert_response :redirect

    @post.reload

    #TODO разобраться с использованием .extract!()
    created_comment = Comment.where(attrs.extract!(:commenter)).first
    assert created_comment

    assert Comment.exists?(created_comment)
    assert @post.comments.include?(created_comment)
  end

  test "should destroy comment" do
    #TODO убедиться что не overengeneering и нет лишних assert'ов
    @comment = create :comment, post_id: @post.id
    assert @post.comments.include?(@comment)

    delete :destroy, id: @comment.id, post_id: @post.id
    assert_response :redirect

    @post.reload

    assert !Comment.exists?(@comment)<commit_msg>refactor test comment controller<commit_after>require 'test_helper'

class CommentsControllerTest < ActionController::TestCase
  setup do
    @post = create :post

    @request.env['HTTP_AUTHORIZATION'] =
      ActionController::HttpAuthentication::
      Basic.encode_credentials("dhhh", "secret")
  end

  test "should create comment" do
    attrs = attributes_for :comment

    post :create, comment: attrs, post_id: @post
    assert_response :redirect

    #TODO разобраться с использованием .extract!()
    created_comment = Comment.where(attrs.extract!(:commenter)).first
    assert created_comment

    assert @post.comments.include?(created_comment)
  end

  test "should destroy comment" do
    @comment = create :comment, post: @post

    delete :destroy, id: @comment.id, post_id: @post.id
    assert_response :redirect

{'fraction_non_alphanumeric': 0.09835194045720362, 'fraction_numerical': 0.0, 'mean_word_length': 4.156164383561644, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6429855', 'n_tokens_mistral': 556, 'n_tokens_neox': 553, 'n_words': 141}