我正在使用以下路线:
resources :groups, :only => [:show, :create, :update, :destroy] do
get 'viewmembers' => 'groups#view_members"
end
但是当我试图在RSpec中测试时:
describe "GET #viewmembers" do
context "the group members are retrieved" do
before do
@group = FactoryGirl.create :group
..
get :viewmembers, group_id: @group.id
end
it { should respond_with :ok}
# others tests...
end
我收到以下错误:
Failure/Error: get 'viewmembers', group_id: @group.id
ActionController::UrlGenerationError:
No route matches {:action=>"viewmembers", :controller=>"api/v1/groups", :group_id=>"1"}
以下是rake routes
中列出的内容:
GET /api/v1/groups/:group_id/viewmembers(.:format) api/v1/group#viewmembers{:format=>:json}`
如果我采用嵌套的do-end块的get 'viewmembers'...
路由OUT作为组资源,如下所示:
resources :groups, :only => [:show, :create, :update, :destroy]
get '/groups/viewmembers' => 'groups#view_members'
然后rspec测试运行正常,因此我必须解决我制定请求的方式...