<commit_before># encoding: utf-8
require "integration_test_helper"

class AdvancedSearchTest < IntegrationTest
  def setup
    super
    stub_elasticsearch_settings
  end

  def test_returns_json_for_advanced_search_results
    Elasticsearch::Index.any_instance.stubs(:advanced_search)
      .returns({total: 1, results: [sample_document]})
    get "/rummager_test/advanced_search", {per_page: '1', page: '1', keywords: 'meh'}, "HTTP_ACCEPT" => "application/json"
    assert last_response.ok?
    result = MultiJson.decode(last_response.body)
    assert_match /application\/json/, last_response.headers["Content-Type"]
    assert_equal 1, result["total"]
  end

  def test_json_response_includes_total_and_results
    Elasticsearch::Index.any_instance.stubs(:advanced_search)
      .returns({total: 1, results: [sample_document]})
    get "/rummager_test/advanced_search.json", {per_page: '1', page: '1', keywords: 'meh'}
    expected_result = {'total' => 1, 'results' => [sample_document_attributes.merge('highlight' => 'DESCRIPTION')]}
    assert last_response.ok?
    assert_match /application\/json/, last_response.headers["Content-Type"]
    result = MultiJson.decode(last_response.body)
    assert_equal expected_result, result
  end<commit_msg>Make some search test failures more informative.<commit_after># encoding: utf-8
require "integration_test_helper"

class AdvancedSearchTest < IntegrationTest
  def setup
    super
    stub_elasticsearch_settings
  end

  def test_returns_json_for_advanced_search_results
    Elasticsearch::Index.any_instance.stubs(:advanced_search)
      .returns({total: 1, results: [sample_document]})
    get "/rummager_test/advanced_search", {per_page: '1', page: '1', keywords: 'meh'}, "HTTP_ACCEPT" => "application/json"
    assert last_response.ok?, "Bad status: #{last_response.status}"
    result = MultiJson.decode(last_response.body)
    assert_match /application\/json/, last_response.headers["Content-Type"]
    assert_equal 1, result["total"]
  end

  def test_json_response_includes_total_and_results
    Elasticsearch::Index.any_instance.stubs(:advanced_search)
      .returns({total: 1, results: [sample_document]})
    get "/rummager_test/advanced_search.json", {per_page: '1', page: '1', keywords: 'meh'}
    expected_result = {'total' => 1, 'results' => [sample_document_attributes.merge('highlight' => 'DESCRIPTION')]}
    assert last_response.ok?, "Bad status: #{last_response.status}"
    assert_match /application\/json/, last_response.headers["Content-Type"]
    result = MultiJson.decode(last_response.body)
    assert_equal expected_result, result
  end
{'fraction_non_alphanumeric': 0.12351816443594646, 'fraction_numerical': 0.006883365200764819, 'mean_word_length': 5.318840579710145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3616731', 'n_tokens_mistral': 816, 'n_tokens_neox': 794, 'n_words': 157}