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

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

class UsersControllerTest < ActionController::TestCase

  all_fixtures
  def setup
    @controller = UsersController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  should 'not access without right permission' do
    create_user('guest')
    login_as 'guest'
    get :index
    assert_response 403 # forbidden
  end

  should 'grant access with right permission' do
    admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default)
    login_as('admin_user')

    get :index
    assert_response :success
  end

  should 'response as XML to export users' do
    admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default)
    login_as('admin_user')

    get :index, :format => 'xml'
    assert_equal 'application/xml', @response.content_type
  end

  should 'response as CSV to export users' do
    admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default)
    login_as('admin_user')

    get :index, :format => 'csv'
    assert_equal 'text/csv', @response.content_type
  end

end
<commit_msg>Fixes test so it meets the new logic for download xml users lis<commit_after>require File.dirname(__FILE__) + '/../test_helper'
require 'users_controller'

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

class UsersControllerTest < ActionController::TestCase

  all_fixtures
  def setup
    @controller = UsersController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
  end

  should 'not access without right permission' do
    create_user('guest')
    login_as 'guest'
    get :index
    assert_response 403 # forbidden
  end

  should 'grant access with right permission' do
    admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default)
    login_as('admin_user')

    get :index
    assert_response :success
  end

  should 'response as XML to export users' do
    admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default)
    login_as('admin_user')

    get :index, :format => 'xml'
    assert_equal 'text/xml', @response.content_type
  end

  should 'response as CSV to export users' do
    admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default)
    login_as('admin_user')

    get :index, :format => 'csv'
    assert_equal 'text/csv', @response.content_type
  end

end

{'fraction_non_alphanumeric': 0.08760155422112328, 'fraction_numerical': 0.0021193924408336277, 'mean_word_length': 4.499029126213593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7046242', 'n_tokens_mistral': 839, 'n_tokens_neox': 803, 'n_words': 228}