<commit_before>require 'spec_helper'

module SimpleBlog
  describe PostsController do
    describe "#index" do
      it "assigns @posts" do
        post = FactoryGirl.create(:post)
        get :index, :use_route => :simple_blog
        expect(assigns(:posts)).to eq([post])
      end

      it "renders the index template" do
        get :index, :use_route => :simple_blog
        expect(response).to render_template('posts/index')
      end
    end

    describe "#create" do
      let(:params) { FactoryGirl.attributes_for(:post, :title => "Cool post") }

      it "assigns to @post" do
        post :create, :post => params, :use_route => :simple_blog
        expect(assigns(:post)).to be_a(Post)
      end

      context "attributes are valid" do
        it "creates a new record" do
          expect {
            post :create, :post => params, :use_route => :simple_blog
          }.to change(Post, :count).by(1)
        end

        it "sets a flash notice" do
          post :create, :post => params, :use_route => :simple_blog
          expect(flash[:notice]).not_to be_nil
        end

        it "redirects to the post details page" do
          post :create, :post => params, :use_route => :simple_blog
          expect(response).to redirect_to(Post.last)
        end
      end

      context "attributes are invalid" do
        it "doesn't create a new record" do
          expect {
            post :create, :post => {:foo => :bar}, :use_route => :simple_blog
          }.to_not change(Post, :count)
        end

        it "sets a flash alert" do
          post :create, :post => {:foo => :bar}, :use_route => :simple_blog
          expect(flash[:alert]).not_to be_nil
        end

        it "redirects back to the new post form" do
          post :create, :post => {:foo => :bar}, :use_route => :simple_blog
          expect(response).to render_template('posts/new')
        end
      end
    end

    describe "#new" do
      it "renders the new template" do
        get :new, :use_route => :simple_blog
        expect(response).to render_template('posts/new')
      end
    end

    describe "#show" do<commit_msg>Added spec for Posts#new assignment<commit_after>require 'spec_helper'

module SimpleBlog
  describe PostsController do
    describe "#index" do
      it "assigns @posts" do
        post = FactoryGirl.create(:post)
        get :index, :use_route => :simple_blog
        expect(assigns(:posts)).to eq([post])
      end

      it "renders the index template" do
        get :index, :use_route => :simple_blog
        expect(response).to render_template('posts/index')
      end
    end

    describe "#create" do
      let(:params) { FactoryGirl.attributes_for(:post, :title => "Cool post") }

      it "assigns to @post" do
        post :create, :post => params, :use_route => :simple_blog
        expect(assigns(:post)).to be_a(Post)
      end

      context "attributes are valid" do
        it "creates a new record" do
          expect {
            post :create, :post => params, :use_route => :simple_blog
          }.to change(Post, :count).by(1)
        end

        it "sets a flash notice" do
          post :create, :post => params, :use_route => :simple_blog
          expect(flash[:notice]).not_to be_nil
        end

        it "redirects to the post details page" do
          post :create, :post => params, :use_route => :simple_blog
          expect(response).to redirect_to(Post.last)
        end
      end

      context "attributes are invalid" do
        it "doesn't create a new record" do
          expect {
            post :create, :post => {:foo => :bar}, :use_route => :simple_blog
          }.to_not change(Post, :count)
        end

        it "sets a flash alert" do
          post :create, :post => {:foo => :bar}, :use_route => :simple_blog
          expect(flash[:alert]).not_to be_nil
        end

        it "redirects back to the new post form" do
          post :create, :post => {:foo => :bar}, :use_route => :simple_blog
          expect(response).to render_template('posts/new')
        end
      end
    end

    describe "#new" do
      it "assigns a new Post to @post" do
        get :new, :use_route => :simple_blog
        expect(assigns[:post]).to be_a_new(Post)
      end

      it "renders the new template" do
        get :new, :use_route => :simple_blog
        expect(response).to render_template('posts/new')
      end
    end

    describe "#show" do
{'fraction_non_alphanumeric': 0.11544532130777903, 'fraction_numerical': 0.00045095828635851183, 'mean_word_length': 2.1936645068394527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 46, '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': '5103071', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1286, 'n_words': 408}