<commit_before>require 'spec_helper'

describe IdeasController do
  
  context "When user is not signed in" do

    describe '#index' do
      before do
        @ideas = FactoryGirl.create_list :idea, 10
        get :index
      end
      it { should respond_with :success }
      it { should render_template(:index) }
      it { assigns(:ideas).should == @ideas }
    end
  end

  context "When user is signed in" do 
   
    before :each do
      @user = FactoryGirl.create :user
      sign_in @user
    end

    describe '#new' do
      before do
        get :new
      end
      it { should respond_with :success }
      it { should render_template(:new) }
      it { assert assigns(:idea).new_record? }
    end

    describe '#create' do
      describe 'with valid params' do
        let(:idea_params) {{title: "Some title", description: "desc"}}
        before do
          @idea_count = Idea.count
          post :create, {idea: idea_params}
        end
        it { should redirect_to :root }
        it { Idea.last.title.should == idea_params[:title] }<commit_msg>Test, User should not be able to upvote when not signed in<commit_after>require 'spec_helper'

describe IdeasController do
  
  context "When user is not signed in" do

    describe '#index' do
      before do
        @ideas = FactoryGirl.create_list :idea, 10
        get :index
      end
      it { should respond_with :success }
      it { should render_template(:index) }
      it { assigns(:ideas).should == @ideas }
    end

    describe "PUT #upvote" do
      let(:idea) { FactoryGirl.create :idea }

      before do
        Idea.stub(find: idea)
        put :upvote, id: idea.to_param, format: :json
      end

      it "responds with unauthorized status" do
        expect(response.status).to eq 401
      end

      it "doesn't increase the votes" do
        expect(idea.votes).to eq 0
      end
    end
  end

  context "When user is signed in" do 
   
    before :each do
      @user = FactoryGirl.create :user
      sign_in @user
    end

    describe '#new' do
      before do
        get :new
      end
      it { should respond_with :success }
      it { should render_template(:new) }
      it { assert assigns(:idea).new_record? }
    end

    describe '#create' do
      describe 'with valid params' do
        let(:idea_params) {{title: "Some title", description: "desc"}}
        before do
          @idea_count = Idea.count
          post :create, {idea: idea_params}
        end
        it { should redirect_to :root }
        it { Idea.last.title.should == idea_params[:title] }
{'fraction_non_alphanumeric': 0.0912621359223301, 'fraction_numerical': 0.0031067961165048546, 'mean_word_length': 2.1262135922330097, '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': '5819212', 'n_tokens_mistral': 789, 'n_tokens_neox': 751, 'n_words': 254}