Hi I am creating my `User` which the `User` requirements are: 
1. to have a `User.sponsor_id` with an exeption of the first user does not require to have a `sponsor_id`.
2. the sponsor\_id must be exist on User.

I have this code right now for the `model/user.rb`:

```
class User < ActiveRecord::Base  
  belongs_to :sponsor, class_name: "User"

  attr_accessor :remember_token
  before_save {email.downcase!} 
  validates :first_name, :presence =>true, length: {maximum: 50}
  validates :last_name, :presence => true, length: {maximum: 50}
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
  validates :email, :presence =>true, length: {maximum: 255}, format: {with: VALID_EMAIL_REGEX }, uniqueness: {case_sensitive: false }
  has_secure_password
  validates :password, presence: true, length: {minimum: 6}, allow_nil:true
  validates :sponsor, presence:true 
  validate :sponsor_id_valid

  .
  .
  .

  def first_user
    return true if User.count==0
    return true if persisted&& self.id== User.first.id
    return false
  end

  def sponsor_id_valid
    return if first_user
    unless self.class.find_by(id: sponsor_id)
      errors.add(:sponsor_id, "does not exist")
    end
  end
end

```

And I have this code for my db/migrate/...usertable.rb

```
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :first_name
      t.string :last_name
      t.string :email, unique: true
      t.integer :sponsor_id

      t.timestamps null: false
    end
    add_index :users, :sponsor_id
  end
end

```

And this is my `db/seeds.rb` file 

```
User.delete_all
User.create!(first_name: "Test",
            last_name: "User",
            email: "test@user.com",
            password: "password",
            password_confirmation: "password",
            sponsor_id: 1 )
10.times do |n|
  first_name = Faker::Name.name
  last_name=Faker::Name.name
  email = "example-#{n+1}@user.com"
  password = "password"
  User.create!(first_name: first_name,
               last_name: last_name,
               email: email,
               password: password,
               password_confirmation: password,
               sponsor_id:test.id )
end

```

The test code I want to past is in `test/model/users.rb`:

```
require 'test_helper'

class UserTest < ActiveSupport::TestCase

  def setup
      @user=User.first
      @user2=User.new(
      first_name: "Test2", 
      last_name: "User2", 
      email: "user2@test.com", 
      sponsor_id: @user.id,
      password:"foobar",
      password_confirmation:"foobar") 
      @user2.save

  end

  test "1. should be valid" do
    byebug
    assert @user.valid?
  end

  test "2. First name should be present" do 
    @user.first_name = ""
    assert_not @user.valid?
  end

  test "3. Last name should be present" do 
    @user.last_name=""
    assert_not @user.valid?
  end

  test "4. email should be present" do
    @user.email=""
    assert_not @user.valid?
  end

  test "5. sponsor_id should be present" do
    @user2.sponsor_id= nil
    assert_not @user2.valid?
  end

  test "6.name should not be too long" do
    @user.first_name= "a" * 52
    @user.last_name="a" * 52
    assert_not @user.valid?
  end

  test "7. email should not be too long " do
    @user.email="a" * 244+ "@example.com"
    assert_not @user.valid?
  end

  test "8.email validation should accept valid addresses" do 
    valid_addresses= %w[userunique@test.com USER@foo.COM A_US-ER@foo.bar.org first.last@foo.jp alice+bob@bax.cn]
    valid_addresses.each do |valid_address|
      @user.email = valid_address
      assert @user.valid?, "#{valid_address.inspect} should be valid" 
    end
  end

  test "9. email validation should reject invalid addresses" do
    invalid_addresses = %w[user@example,com user_at_foo.org user.name@example. foo@bar_baz.com foo@bar+baz.com foo@bar..com]
    invalid_addresses.each do |invalid_address|
      @user.email = invalid_address
      assert_not @user.valid?, "#{invalid_address.inspect} should be invalid"
   end
  end

  test "10. Email addresses should be unique" do 
    duplicate_user=@user.dup
    duplicate_user.email= @user.email.upcase
    @user.save
    assert_not duplicate_user.valid?
  end

  test "11. password should be present (nonblank" do 
    @user.password = @user.password_confirmation = " " * 6
    assert_not @user.valid?
  end

  test "12. password should have a minimum length" do
    @user.password = @user.password_confirmation = "a" * 5 
    assert_not @user.valid?
  end

  test "13. email addresses should be saved as lower-case" do
    mixed_case_email = "PEaK@ExAMPle.CoM"
    @user.email = mixed_case_email
    @user.save
    assert_equal mixed_case_email.downcase, @user.reload.email
      end

  test "14.sponsor_id must be presence" do 
    @user2.sponsor_id= nil 
    assert_not @user2.valid?
  end

  test "15. the sponsor_id must be the existing id" do
    @user2.sponsor_id = 1000
    assert_not @user2.valid?
  end

  test "16. authenticated? should return false for a suer with nil digest" do
    assert_not @user.authenticated?('')
  end

end

```

When I run `rake db:seed` it always said I have wrong argument 
Can anyone help me? Please advise.

This is the full error message :

```
$ rake db:seed --trace
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Sponsor can't be blank
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/validations.rb:79:in `raise_record_invalid'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/validations.rb:43:in `save!'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/transactions.rb:291:in `block in save!'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/transactions.rb:220:in `transaction'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/transactions.rb:291:in `save!'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/persistence.rb:51:in `create!'
/Users/peakdrum/workspace/Goldshape/db/seeds.rb:3:in `<top (required)>'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/engine.rb:547:in `load_seed'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/peakdrum/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/peakdrum/.rbenv/versions/2.2.3/bin/rake:33:in `<main>'
Tasks: TOP => db:seed

```

Thanks in advance

PS @RichPeck (I don't know how to tag) but this is the upgraded version