<commit_before># coding: utf-8

require File.expand_path("../../test_helper", __FILE__)

# :stopdoc:
class PeopleControllerTest < ActionController::TestCase
  def test_index
    get(:index)
    assert_response(:success)
    assert_template("people/index")
    assert_layout("application")
    assert_not_nil(assigns["people"], "Should assign people")
    assert(assigns["people"].empty?, "Should find no one")
    assert_select ".tabs", :count => 0
    assert_select "a#export_link", :count => 0
  end

  def test_list
    get(:list, :q => 'jone')
    assert_response(:success)
    assert_not_nil(@response.body.index("Jones"), 'Search for jone should find Jones #{@response.to_s}')
    assert_not_nil(@response.body.index("2"), 'Search for jone should return ID of 2')
  end

  def test_index_as_promoter
    PersonSession.create(people(:promoter))
    get(:index)
    assert_response(:success)
    assert_template("people/index")
    assert_layout("application")
    assert_not_nil(assigns["people"], "Should assign people")
    assert(assigns["people"].empty?, "Should find no one")
    assert_select ".tabs", :count => 1
    assert_select "a#export_link", :count => 1
  end

  def test_find
    get(:index, :name => "weav")
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert_equal([people(:weaver)], assigns['people'], 'Search for weav should find Weaver')
    assert_not_nil(assigns["name"], "Should assign name")
    assert_equal('weav', assigns['name'], "'name' assigns")
  end

  def test_find_nothing
    get(:index, :name => 's7dfnacs89danfx')
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert_equal(0, assigns['people'].size, "Should find no people")
  end
  
  def test_find_empty_name
    get(:index, :name => '')
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert(assigns["people"].empty?, "Should find no one")
    assert_not_nil(assigns["name"], "Should assign name")
    assert_equal('', assigns['name'], "'name' assigns")
  end

  def test_find_limit
    for i in 0..RacingAssociation.current.search_results_limit
      Person.create(:name => "Test Person #{i}")
    end
    get(:index, :name => 'Test')
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert_equal(30, assigns['people'].size, "Search for '' should find all people and paginate")
    assert_not_nil(assigns["name"], "Should assign name")
    assert(flash.empty?, 'flash not empty?')
    assert_equal('Test', assigns['name'], "'name' assigns")
  end

  def test_ajax_ssl_find
    use_ssl
    xhr :get, :index, :name => "weav"
    assert_response :success
    assert_not_nil assigns["people"], "Should assign people"
    assert_equal [ people(:weaver) ], assigns['people'], "Search for weav should find Weaver"
    assert_template "people/index"
    assert_layout nil
  end
  
  def test_edit
    use_ssl
    login_as :member
    get :edit, :id => people(:member).to_param
    assert_response :success
    assert_equal people(:member), assigns(:person), "@person"
    assert_select ".tabs", :count => 0
  end

  def test_edit_promoter
    use_ssl
    login_as :promoter
    get :edit, :id => people(:promoter).to_param
    assert_response :success
    assert_equal people(:promoter), assigns(:person), "@person"
    assert_select ".tabs", :count => 1<commit_msg>Test new autocomplete<commit_after># coding: utf-8

require File.expand_path("../../test_helper", __FILE__)

# :stopdoc:
class PeopleControllerTest < ActionController::TestCase
  def test_index
    get(:index)
    assert_response(:success)
    assert_template("people/index")
    assert_layout("application")
    assert_not_nil(assigns["people"], "Should assign people")
    assert(assigns["people"].empty?, "Should find no one")
    assert_select ".tabs", :count => 0
    assert_select "a#export_link", :count => 0
  end

  def test_list
    get(:list, :q => 'jone')
    assert_response(:success)
    assert_not_nil(@response.body.index("Jones"), 'Search for jone should find Jones #{@response.to_s}')
    assert_not_nil(@response.body.index("2"), 'Search for jone should return ID of 2')
  end

  def test_index_as_promoter
    PersonSession.create(people(:promoter))
    get(:index)
    assert_response(:success)
    assert_template("people/index")
    assert_layout("application")
    assert_not_nil(assigns["people"], "Should assign people")
    assert(assigns["people"].empty?, "Should find no one")
    assert_select ".tabs", :count => 1
    assert_select "a#export_link", :count => 1
  end

  def test_find
    get(:index, :name => "weav")
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert_equal([people(:weaver)], assigns['people'], 'Search for weav should find Weaver')
    assert_not_nil(assigns["name"], "Should assign name")
    assert_equal('weav', assigns['name'], "'name' assigns")
  end

  def test_find_nothing
    get(:index, :name => 's7dfnacs89danfx')
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert_equal(0, assigns['people'].size, "Should find no people")
  end
  
  def test_find_empty_name
    get(:index, :name => '')
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert(assigns["people"].empty?, "Should find no one")
    assert_not_nil(assigns["name"], "Should assign name")
    assert_equal('', assigns['name'], "'name' assigns")
  end

  def test_find_limit
    for i in 0..RacingAssociation.current.search_results_limit
      Person.create(:name => "Test Person #{i}")
    end
    get(:index, :name => 'Test')
    assert_response(:success)
    assert_not_nil(assigns["people"], "Should assign people")
    assert_equal(30, assigns['people'].size, "Search for '' should find all people and paginate")
    assert_not_nil(assigns["name"], "Should assign name")
    assert(flash.empty?, 'flash not empty?')
    assert_equal('Test', assigns['name'], "'name' assigns")
  end

  def test_ajax_ssl_find
    use_ssl
    xhr :get, :index, :term => "weav", :format => "json"
    assert @response.body["Weaver"], "Response should include Weaver in #{@response.body}"
    assert_response :success
    assert_template nil
    assert_layout nil
  end
  
  def test_edit
    use_ssl
    login_as :member
    get :edit, :id => people(:member).to_param
    assert_response :success
    assert_equal people(:member), assigns(:person), "@person"
    assert_select ".tabs", :count => 0
  end

  def test_edit_promoter
    use_ssl
    login_as :promoter
    get :edit, :id => people(:promoter).to_param
    assert_response :success
    assert_equal people(:promoter), assigns(:person), "@person"
    assert_select ".tabs", :count => 1
{'fraction_non_alphanumeric': 0.14145985401459854, 'fraction_numerical': 0.004671532846715329, 'mean_word_length': 4.43298969072165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '2638210', 'n_tokens_mistral': 2171, 'n_tokens_neox': 2099, 'n_words': 517}