Hello, there is such a test:

it "renders show template if an item is found" do question = Question.create get :show, {id: question.id} expect(response).to render_template(assigns(:question)) end 

The factory is responsible for creating the question.

 FactoryGirl.define do factory :question do title "test title" description "Test description" visitors 5 association(:user) end end 

The model has two lines of validation:

  validates :title, presence: true validates :description, presence: true 

The show method simply displays the question. Please explain why an error occurs:

  1) QuestionsController Show action renders show template if an item is found Failure/Error: get :show, {id: question.id} ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"questions", :id=>nil} 

On the site, adding a question works.

  • Well, apparently the question is not created - Mal Skrylev

2 answers 2

Error corrected so

 it "renders show template if an item is found" do user = User.create question = FactoryGirl.create(:question, user_id: user.id) get :show, {id: question.id} response.should render_template('show') end 

    You did not specify an id in the factory, so it takes the value nil , and the router is incorrectly configured. Try adding it to the factory.

     FactoryGirl.define do factory :question do sequence(:id) title "test title" description "Test description" visitors 5 association(:user) end end 
    • It did not help (The same error - Maxim Cherevatov