<commit_before>require 'spec_helper'

describe ContactMessagesController do

  describe "#index" do
    it "renders the #index view" do
      get :index
      expect(response).to render_template :index
    end
  end

  describe "#create" do

    context "when sending no form data" do
      it "redirects to the root path and displays an error message" do
        post :create, params: nil
        expect(response).to redirect_to root_path
        expect(flash[:notice]).to eq(I18n.t(".controllers.messages.errors.missing_form_data"))
      end
    end

    context "when sending valid contact form data" do
      it "renders the index page and displays a success message" do
        post :create, contact_form: FactoryGirl.attributes_for(:valid_contact_message)
        expect(response).to render_template :index
        expect(flash[:notice]).to eq(I18n.t(".controllers.messages.success.email_sent"))
      end
    end

    context "when sending invalid contact form data" do
      it "renders the index page and displays an error message" do
        post :create, contact_form: FactoryGirl.attributes_for(:invalid_contact_message)
        expect(response).to render_template :index
        expect(flash[:notice]).to eq(I18n.t(".controllers.messages.errors.email_not_sent"))
      end
    end

  end

end
<commit_msg>FIx specs.<commit_after>require 'spec_helper'

describe ContactMessagesController do
  describe "#new" do
    it "renders the #new view" do
      get :new
      expect(response).to render_template :new
    end
  end

  describe "#create" do
    context "when sending no form data" do
      it "renders the 'new' template for the invalid contact_message" do
        post :create, contact_message: nil
        expect(assigns(:contact_message)).not_to be_valid
        expect(response).to render_template :new
      end
    end

    context "when sending valid contact form data" do
      it "renders the index page and displays a success message" do
        expect do
          params = {}
          params[:contact_message] = FactoryGirl.attributes_for(:valid_contact_message)
          post :create, params
        end.to change { ActionMailer::Base.deliveries.count }.by(1)
        expect(assigns(:contact_message)).to be_valid
        expect(flash[:notice]).to eq(I18n.t(".controllers.messages.success.email_sent"))
        expect(response).to redirect_to root_path
      end
    end

    context "when sending invalid contact form data" do
      it "renders the index page and displays an error message" do
        post :create, contact_message: FactoryGirl.attributes_for(:invalid_contact_message)
        expect(assigns(:contact_message)).not_to be_valid
        expect(response).to render_template :new
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08091436865021771, 'fraction_numerical': 0.003265602322206096, 'mean_word_length': 3.127245508982036, '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': '1687265', 'n_tokens_mistral': 772, 'n_tokens_neox': 751, 'n_words': 241}