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

  • SEARCH
  • Home
  • 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 8109231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:21:16+00:00 2026-06-06T01:21:16+00:00

I am trying to test my show action, but I first must save an

  • 0

I am trying to test my show action, but I first must save an object to the DB for it to show.

test "should get show" do
  post :create, question: { question: 'apple'}
  get :show, {'id' => "1"}
  assert_response :success
  assert_not_nil assigns(:question)
end

In another test, I have the post :create... line and it works. But, here I keep getting ActiveRecord::RecordNotFound: Couldn't find Question with id=1 and so I’m not sure what the issue is. How do I fix this? Big picture what is the best way to do this?

Edit:

I’ve changed my test to look like this:

test "should get show" do
    post :create, question: {set_id: 4}
    pp Question.all
    get :show, {'id' => "1"}
    assert_response :success
    assert_not_nil assigns(:question)
end

Which gives me:

[#<Question id: 261990764, question: "Who was... updated_at: "2012-06-15 19:34:16">,
 #<Question id: 607888892, question: "Who was... updated_at: "2012-06-15 19:34:16">,
 #<Question id: 607888893, question: nil, ... set_id: 4,...]

Which is what you would expect, except for the ID part. Does rails assign random IDs in the test environment?

Here is my passing test:

test "should get show" do
  q = Question.new(question: 'q', answer: 'a', set_id: 1)
  q.save
  get :show, {id: q.id}
  assert_response :success
  assert_not_nil assigns(:question)
end

Still would love for someone to explain to me why the ID is so high though and how rails assigns it.

And, Here is an example that takes advantage of fixtures:

test "should get show2" do
    get :show, {id: questions(:prez_one).id}
    assert_response :success
    assert_not_nil assigns(:question)
end
  • 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-06T01:21:17+00:00Added an answer on June 6, 2026 at 1:21 am

    Have you checked if the Question you created has id = 1?
    Is the id column auto-incremented in your db?
    Are you using MySQL db?

    You might want to show all Questions after the post :create line.
    Then, select the Question with apple to get the corresponding id.

    Hope that helps.

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

Sidebar

Related Questions

I'm trying to show test run log (text file in a windows server) to
I am trying to plot some test data (show at the end of this
I'm trying to test an Activity in android which will show a ProgressDialog and
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I am trying to post to my facebook page wall using curl but i
I'm trying to do a simple test post with jQuery in Kohana. Note that
I am trying to create a test application the source is the following (index.php):
I've created a quick test to show what I'm trying to do: http://jsfiddle.net/zY3HH/ If
I'm trying to make it so that my script will show test.jpg in an

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.