Rails 4: Testing a GET Request on a Name Extension Controller

I have a failed test that I am trying to understand. I have a class Users::QueriesController < ApplicationController controller class Users::QueriesController < ApplicationController in application / controllers / users / queries_controller.rb that has a show action and a corresponding route with names:

 namespace :users do resources :queries end 

I also have a test for the test / controllers / users / queries_controller_test.rb:

 require 'test_helper' class Users::QueriesControllerTest < ActionController::TestCase test "accessing :show action" do get :show assert_response :success end end 

Running this test results in ActionController::UrlGenerationError: No route matches {:controller=>"users/queries", :action=>"show"} .

Running rake routes includes this line: users_query GET /users/queries/:id(.:format) users/queries#show .

What's going on here? I am using Rails 4.0.0.

+4
source share
1 answer

I think you need to provide show action id

  test "accessing :show action" do get :show, {:id => 1} assert_response :success end 

The correct way to the rails 4.

Please try and let me know the result.

+8
source

Source: https://habr.com/ru/post/1489837/


All Articles