<commit_before>describe API do
  include Rack::Test::Methods

  def app
    API::API
  end

  before :each do
    DatabaseCleaner.start
  end

  after :each do
    DatabaseCleaner.clean
  end

  it 'should persist the user correctly' do
    public_key = generate_public_key
    user_json = {
      username: 'test',
      password: '<PASSWORD>!',
      password_confirmation: '<PASSWORD>!',
      public_key: public_key
    }.to_json
    post '/v1/users', user_json, 'CONTENT_TYPE' => 'application/json'

    expect(last_response.status).to eq(201)
    user_id = User.first(username: 'test').id
    expect(last_response.body).to eq(
      {
        id: user_id,
        username: 'test',
        public_key: public_key,
        url: "http://example.org/v1/users/#{user_id}"
      }.to_json
    )
    expect(User.all.count).to eq(1)
  end

  it 'should error when a username is not given' do
    user_json = {
      password: '<PASSWORD>!',
      password_confirmation: '<PASSWORD>!',
      public_key: generate_public_key
    }.to_json
    post '/v1/users', user_json, 'CONTENT_TYPE' => 'application/json'

    expect(last_response.status).to eq(422)
    expect(last_response.body).to eq({
      'message' => ['Username must not be blank']
    }.to_json)
    expect(User.all.count).to eq(0)
  end

  it 'should error when a username contains illegal characters' do
    user_json = {
      username: 'test?',
      password: '<PASSWORD>!',
      password_confirmation: '<PASSWORD>!',
      public_key: generate_public_key
    }.to_json
    post '/v1/users', user_json, 'CONTENT_TYPE' => 'application/json'

    expect(last_response.status).to eq(422)<commit_msg>improve user test<commit_after>describe API do
  include Rack::Test::Methods

  def app
    API::API
  end

  before :each do
    DatabaseCleaner.start
  end

  after :each do
    DatabaseCleaner.clean
  end

  it 'should persist the user correctly' do
    public_key = generate_public_key
    user_json = {
      username: 'flower-pot',
      password: '<PASSWORD>!',
      password_confirmation: '<PASSWORD>!',
      public_key: "-----<KEY>"
    }.to_json
    post '/v1/users', user_json, 'CONTENT_TYPE' => 'application/json'

    expect(last_response.status).to eq(201)
    user_id = User.first(username: 'flower-pot').id
    expect(last_response.body).to eq(
      {
        id: user_id,
        username: 'flower-pot',
        public_key: "-----<KEY>-----\n",
        url: "http://example.org/v1/users/#{user_id}"
      }.to_json
    )
    expect(User.all.count).to eq(1)
  end

  it 'should error when a username is not given' do
    user_json = {
      password: '<PASSWORD>!',
      password_confirmation: '<PASSWORD>!',
      public_key: generate_public_key
    }.to_json
    post '/v1/users', user_json, 'CONTENT_TYPE' => 'application/json'

    expect(last_response.status).to eq(422)
    expect(last_response.body).to eq({
      'message' => ['Username must not be blank']
    }.to_json)
    expect(User.all.count).to eq(0)
  end

  it 'should error when a username contains illegal characters' do
    user_json = {
      username: 'test?',
      password: '<PASSWORD>!',
      password_confirmation: '<PASSWORD>!',
      public_key: generate_public_key
    }.to_json
    post '/v1/users', user_json, 'CONTENT_TYPE' => 'application/json'

    expect(last_response.status).to eq(422)
{'fraction_non_alphanumeric': 0.13442622950819672, 'fraction_numerical': 0.00894187779433681, 'mean_word_length': 2.8932714617169375, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, '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': '940404', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1102, 'n_words': 253}