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 8232085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:42:47+00:00 2026-06-07T17:42:47+00:00

This following Controller test is failing, and I can’t figure out why: describe GET

  • 0

This following Controller test is failing, and I can’t figure out why:

describe "GET 'index'" do 

    before(:each) do 
        @outings = FactoryGirl.create_list(:outing, 30)
        @user = FactoryGirl.create(:user)
    end 

    it "should be successful" do 
        get :index
        response.should be_success
    end 

end

Rspec offers up the (rather unhelpful) error:

Failure/Error: response.should be_success
   expected success? to return true, got false

Here’s the code for the actual Controller, too:

def index
    if @user
        @outings = Outing.where(:user_id => @user.id)
        @outing_invites = OutingGuest.where(:user_id => @user.id)
     else
        flash[:warning] = "You must log in to view your Outings!"
        redirect_to root_path
     end 
end

Anyone have an idea what’s causing my test to fail? I assume it may have something to do with the conditional in the Outing Controller, but I have no idea what a passing test would look like…

  • 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-07T17:42:49+00:00Added an answer on June 7, 2026 at 5:42 pm

    You’re confusing instance variables between two separate classes – the controller is its own class and the specification is its own class. They don’t share state. You could try this simple example to get a better understanding…

    def index
        // obvious bad code, but used to prove a point
        @user = User.first
        if @user
            @outings = Outing.where(:user_id => @user.id)
            @outing_invites = OutingGuest.where(:user_id => @user.id)
         else
            flash[:warning] = "You must log in to view your Outings!"
            redirect_to root_path
         end 
    end
    

    I’ll guess that FactoryGirl.create_list(:outing, 30) doesn’t create an outing associating the first user with the outing since you’re creating the user after you create the outing so your Outing.where will fail as well.

    Its important to understand that when you are including the database in your test stack the database needs to contain the data in the way the test expects. So if your controller is querying for outings belonging to a specific user your spec needs to setup the environment such that the user the controller will retrieve (in this case, the terrible line with User.first from my example) will also have the outings associated with it that the specification is expecting.

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

Sidebar

Related Questions

This is basic stuff but I can't get this following form to process reliably.
The following is in my spec/controllers/superadmin/users_controller_spec.rb: describe GET index do it receives the where
Please take a look at the following code in a controller named test: $this->load->library('pagination');
I have the following Model and Controller files, and when i visit this url,
I have this following jquery text fly-in animation.Here is my code before I explain
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
My question is similar to this following post Render a view of another controller
Lets say i have the following controller: // // GET: /Courses/Edit/5 public ActionResult Edit(int
I have the following controller action and test. I'm new to testing with Shoulda
I'm getting this warning in my Test::Unit output... /usr/local/bin/ruby -I.:lib:test -rtest/unit -e %w[test/functional/sessions_controller_test.rb].each {

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.