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

class UserTest < Test::Unit::TestCase
  fixtures :users
  
  def test_invalid_with_empty_attributes
    user = User.new
    assert !user.valid?
    assert user.errors.invalid?(:email)
    assert user.errors.invalid?(:pass_crypt)
    assert user.errors.invalid?(:display_name)
    assert user.errors.invalid?(:email)
    assert !user.errors.invalid?(:home_lat)
    assert !user.errors.invalid?(:home_lon)
    assert !user.errors.invalid?(:home_zoom)
  end
  
  def test_unique_email
    new_user = User.new(:email => users(:normal_user).email,
      :active => 1, 
      :pass_crypt => <PASSWORD>.<PASSWORD>('<PASSWORD>'),
      :display_name => "new user",
      :data_public => 1,
      :description => "desc")
    assert !new_user.save
    assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:email)
  end
  
  def test_unique_display_name
    new_user = User.new(:email => "<EMAIL>",
      :active => 0,
      :pass_crypt => <PASSWORD>('<PASSWORD>'),
      :display_name => users(:normal_user).display_name, 
      :data_public => 1,
      :description => "desc")
    assert !new_user.save
    assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:display_name)
  end
end
<commit_msg>Check to see if the e-mail test works<commit_after>require File.dirname(__FILE__) + '/../test_helper'

class UserTest < Test::Unit::TestCase
  fixtures :users
  
  def test_invalid_with_empty_attributes
    user = User.new
    assert !user.valid?
    assert user.errors.invalid?(:email)
    assert user.errors.invalid?(:pass_crypt)
    assert user.errors.invalid?(:display_name)
    assert user.errors.invalid?(:email)
    assert !user.errors.invalid?(:home_lat)
    assert !user.errors.invalid?(:home_lon)
    assert !user.errors.invalid?(:home_zoom)
  end
  
  def test_unique_email
    new_user = User.new(:email => users(:normal_user).email,
      :active => 1, 
      :pass_crypt => Digest::MD5.hexdigest('<PASSWORD>'),
      :display_name => "new user",
      :data_public => 1,
      :description => "desc")
    assert !new_user.save
    assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:email)
  end
  
  def test_unique_display_name
    new_user = User.new(:email => "<EMAIL>",
      :active => 0,
      :pass_crypt => Digest::MD5.hexdigest('test'),
      :display_name => users(:normal_user).display_name, 
      :data_public => 1,
      :description => "desc")
    assert !new_user.save
    assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:display_name)
  end
  
  def test_email_valid
    ok = %w{ <EMAIL> <EMAIL> hello_local@ping-d.ng <EMAIL> <EMAIL> }
    bad = %w{ hi ht@ n@ @.com help@.me.uk help"hi.me.uk }
    
    ok.each do |name|
      user = users(:normal_user)
      user.email = name
      assert user.valid?, user.errors.full_messages
    end
    
    bad.each do |name|
      user = users(:normal_user)
      user.email = name
      assert !user.valid?, "#{name} is valid when it shouldn't be" 
    end
  end
end

{'fraction_non_alphanumeric': 0.13925263494091344, 'fraction_numerical': 0.0031938677738741618, 'mean_word_length': 3.4935437589670015, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1270338', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1029, 'n_words': 199}