<commit_before># encoding: utf-8
require 'rails_helper'

describe UsersController do
render_views
  
  before(:each) do
    @user = FactoryGirl.create(:user, :login => "vdaubry", :city => "paris", :country => "france")
    FactoryGirl.create(:repository, :language => "ruby", :user_id => @user.login)
    FactoryGirl.create(:repository, :language => "javascript", :user_id => @user.login)
    $redis.zadd("rank_paris_ruby", 1.1, @user.id)
    $redis.zadd("rank_france_ruby", 1.1, @user.id)
    $redis.zadd("rank_ruby", 1.1, @user.id)
    $redis.zadd("rank_paris_javascript", 1.1, @user.id)
    $redis.zadd("rank_france_javascript", 1.1, @user.id)
    $redis.zadd("rank_javascript", 1.1, @user.id)
  end
  
  
  describe "GET show" do
    context "user exists" do
      it "sets user" do
        get :show, :id => "vdaubry"
        assigns(:user).should == @user
      end
      
      it "is case insensitive" do
        get :show, :id => "VDAUBRY"
        assigns(:user).should == @user
      end
    end
    
    context "user doesn't exists" do
      it "returns 404" do
        expect {
          get :show, :id => "foobar"
        }.to raise_error(ActiveRecord::RecordNotFound)
      end
    end
    
    context "user is an organization" do
      it "redirects to home page with alert" do
        FactoryGirl.create(:user, :login => "org_user", :organization => true)
        get :show, :id => "org_user"
        response.should redirect_to(welcome_path)
        flash[:alert].should_not == nil
      end
    end
  end
  
  describe "GET search" do
    context "user exists" do
      it "sets user" do
        get :search, :login => "vdaubry"
        assigns(:user).should == @user
      end
      
      it "search case insensitive" do
        get :search, :login => "Vdaubry"
        assigns(:user).should == @user
      end

      it "search trim whitespace" do
        get :search, :login => " vdaubry "
        assigns(:user).should == @user
      end
    end
    
    context "user doesn't exists" do
      it "redirects to users index" do
        get :search, :login => "foobar"
        response.should redirect_to(welcome_path)
      end
    end
    
    context "empty user" do
      it "redirects to users index" do
        get :search
        response.should redirect_to(welcome_path)
      end
    end
  end
  
  describe "GET index" do
    it "returns presenter" do
      get :index, :city => "Paris", :language => "Ruby", :type => "city"
      assigns(:user_list_presenter).should_not == nil
    end
  end
end<commit_msg>add test on invalid location type<commit_after># encoding: utf-8
require 'rails_helper'

describe UsersController do
render_views
  
  before(:each) do
    @user = FactoryGirl.create(:user, :login => "vdaubry", :city => "paris", :country => "france")
    FactoryGirl.create(:repository, :language => "ruby", :user_id => @user.login)
    FactoryGirl.create(:repository, :language => "javascript", :user_id => @user.login)
    $redis.zadd("rank_paris_ruby", 1.1, @user.id)
    $redis.zadd("rank_france_ruby", 1.1, @user.id)
    $redis.zadd("rank_ruby", 1.1, @user.id)
    $redis.zadd("rank_paris_javascript", 1.1, @user.id)
    $redis.zadd("rank_france_javascript", 1.1, @user.id)
    $redis.zadd("rank_javascript", 1.1, @user.id)
  end
  
  
  describe "GET show" do
    context "user exists" do
      it "sets user" do
        get :show, :id => "vdaubry"
        assigns(:user).should == @user
      end
      
      it "is case insensitive" do
        get :show, :id => "VDAUBRY"
        assigns(:user).should == @user
      end
    end
    
    context "user doesn't exists" do
      it "returns 404" do
        expect {
          get :show, :id => "foobar"
        }.to raise_error(ActiveRecord::RecordNotFound)
      end
    end
    
    context "user is an organization" do
      it "redirects to home page with alert" do
        FactoryGirl.create(:user, :login => "org_user", :organization => true)
        get :show, :id => "org_user"
        response.should redirect_to(welcome_path)
        flash[:alert].should_not == nil
      end
    end
  end
  
  describe "GET search" do
    context "user exists" do
      it "sets user" do
        get :search, :login => "vdaubry"
        assigns(:user).should == @user
      end
      
      it "search case insensitive" do
        get :search, :login => "Vdaubry"
        assigns(:user).should == @user
      end

      it "search trim whitespace" do
        get :search, :login => " vdaubry "
        assigns(:user).should == @user
      end
    end
    
    context "user doesn't exists" do
      it "redirects to users index" do
        get :search, :login => "foobar"
        response.should redirect_to(welcome_path)
      end
    end
    
    context "empty user" do
      it "redirects to users index" do
        get :search
        response.should redirect_to(welcome_path)
      end
    end
  end
  
  describe "GET index" do
    it "returns presenter" do
      get :index, :city => "Paris", :language => "Ruby", :type => "city"
      assigns(:user_list_presenter).should_not == nil
    end
    
    context "invalid type" do
      it "should not fail" do
        get :index, :type => "foo"
        response.code.should == "200"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12723468999619628, 'fraction_numerical': 0.006656523392925067, 'mean_word_length': 2.3798200514138816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, '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': '7647551', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1723, 'n_words': 479}