Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:05:04+00:00 2026-06-03T09:05:04+00:00

I am getting this error, when starting spec tests. I understand that connection with

  • 0

I am getting this error, when starting spec tests. I understand that connection with the user is not set. What shall I do to pass the tests?

RSpec file : posts_controller_spec.rb

require 'spec_helper'
include Devise::TestHelpers

describe PostsController do
  render_views

  context "Logged in as user" do
    let(:user) { FactoryGirl.create(:user) }

    before { login_as(user) }

    context "on viewing index page" do
      let!(:p) { FactoryGirl.create(:post) }

      before { get :index }

      it { should respond_with(:success) }

      it { assigns(:posts).should == [p] }
    end
  end
end

My view: _home.html.erb

<% @posts.each do |post| %>
  <%= link_to post.title, post %>

    <%= post.user.full_name %></i></b><hr />

    <div>
      <%= post.content.html_safe %>
    </div>
<% end %>

RSpec failures:

PostsController Logged in as user on viewing index page 
     Failure/Error: before { get :index }
     ActionView::Template::Error:
       undefined method `full_name' for nil:NilClass
     # ./app/views/posts/_home.html.erb:5:in `block in _app_views_posts__home_html_erb__709569216_93469850'
     # ./app/views/posts/_home.html.erb:2:in `each'
     # ./app/views/posts/_home.html.erb:2:in `_app_views_posts__home_html_erb__709569216_93469850'
     # ./app/views/posts/index.html.erb:1:in `_app_views_posts_index_html_erb___825727830_90641210'
     # ./spec/controllers/posts_controller_spec.rb:33:in `block (4 levels) in <top (required)>'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:05:05+00:00Added an answer on June 3, 2026 at 9:05 am

    Without seeing your model for Post and User, it looks like you need to change

    let!(:p) { FactoryGirl.create(:post) }
    

    to

    let!(:p) { FactoryGirl.create(:post, :user => user) }
    

    or

    let!(:p) { FactoryGirl.create(:post, :user_id => user.id) }
    

    to correctly set up the association.

    However, if your view is assuming that a Post always has a User, maybe your Post model should validate the presence of a User, or maybe you should change your view to handle the case where a Post does not have a User.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am getting this error while starting OracleMTSRecoveryService : Could not start the OracleMTSRecoveryService
Just as the title says. I'm getting this error when starting a Service that
We are getting this error on starting tomcat (both as a service and via
I am getting this error message when starting my local neo4j server for development
Im getting this error, What is the reason it? Starting Server Exception in thread
I've uploaded an MVC3 website and I'm getting this error: Could not load file
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException Why am I getting this error while starting my server
I am getting this exception sometimes when my program is starting connection to MS
I am getting this error when starting JBoss with my application built with warbler:
Starting form now, for the first time, I am getting this error when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.