<commit_before>#!/usr/bin/env ruby

require_relative 'controller_test_base'

class DashboardControllerTest < ControllerTestBase

  test 'show no avatars' do
    stub_dojo
    stub_language('fake-C#','nunit')
    stub_exercise('fake-Yatzy')
    @id = create_kata('fake-C#','fake-Yatzy')
    show_dashboard
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'show avatars but no traffic-lights' do
    stub_dojo
    stub_language('fake-C#','nunit')
    stub_exercise('fake-Yatzy')
    @id = create_kata('fake-C#','fake-Yatzy')
    (1..4).each do |n|
      enter
      avatar_name = json['avatar_name']
      setup_initial_edit(@id,avatar_name)
      get 'kata/edit', :id => @id, :avatar => avatar_name
      assert_response :success
    end
    show_dashboard
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'show avatars with some traffic lights' do
    @id = create_kata
    (1..3).each do |n|
      enter
      avatar_name = json['avatar_name']
      get 'kata/edit', :id => @id, :avatar => avatar_name
      assert_response :success
      (1..2).each do |m|
        post 'kata/run_tests',
          :format => :js,
          :id => @id,
          :avatar => avatar_name,
          :file_content => {
            'cyber-dojo.sh' => ""
          },
          :file_hashes_incoming => {
            'cyber-dojo.sh' => 234234
          },
          :file_hashes_outgoing => {
            'cyber-dojo.sh' => -4545645678
          }
      end
    end
    show_dashboard
    assert_response :success
    get 'dashboard/show',  :id => @id, :minute_columns => false
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'show dashboard and open a diff-dialog' do
    @id = create_kata
    enter
    avatar_name = json['avatar_name']
    get 'kata/edit', :id => @id, :avatar => avatar_name
    assert_response :success
    (1..3).each do |m|
      post 'kata/run_tests',
        :format => :js,
        :id => @id,
        :avatar => avatar_name,
        :file_content => {
          'cyber-dojo.sh' => ''
        },
        :file_hashes_incoming => {
          'cyber-dojo.sh' => 234234
        },
        :file_hashes_outgoing => {
          'cyber-dojo.sh' => -4545645678
        }
    end
    get 'dashboard/show',
      :id => @id,
      :avatar => avatar_name,
      :was_tag => 1,
      :now_tag => 2
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

begin # failing rails 3->4 upgrade. Only js.erb action?
  test 'heartbeat' do
    id = create_kata

    get 'dojo/enter', :id => id
    avatar_name = json['avatar_name']

    get 'kata/edit', :id => id, :avatar => avatar_name
    assert_response :success

    post 'kata/run_tests',
      :format => :js,
      :id => id,
      :avatar => avatar_name,
      :file_content => {
        'cyber-dojo.sh' => ''
      },
      :file_hashes_incoming => {
        'cyber-dojo.sh' => 234234
      },
      :file_hashes_outgoing => {
        'cyber-dojo.sh' => -4545645678
      }

    get 'dashboard/heartbeat', :format => :js, :id => id
  end
end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  def show_dashboard
    get 'dashboard/show', :id => @id
  end

end<commit_msg>refactoring<commit_after>#!/usr/bin/env ruby

require_relative 'controller_test_base'

class DashboardControllerTest < ControllerTestBase

  test 'show no avatars' do
    stub_dojo
    stub_language('fake-C#','nunit')
    stub_exercise('fake-Yatzy')
    @id = create_kata('fake-C#','fake-Yatzy')
    show_dashboard
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'show avatars but no traffic-lights' do
    stub_dojo
    stub_language('fake-C#','nunit')
    stub_exercise('fake-Yatzy')
    @id = create_kata('fake-C#','fake-Yatzy')
    (1..4).each do |n|
      enter
      avatar_name = json['avatar_name']
      setup_initial_edit(@id,avatar_name)
      get 'kata/edit', :id => @id, :avatar => avatar_name
      assert_response :success
    end
    show_dashboard
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'show avatars with some traffic lights' do
    @id = create_kata
    (1..3).each do |n|
      enter
      avatar_name = json['avatar_name']
      get 'kata/edit', :id => @id, :avatar => avatar_name
      assert_response :success
      (1..2).each do |m|
        post 'kata/run_tests',
          :format => :js,
          :id => @id,
          :avatar => avatar_name,
          :file_content => {
            'cyber-dojo.sh' => ""
          },
          :file_hashes_incoming => {
            'cyber-dojo.sh' => 234234
          },
          :file_hashes_outgoing => {
            'cyber-dojo.sh' => -4545645678
          }
      end
    end
    show_dashboard
    assert_response :success
    get 'dashboard/show',  :id => @id, :minute_columns => false
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'show dashboard and open a diff-dialog' do
    @id = create_kata
    enter
    avatar_name = json['avatar_name']
    get 'kata/edit', :id => @id, :avatar => avatar_name
    assert_response :success
    (1..3).each do |m|
      post 'kata/run_tests',
        :format => :js,
        :id => @id,
        :avatar => avatar_name,
        :file_content => {
          'cyber-dojo.sh' => ''
        },
        :file_hashes_incoming => {
          'cyber-dojo.sh' => 234234
        },
        :file_hashes_outgoing => {
          'cyber-dojo.sh' => -4545645678
        }
    end
    get 'dashboard/show',
      :id => @id,
      :avatar => avatar_name,
      :was_tag => 1,
      :now_tag => 2
    assert_response :success
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  test 'heartbeat' do
    id = create_kata

    get 'dojo/enter', :id => id
    avatar_name = json['avatar_name']

    get 'kata/edit', :id => id, :avatar => avatar_name
    assert_response :success

    post 'kata/run_tests',
      :format => :js,
      :id => id,
      :avatar => avatar_name,
      :file_content => {
        'cyber-dojo.sh' => ''
      },
      :file_hashes_incoming => {
        'cyber-dojo.sh' => 234234
      },
      :file_hashes_outgoing => {
        'cyber-dojo.sh' => -4545645678
      }

    get 'dashboard/heartbeat', :format => :js, :id => id
  end

  #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  def show_dashboard
    get 'dashboard/show', :id => @id
  end

end
{'fraction_non_alphanumeric': 0.17218543046357615, 'fraction_numerical': 0.017760385310054184, 'mean_word_length': 1.6182033096926713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7305776', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2458, 'n_words': 436}