<commit_before>require 'test_helper'

class Admin::DocumentSeriesMembershipsControllerTest < ActionController::TestCase
  setup do
    @document_series = create(:document_series)
    login_as create(:policy_writer)
  end

  should_be_an_admin_controller

  view_test 'GET #index lists the documents in the series' do
    skip
    doc1 = create(:published_publication)
    doc2 = create(:published_publication)
    @document_series.documents = [doc1.document, doc2.document]

    get :index, document_series_id: @document_series

    assert_select 'a', doc1.title
    assert_select 'a', doc2.title
  end

  test 'JS POST #create adds the document to the series' do
    skip
    document = create(:publication).document
    xhr :post, :create, document_series_id: @document_series, id: document.id

    assert_response :success
    assert_template :create
    assert @document_series.documents.include?(document), "Document #{document.id} should be in series"
  end

  test 'JS DELETE #destroy removes a document from the series' do
    skip
    document = create(:publication).document
    @document_series.documents << document
    xhr :delete, :destroy, document_series_id: @document_series, id: document.id

    assert_response :success
    assert_template :destroy
    refute @document_series.documents(true).include?(document), "Document #{document.id} should not be in series"
  end

  view_test 'JSON GET #search returns filter results as JSON' do
    publication = create(:publication, title: 'search term')

    get :search, document_series_id: @document_series, title: 'search term', format: :json

    assert_response :success

    response_as_hash = JSON.parse(response.body)
    assert_equal true, response_as_hash['results_any?']
    assert_equal 1, response_as_hash['results'].size

    publication_json = response_as_hash['results'][0]
    assert_equal publication.id, publication_json['id']
    assert_equal publication.document_id, publication_json['document_id']
    assert_equal publication.title, publication_json['title']
    assert_equal 'publication', publication_json['type']
    assert_equal publication.display_type, publication_json['display_type']
  end
end<commit_msg>Shorten instance variable names<commit_after>require 'test_helper'

class Admin::DocumentSeriesMembershipsControllerTest < ActionController::TestCase
  setup do
    @series = create(:document_series, :with_group)
    @first_group = @series.groups.first
    login_as create(:policy_writer)
  end

  should_be_an_admin_controller

  view_test 'GET #index lists the groups and documents in the series' do
    doc1 = create(:published_publication)
    doc2 = create(:published_publication)
    @first_group.documents = [doc1.document, doc2.document]

    get :index, document_series_id: @series

    assert_select 'h2', @first_group.heading
    assert_select 'a', doc1.title
    assert_select 'a', doc2.title
  end

  test 'JS POST #create adds the document to the series' do
    skip
    document = create(:publication).document
    xhr :post, :create, document_series_id: @series, id: document.id

    assert_response :success
    assert_template :create
    assert @series.documents.include?(document)
  end

  test 'JS DELETE #destroy removes a document from the series' do
    skip
    document = create(:publication).document
    @series.documents << document
    xhr :delete, :destroy, document_series_id: @series, id: document.id

    assert_response :success
    assert_template :destroy
    refute @series.documents(true).include?(document)
  end

  view_test 'JSON GET #search returns filter results as JSON' do
    publication = create(:publication, title: 'search term')

    get :search, document_series_id: @series, title: 'search term', format: :json

    assert_response :success

    response_as_hash = JSON.parse(response.body)
    assert_equal true, response_as_hash['results_any?']
    assert_equal 1, response_as_hash['results'].size

    publication_json = response_as_hash['results'][0]
    assert_equal publication.id, publication_json['id']
    assert_equal publication.document_id, publication_json['document_id']
    assert_equal publication.title, publication_json['title']
    assert_equal 'publication', publication_json['type']
    assert_equal publication.display_type, publication_json['display_type']
  end
end
{'fraction_non_alphanumeric': 0.09036422314430613, 'fraction_numerical': 0.003918856615952052, 'mean_word_length': 4.816353887399464, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '5326284', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1225, 'n_words': 328}