<commit_before>require 'spec_helper'

describe UsersController do

  describe "GET 'index'" do

    context 'when not logged in' do
      it "should redirect to the root" do
        get :index
        response.should redirect_to(root_path)
      end
    end

    context 'when logged in' do
      context 'with an admin user' do

        before do
          User.any_instance.stub(:update_likes).and_return(true)
          @user = FactoryGirl.create(:user)
          @user.add_role :admin
          test_sign_in(@user)
        end

        it "should be successful" do
          get :index
          response.should be_success
        end

        it "should get a list of users" do
          get :index
          assigns(:users).should eq(User.all)
        end
      end
      context 'with a non admin user' do

        before do
          User.any_instance.stub(:update_likes).and_return(true)
          @user = FactoryGirl.create(:user)
          test_sign_in(@user)
        end

        it "should redirect to the root path" do
          get :index
          response.should redirect_to(root_path)
        end
      end
    end
  end

  describe "GET 'show'" do

    before do
      User.any_instance.stub(:update_likes).and_return(true)
      @user = FactoryGirl.create(:user)
      10.times do
        @user.likes << FactoryGirl.create(:like)
      end
    end

    it "should be successful" do
      get :show, id:@user
      response.should be_success
    end

    it "should find the right user" do
      get :show, id:@user
      assigns(:user).should eq(@user)
    end

    it "should assign the user's likes"

  end

  describe "GET 'edit'" do

    before(:each) do
      @user = FactoryGirl.create(:user)
      test_sign_in(@user)
    end

    it "should be successful" do
      get :edit, id: @user
      response.should be_success
    end

    it "should assign the correct user" do
      get :edit, id:@user
      assigns(:user).should eq(@user)
    end
  end

  describe "PUT 'update'" do

    before(:each) do
      @user = FactoryGirl.create(:user)<commit_msg>add specs for paginating likes<commit_after>require 'spec_helper'

describe UsersController do

  describe "GET 'index'" do

    context 'when not logged in' do
      it "should redirect to the root" do
        get :index
        response.should redirect_to(root_path)
      end
    end

    context 'when logged in' do

      context 'with an admin user' do

        before do
          User.any_instance.stub(:update_likes).and_return(true)
          @user = FactoryGirl.create(:user)
          @user.add_role :admin
          test_sign_in(@user)
        end

        it "should be successful" do
          get :index
          response.should be_success
        end

        it "should get a list of users" do
          get :index
          assigns(:users).should eq(User.all)
        end
      end

      context 'with a non admin user' do

        before do
          User.any_instance.stub(:update_likes).and_return(true)
          @user = FactoryGirl.create(:user)
          test_sign_in(@user)
        end

        it "should redirect to the root path" do
          get :index
          response.should redirect_to(root_path)
        end
      end
    end
  end

  describe "GET 'show'" do

    before(:each) do
      User.any_instance.stub(:update_likes).and_return(true)
      @user = FactoryGirl.create(:user)
    end

    it "should be successful" do
      get :show, id:@user
      response.should be_success
    end

    it "should find the right user" do
      get :show, id:@user
      assigns(:user).should eq(@user)
    end

    context 'for a user with no likes' do
      it "should assign an empty collection to the user's likes" do
        get :show, id:@user
        assigns(:likes).should be_empty
      end
    end

    context 'for a user with likes' do

      before do
        10.times do
          @user.likes << FactoryGirl.create(:like)
        end
      end

      it "should assign the user's likes" do
        get :show, id:@user
        assigns(:likes).should_not be_empty
      end

      it "should paginate the user's likes" do
        get :show, id:@user
        likes = assigns(:likes)
        likes.all.class.should eq(WillPaginate::Collection)
        likes.all.count.should eq(5)
      end
    end
  end

  describe "GET 'edit'" do

    before(:each) do
      @user = FactoryGirl.create(:user)
      test_sign_in(@user)
    end

    it "should be successful" do
      get :edit, id: @user
      response.should be_success
    end

    it "should assign the correct user" do
      get :edit, id:@user
      assigns(:user).should eq(@user)
    end
  end

  describe "PUT 'update'" do

    before(:each) do
      @user = FactoryGirl.create(:user)
{'fraction_non_alphanumeric': 0.08541448058761805, 'fraction_numerical': 0.001049317943336831, 'mean_word_length': 1.993718592964824, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7577227', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1405, 'n_words': 448}