<commit_before>require File.dirname(__FILE__) + '/../../test_helper'
require 'tool/tasklist_controller'

# Re-raise errors caught by the controller.
class Tool::TasklistController; def rescue_action(e) raise e end; end

class Tool::TasklistControllerTest < Test::Unit::TestCase
  fixtures :pages, :users, :task_lists, :tasks, :user_participations

  def setup
    @controller = Tool::TasklistController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_sort
    login_as :quentin
    assert_equal Task::Task.find(1).position, 1
    assert_equal Task::Task.find(2).position, 2
    assert_equal Task::Task.find(3).position, 3

    xhr :post, :sort, :controller => "tool/tasklist", :page_id => 21, :id => 0, :sort_list_21_pending => ["3","2","1"]

    assert_equal Task::Task.find(1).position, 3
    assert_equal Task::Task.find(2).position, 2
    assert_equal Task::Task.find(3).position, 1
  end

  def test_multi_list_sort
    login_as :quentin
    tasks = Task::Task.find(1,2,3,4,5,6).index_by {|t| t.id}
    assert_equal tasks[1].position, 1
    assert_equal tasks[2].position, 2
    assert_equal tasks[3].position, 3
    assert_equal tasks[4].position, 1
    assert_equal tasks[5].position, 2
    assert_equal tasks[6].position, 3

    xhr :post, :sort, :controller => "tool/tasklist", :page_id => 21, :id => 0, :sort_list_21_pending => ["1","3"]
    @controller = Tool::TasklistController.new
    xhr :post, :sort, :controller => "tool/tasklist", :page_id => 22, :id => 0, :sort_list_22_pending => ["4","5","2","6"]

    tasks = Task::Task.find(1,2,3,4,5,6).index_by {|t| t.id}
    assert_equal tasks[1].position, 1
    assert_equal tasks[2].position, 3
    assert_equal tasks[3].position, 2
    assert_equal tasks[4].position, 1
    assert_equal tasks[5].position, 2
    assert_equal tasks[6].position, 4
    assert_equal tasks[2].task_list_id, 2
  end
end<commit_msg>fix failing test<commit_after>require File.dirname(__FILE__) + '/../../test_helper'
require 'tool/tasklist_controller'

# Re-raise errors caught by the controller.
class Tool::TasklistController; def rescue_action(e) raise e end; end

class Tool::TasklistControllerTest < Test::Unit::TestCase
  fixtures :pages, :users, :task_lists, :tasks, :user_participations

  def setup
    @controller = Tool::TasklistController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  def test_sort
    login_as :quentin
    assert_equal Task::Task.find(1).position, 1
    assert_equal Task::Task.find(2).position, 2
    assert_equal Task::Task.find(3).position, 3

    xhr :post, :sort, :controller => "tool/tasklist", :page_id => 21, :id => 0, :sort_list_21_pending => ["3","2","1"]

    assert_equal Task::Task.find(1).position, 3
    assert_equal Task::Task.find(2).position, 2
    assert_equal Task::Task.find(3).position, 1
  end

  def test_multi_list_sort
    login_as :quentin
    tasks = Task::Task.find(1,2,3,4,5,6).index_by {|t| t.id}
    assert_equal tasks[1].position, 1
    assert_equal tasks[2].position, 2
    assert_equal tasks[3].position, 3
    assert_equal tasks[4].position, 1
    assert_equal tasks[5].position, 2
    assert_equal tasks[6].position, 3
    assert_not_equal tasks[2].task_list_id, tasks[4].task_list_id

    xhr :post, :sort, :controller => "tool/tasklist", :page_id => 21, :id => 0, :sort_list_21_pending => ["1","3"]
    @controller = Tool::TasklistController.new
    xhr :post, :sort, :controller => "tool/tasklist", :page_id => 22, :id => 0, :sort_list_22_pending => ["4","5","2","6"]

    tasks = Task::Task.find(1,2,3,4,5,6).index_by {|t| t.id}
    assert_equal tasks[1].position, 1
    assert_equal tasks[2].position, 3
    assert_equal tasks[3].position, 2
    assert_equal tasks[4].position, 1
    assert_equal tasks[5].position, 2
    assert_equal tasks[6].position, 4
    assert_equal tasks[2].task_list_id, tasks[4].task_list_id
  end
end
{'fraction_non_alphanumeric': 0.14790674354474806, 'fraction_numerical': 0.0376034093757834, 'mean_word_length': 4.370121130551817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '1363451', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1360, 'n_words': 300}