<commit_before>require 'rails_helper'


describe AnswersController do
  let(:question) { create(:question) }
  let(:user) {create(:user, username: 'Tyaasdfasdf', email: '<EMAIL>')}
  before do
    allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user)
  end


  context "POST #create" do

    describe "when valid params are passed" do
      it 'creates a new answer' do
        expect {
          post :create, question_id: question.id, answer: {content: "hey its a content", user: user}}
          .to change{Answer.count}.by(1)
      end

  #     it 'assigns a newly created question as a question' do
  #       post :create, { question: {title: "hey its a test", content: "hey its a content"} }
  #       expect(assigns(:question)).to be_a Question
  #     end

  #     it 'redirects to the newly created question' do
  #       expect(
  #         post :create, { question: {title: "hey its a test", content: "hey its a content"} }
  #       ).to redirect_to questions_path(assigns(:question))
  #     end
  #   end

  #   describe "when invalid params are passed" do
  #     it 'does not create a new question' do
  #       expect {
  #         post :create, { question: {content: "hey its a content"} }
  #       }.to change{Question.count}.by(0)
  #     end

  #     it 'sends the user to new question page' do

  #     end
    end
  end

end<commit_msg>Add tests for post #create route<commit_after>require 'rails_helper'


describe AnswersController do
  let(:question) { create(:question) }
  let(:user) {create(:user, username: 'Tyaasdfasdf', email: '<EMAIL>')}
  before do
    allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user)
  end


  context "POST #create" do

    describe "when valid params are passed" do
      it 'creates a new answer' do
        expect {
          post :create, question_id: question.id, answer: {content: "hey its a content", user: user}}
          .to change{Answer.count}.by(1)
      end

      it 'assigns a newly created answer as an answer' do
        post :create, question_id: question.id, answer: {content: "hey its a content", user: user}
          expect(assigns(:answer)).to be_a Answer
      end

      it 'redirects to the newly created answers question page' do
        expect(
          post :create, question_id: question.id, answer: {content: "hey its a content", user: user}
        ).to redirect_to question_path(question.id)
      end
    end

  #   describe "when invalid params are passed" do
  #     it 'does not create a new question' do
  #       expect {
  #         post :create, { question: {content: "hey its a content"} }
  #       }.to change{Question.count}.by(0)
  #     end

  #     it 'sends the user to new question page' do

  #     end
    # end
  end

end
{'fraction_non_alphanumeric': 0.10845522654298966, 'fraction_numerical': 0.0014270424545130217, 'mean_word_length': 2.679790026246719, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2356576', 'n_tokens_mistral': 883, 'n_tokens_neox': 842, 'n_words': 294}