<commit_before>require 'spec_helper'

describe CommentsController do
	let!(:user) { User.create(user_test_params) }
	let!(:question) { Question.create(question_test_params) }
  let!(:comment) { Comment.new(comment_test_params) }


  describe 'GET #new' do
    it "creates a new, unsaved, comment" do
      get :new, question_id: 1
      expect(assigns(:comment)).to be_instance_of Comment
      expect(assigns(:comment).id).to be_nil
    end
  end

  describe 'POST #create' do
    context "when valid params are passed" do
      it "creates a new Comment" do
      	session[:user_id] = user.id
      	allow(comment).to receive(:current_user).with(:user)

        expect{ post :create, question_id: 1, comment: comment_test_params }.to change{ Comment.count }.by(1)
      end
    end

    context "when invalid params are passed" do
      xit "assigns a newly created but unsaved comment as @comment" do
        post :create, question_id: 1, comment: { content: "" }
        expect(assigns(:comment).id).to be_nil
      end

      xit "re-renders the comment form" do
        post :create, comment: { content: "" }
        expect(response).to render_template :new
      end
    end
  end
end

def comment_test_params
  { content: "This is a fake comment. It's very commenty, and egregious. Sesquipedalian is my new favorite word.",<commit_msg>Comment Controller Spec complete<commit_after>require 'spec_helper'

describe CommentsController do
	let!(:user) { User.create(user_test_params) }
	let!(:question) { Question.create(question_test_params) }
  let!(:comment) { Comment.new(comment_test_params) }


  describe 'GET #new' do
    it "creates a new, unsaved, comment" do
      get :new, question_id: 1
      expect(assigns(:comment)).to be_instance_of Comment
      expect(assigns(:comment).id).to be_nil
    end
  end

  describe 'POST #create' do
    context "when valid params are passed" do
      it "creates a new Comment" do
      	session[:user_id] = user.id
      	allow(comment).to receive(:current_user).with(:user)

        expect{ post :create, question_id: 1, comment: comment_test_params }.to change{ Comment.count }.by(1)
      end
    end

    context "when invalid params are passed" do
      it "assigns a newly created but unsaved comment as @comment" do
      	session[:user_id] = user.id
      	allow(comment).to receive(:current_user).with(:user)    
        post :create, question_id: 1, comment: { content: "" }
        expect(assigns(:comment).id).to be_nil
      end

      it "re-renders the comment form" do
      	session[:user_id] = user.id
      	allow(comment).to receive(:current_user).with(:user)    	
        post :create, question_id: 1, comment: { content: "" }
        expect(response).to render_template :new
      end
    end
  end
end

def comment_test_params
  { content: "This is a fake comment. It's very commenty, and egregious. Sesquipedalian is my new favorite word.",
{'fraction_non_alphanumeric': 0.10555174777244689, 'fraction_numerical': 0.003084304318026045, 'mean_word_length': 3.2243125904486254, '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': '2263902', 'n_tokens_mistral': 922, 'n_tokens_neox': 894, 'n_words': 272}