<commit_before>require 'test/helper'

class Admin::PostsControllerTest < ActionController::TestCase

  def test_should_generate_xml

    assert @typus_user.is_root?

    expected = <<-RAW
<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <status>unpublished</status>
    <title>Owned by admin</title>
  </post>
  <post>
    <status>unpublished</status>
    <title>Owned by editor</title>
  </post>
  <post>
    <status>published</status>
    <title>Title One</title>
  </post>
  <post>
    <status>unpublished</status>
    <title>Title Two</title>
  </post>
</posts>
    RAW

    get :index, :format => 'xml'
    assert_equal expected, @response.body

  end

  def test_should_generate_csv

    assert @typus_user.is_root?

    expected = <<-RAW
Title,Status
Owned by admin,unpublished
Owned by editor,unpublished
Title One,published
Title Two,unpublished
     RAW

    get :index, :format => 'csv'
    assert_equal expected, @response.body

  end

end<commit_msg>Fixed generate_csv test as now we get a file.<commit_after>require 'test/helper'

class Admin::PostsControllerTest < ActionController::TestCase

  def test_should_generate_xml

    assert @typus_user.is_root?

    expected = <<-RAW
<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <status>unpublished</status>
    <title>Owned by admin</title>
  </post>
  <post>
    <status>unpublished</status>
    <title>Owned by editor</title>
  </post>
  <post>
    <status>published</status>
    <title>Title One</title>
  </post>
  <post>
    <status>unpublished</status>
    <title>Title Two</title>
  </post>
</posts>
    RAW

    get :index, :format => 'xml'
    assert_equal expected, @response.body

  end

  def test_should_generate_csv

    assert @typus_user.is_root?

    expected = <<-RAW
title;status
Title One;published
Title Two;unpublished
Owned by admin;unpublished
Owned by editor;unpublished
     RAW

    get :index, :format => 'csv'
    assert_response :success

    assert @response.body.is_a?(Proc)
    require 'stringio'
    output = StringIO.new
    output.binmode
    assert_nothing_raised { @response.body.call(@response, output) }
    assert_equal(expected, output.string)

  end

end
{'fraction_non_alphanumeric': 0.127996381727725, 'fraction_numerical': 0.0027137042062415195, 'mean_word_length': 3.656842105263158, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 2, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '3521209', 'n_tokens_mistral': 765, 'n_tokens_neox': 730, 'n_words': 168}