<commit_before>require 'test_helper'

class UsersManipulateProjectTest < ActionDispatch::IntegrationTest
  def setup
    @user = users(:test_user)
  end

  test 'logged-in user adds a project' do
    # Go to login_path to initialize the session
    get login_path
    log_in_as @user

    get '/projects/new'
    assert_response :success
    assert_template 'projects/new'

    repo_url = 'https://github.com/linuxfoundation/cii-best-practices-badge'

    VCR.use_cassette('users_manipulate_test') do
      post '/projects',
           'project[project_homepage_url]' => repo_url,
           'project[repo_url]' => repo_url
      assert_response :redirect
      follow_redirect!

      assert_response :success
      assert_template 'projects/edit'

      # Check to ensure that the form includes all the criteria, but only once.
      # This could fail if the view incorrectly omits or duplicates one.
      Criteria.keys.each do |criterion|
        assert_select "##{criterion}" # Check for existence
        assert_select "##{criterion}" do |elements|
          assert_equal 1, elements.count # Check for duplication
        end
      end

      # Ensure that all id's are unique.
      all_name_id = Set.new
      my_result_id = css_select('[id]') # my_result[0]['id']
      my_result_id.each do |e|
        assert_not_includes all_name_id, e['id']
        all_name_id.add e['id']
      end

      # Check that major sections/classes are included in the HTML
      assert_select 'header'
      assert_select '.navbar'
      assert_select 'footer'
      assert_select '.footer'
      assert_select '.container'

      # This ensures that all rows are in containers - except that
      # this currently isn't true:
      # assert_select '#badge-progress' # Ensure we have progress bar area.
      # css_select('.row').each do |e|
      #   assert_includes ['container', 'container-fluid'], e.parent['class']
      # end
<commit_msg>Fix performance issue found by fastly<commit_after>require 'test_helper'

class UsersManipulateProjectTest < ActionDispatch::IntegrationTest
  def setup
    @user = users(:test_user)
  end

  test 'logged-in user adds a project' do
    # Go to login_path to initialize the session
    get login_path
    log_in_as @user

    get '/projects/new'
    assert_response :success
    assert_template 'projects/new'

    repo_url = 'https://github.com/linuxfoundation/cii-best-practices-badge'

    VCR.use_cassette('users_manipulate_test') do
      post '/projects',
           'project[project_homepage_url]' => repo_url,
           'project[repo_url]' => repo_url
      assert_response :redirect
      follow_redirect!

      assert_response :success
      assert_template 'projects/edit'

      # Check to ensure that the form includes all the criteria, but only once.
      # This could fail if the view incorrectly omits or duplicates one.
      Criteria.each_key do |criterion|
        assert_select "##{criterion}" # Check for existence
        assert_select "##{criterion}" do |elements|
          assert_equal 1, elements.count # Check for duplication
        end
      end

      # Ensure that all id's are unique.
      all_name_id = Set.new
      my_result_id = css_select('[id]') # my_result[0]['id']
      my_result_id.each do |e|
        assert_not_includes all_name_id, e['id']
        all_name_id.add e['id']
      end

      # Check that major sections/classes are included in the HTML
      assert_select 'header'
      assert_select '.navbar'
      assert_select 'footer'
      assert_select '.footer'
      assert_select '.container'

      # This ensures that all rows are in containers - except that
      # this currently isn't true:
      # assert_select '#badge-progress' # Ensure we have progress bar area.
      # css_select('.row').each do |e|
      #   assert_includes ['container', 'container-fluid'], e.parent['class']
      # end

{'fraction_non_alphanumeric': 0.09072217938833205, 'fraction_numerical': 0.0010280133641737343, 'mean_word_length': 2.8420533070088845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '819824', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1120, 'n_words': 333}