我的invoice_id
是:
routes.rb
我的Rails.application.routes.draw do
namespace :api, path: "/", constraint: { subdomain: "api" }, defaults: { format: :json } do
scope module: :v1 do
resources :users, only: [:show]
end
end
end
是:
users_controller.rb
我的测试是:
class Api::V1::UsersController < ApplicationController
respond_to :json
def show
respond_with User.find(params[:id])
end
end
为什么此测试会出现以下错误:
require 'test_helper'
class Api::V1::UsersControllerTest < ActionController::TestCase
test '#show displays the specific user' do
@user = FactoryGirl.create(:user)
get :show, id: @user.id, format: :json
assert_response :success
end
end
答案 0 :(得分:0)
我只需要在测试中添加约束:
get :show, id: @user.id, format: :json, :constraint=>{:subdomain=>"api"}