<commit_before>require 'spec_helper'

describe NewsFeedItemCommentsController do
  let(:user) { User.make! }
  let(:task) { Task.make! }
  let(:nfi_post) { NewsFeedItemPost.make! }
  let(:task_nfi) { NewsFeedItem.make!(target: task) }
  let(:post_nfi) { nfi_post.news_feed_item }
  let(:product) { task.product }

end<commit_msg>Add tests for NewsFeedItemCommentsController<commit_after>require 'spec_helper'

describe NewsFeedItemCommentsController do
  let(:user) { User.make! }
  let(:task) { Task.make! }
  let(:nfi_post) { NewsFeedItemPost.make! }
  let(:task_nfi) { NewsFeedItem.make!(target: task) }
  let(:post_nfi) { nfi_post.news_feed_item }
  let(:product) { task.product }

  describe '#create' do
    it "creates a NewsFeedItemComment" do
      sign_in user

      post :create, product_id: product.slug, update_id: task_nfi.id, body: "grumble grumble"

      expect(assigns(:item).body).to eq("grumble grumble")
    end
  end

  describe '#index' do
    let!(:comment) { NewsFeedItemComment.make!(news_feed_item: task_nfi) }

    it "returns NewsFeedItemComments and Events" do
      get :index, product_id: product.slug, update_id: task_nfi.id, format: :json

      expect(JSON.parse(response.body)["comments"].first["body"]).to eq(comment.body)
    end
  end

  describe '#update' do
    let!(:comment) { NewsFeedItemComment.make!(news_feed_item: task_nfi) }

    it "updates a comment" do
      get :index, product_id: product.slug, update_id: task_nfi.id, format: :json

      expect(JSON.parse(response.body)["comments"].first["body"]).to eq(comment.body)

      patch :update, product_id: product.slug, update_id: task_nfi.id, id: comment.id, comment: { body: "rabble rabble" }
      get :index, product_id: product.slug, update_id: task_nfi.id, format: :json

      expect(JSON.parse(response.body)["comments"].first["body"]).to eq("rabble rabble")
    end
  end
end
{'fraction_non_alphanumeric': 0.13778484366719662, 'fraction_numerical': 0.0, 'mean_word_length': 4.4409221902017295, 'pattern_counts': {'":': 0, '<': 3, '<?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': '12876', 'n_tokens_mistral': 665, 'n_tokens_neox': 652, 'n_words': 134}