title: rails post test model error
body: <p>So this is the error I'm getting</p>
  
  <p>.F</p>
  
  <p>Failure:
  PostTest#test_post_should_be_valid [/home/ubuntu/workspace/test/models/post_test.rb:9]:
  ["User must exist"]</p>
  
  <p>I'm not sure what it means by "user must exist" since I'm pretty sure a user with an user_id one does exist.
  heres my code</p>
  
  <h1>post_test.rb</h1>
  
  <pre><code>require 'test_helper'
  
  class PostTest &lt; ActiveSupport::TestCase
    def setup
      @post=Post.new(user_id: "1",name:"ruby meetup")
    end
  
    test "post should be valid" do
      assert @post.valid?, @post.errors.full_messages
    end
  
  end
  </code></pre>
  
  <h1>post.rb</h1>
  
  <pre><code>class Post &lt; ApplicationRecord
  belongs_to :user
   geocoded_by :address
  after_validation :geocode, if: -&gt;(obj){ obj.address.present? and obj.address_changed? }
  reverse_geocoded_by :latitude, :longitude
  after_validation :reverse_geocode
  
  
    has_many :rsvps
    has_many :users, through: :rsvps
  
    validates :name, presence: true
  
  
  
  
  
  
  end
  </code></pre>
  
  <p>I'm not sure if this will be helpful but I'm also going to include my user test and user model.</p>
  
  <h1>user_test.rb</h1>
  
  <pre><code>require 'test_helper'
  
  class UserTest &lt; ActiveSupport::TestCase
    def setup
      @user=User.new(email:"fo30@hotmail.com", password: "h3h3123")
    end
  
  
    test "user should be valid" do
      assert @user.valid?, @user.errors.full_messages
    end
  end
  </code></pre>
  
  <h1>user.rb</h1>
  
  <pre><code>class User &lt; ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
           has_many :posts
  
            has_many :rsvps
            has_many :posts, through: :rsvps
  
            validates :email, presence: true
  
  
  
  
  
  end
  </code></pre>
  
  <p>Any help will greatly be appreciated as I just recently started testing in rails.</p>