<commit_before>require 'spec_helper'
require 'rating/comments_controller'

describe Rating::CommentsController, type: :controller do
  render_views

  let(:valid_attributes) { { "text" => FFaker::CheesyLingo.sentence } }
  let(:valid_session) { {} }
  let(:user) { create(:user) }

  before do
    user.roles.create(name: 'reviewer')
    sign_in user
  end

  describe 'application comment' do
    let(:application) { create(:application) }
    let(:params) { {commentable_id: application.id, commentable_type: 'Application'} }

    context 'with valid params' do
      it 'creates a new Comment' do
        expect {
          post :create, { params: {comment: params.merge(valid_attributes)} }, valid_session
        }.to change(Comment, :count).by(1)
      end

      it 'redirects to comment on application page' do
        post :create, { params: {comment: params.merge(valid_attributes)} }, valid_session
        expect(response).to redirect_to([:rating, application, anchor: 'comment_1'])
      end
    end
    context 'with invalid params (no text)' do
      it 'does not create new Comment' do
        expect {
          post :create, { params: {comment: params} }, valid_session
        }.not_to change(Comment, :count)
      end

      it 'redirects to the application page with flash' do
        post :create, { params: {comment: params} }, valid_session
        expect(flash[:alert]).to be_present
        expect(response).to redirect_to([:rating, application])
      end
    end
  end
end<commit_msg>Fix faky test<commit_after>require 'spec_helper'
require 'rating/comments_controller'

describe Rating::CommentsController, type: :controller do
  render_views

  let(:valid_attributes) { { "text" => FFaker::CheesyLingo.sentence } }
  let(:valid_session) { {} }
  let(:user) { create(:user) }

  before do
    user.roles.create(name: 'reviewer')
    sign_in user
  end

  describe 'application comment' do
    let(:application) { create(:application) }
    let(:params) { {commentable_id: application.id, commentable_type: 'Application'} }

    context 'with valid params' do
      it 'creates a new Comment' do
        expect {
          post :create, { params: {comment: params.merge(valid_attributes)} }, valid_session
        }.to change(Comment, :count).by(1)
      end

      it 'redirects to comment on application page' do
        post :create, { params: {comment: params.merge(valid_attributes)} }, valid_session
        id = Comment.last.id
        expect(response).to redirect_to([:rating, application, anchor: "comment_#{id}"])
      end
    end
    context 'with invalid params (no text)' do
      it 'does not create new Comment' do
        expect {
          post :create, { params: {comment: params} }, valid_session
        }.not_to change(Comment, :count)
      end

      it 'redirects to the application page with flash' do
        post :create, { params: {comment: params} }, valid_session
        expect(flash[:alert]).to be_present
        expect(response).to redirect_to([:rating, application])
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11507028440666885, 'fraction_numerical': 0.0009807126511932004, 'mean_word_length': 3.191780821917808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4818163', 'n_tokens_mistral': 895, 'n_tokens_neox': 869, 'n_words': 255}