title: undefined local variable or method `user' for main:Object (NameError)
body: <p>If i run rspec spec in terminal I will see this error:</p>
  
  <pre><code>3:in `&lt;top (required)&gt;': undefined local variable or method `user' for main:Object (NameError)
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `block in load'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `each'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in `setup'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:in `run'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in `run'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:in `invoke'
  from /home/marketa/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.3.2/exe/rspec:4:in `&lt;top (required)&gt;'
  from /home/marketa/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `load'
  from /home/marketa/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `&lt;main&gt;'
  from /home/marketa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
  from /home/marketa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `&lt;main&gt;'
  </code></pre>
  
  <p>My app/models/user.rb looks like this:</p>
  
  <pre><code>  class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
  
      belongs_to :contact, :foreign_key =&gt; "contact_id", dependent: :destroy
      accepts_nested_attributes_for :contact
  
      has_many :advertisements
      has_many :reviews
  
      #accepts_nested_attributes_for :contact
      #accepts_nested_attributes_for :contact&gt;&gt;&gt;&gt;&gt;&gt;&gt; e29ade655eb7ee8f553f049b9fbb505581246758
      after_create :welcomer
      before_create :set_default_role
  
      validates :email, presence: true
  
      ROLES = %w[admin user]
      devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  
       def get_replies_where_advertisement(advertisement, user)
      Reply.where("advertisement_id = ? OR receiver = ?", advertisement.id, user.id).order(created_at: :DESC)
  
  
      end
  
  
      def get_replies_user(reply)
      user = User.find_by(:id =&gt; reply.user_id)
  
    end
  
    private
    def welcomer
      UserMailer.welcome_email(self)
    end
  
    def set_default_role
      if self.role.blank?
          self.role = 'user'
      end
    end
  
  end
  </code></pre>
  
  <p>My spec/models/user_spec.rb looks like this:</p>
  
  <pre><code>require  'rails_helper'
  RSpec.describe user, type: :model do
  describe "relation" do
      it {should has_many :advertisements}
      it {should has_many :reviews}
      it {should belongs_to(:contact).dependent(:destroy)}
  end
  
  describe "validation" do
      it {should validate_presence_of :email}
  end
  end
  </code></pre>
  
  <p>And my spec/factories/user.rb looks like this</p>
  
  <pre><code>require 'faker'
  
  FactoryGirl.define do
      factory :user do
  
      end
  end
  </code></pre>
  
  <p>Please help, thanks</p>