<commit_before>require 'spec_helper'

describe User do

  describe "#initialize" do

    let(:user) {FactoryGirl.build(:user)}

    it "by creating a new instance of User" do
      user.should be_an_instance_of User
    end

    it "by increasing the number of users" do
      expect{user.save}.to change{User.count}.by(1)
    end

  end

  describe "associations" do
    it { should have_many :questions }
    it { should have_many :answers }
    it { should have_many :comments }
    it { should have_many :votes }
  end

  describe "validations" do
    it { should validate_presence_of :email }
    it { should validate_uniqueness_of :email }
    # it { should validate_length_of :email, :minimum => 3 }
    it { should_not allow_value("blah").for(:email) }
    it { should_not allow_value("b lah").for(:email) }
    it { should allow_value("a<EMAIL>").for(:email) }
    it { should_not allow_value("a.com").for(:email) }
    it { should allow_value("<EMAIL>").for(:email) }
    it { should validate_presence_of :username }
    it { should validate_uniqueness_of :username }
    it { should ensure_length_of(:username).is_at_least(3).
              with_message(/must be at least 3 characters, fool!/) }
    # it { should validate_uniqueness_of :username }
  end

end<commit_msg>complete validation testing in user model spec<commit_after>require 'spec_helper'

describe User do

  describe "create User" do

    it " is valid by creating a new instance of User" do
      user = FactoryGirl.build(:user)
      expect(user).to be_valid
    end

    it "is invalid without a username" do
      expect(User.new(username: '', password: 'password', password_confirmation: 'password', email: '<EMAIL>')).to have(2).errors_on(:username)
    end

    it "is invalid without a unique username" do
      User.create(username: 'alexander', password: 'password', password_confirmation: 'password', email: '<EMAIL>')
      expect(User.new(username: 'alexander', password: 'password', password_confirmation: 'password', email: '<EMAIL>')).to have(1).errors_on(:username)
    end

    it "is invalid without a username greater than 3 chars" do
      expect(User.new(username: 'al', password: 'password', password_confirmation: 'password', email: '<EMAIL>')).to have(1).errors_on(:username)
    end

    it "is invalid without an email" do
      expect(User.new(username: 'alexander', password: 'password', password_confirmation: 'password', email: '')).to have(2).errors_on(:email)
    end

    it "is invalid without a unique email" do
      User.create(username: 'alexander', password: 'password', password_confirmation: 'password', email: '<EMAIL>')
      expect(User.new(username: 'alexander', password: 'password', password_confirmation: 'password', email: '<EMAIL>')).to have(1).errors_on(:email)
    end

    it "is invalid without a correctly formatted email" do
      expect(User.new(username: 'alexander', password: 'password', password_confirmation: 'password', email: 'yahoo.com')).to have(1).errors_on(:email)
    end

    it "is invalid without a pasword" do
      expect(User.new(username: 'alexander', password: '', password_confirmation: 'password', email: '<EMAIL>')).to have(1).errors_on(:password)
    end

    it "is invalid without a correct password confirmation" do
     expect(User.new(username: 'alexander', password: 'password', password_confirmation: '<PASSWORD>', email: '<EMAIL>')).to have(1).errors_on(:password_confirmation)
    end
  end

  describe "User associations" do
    it { should have_many :questions }
    it { should have_many :answers }
    it { should have_many :comments }
    it { should have_many :votes }
  end

end
{'fraction_non_alphanumeric': 0.12592389816589106, 'fraction_numerical': 0.0035587188612099642, 'mean_word_length': 4.019230769230769, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, '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': '2747114', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1090, 'n_words': 325}