0
我有一個規範,我覺得應該沒有問題,但我相信,因爲它是一個嵌套的資源,它可能會拋出我的請求。我在Ruby 2.3.3中使用Rails 4.2。這是怎麼回事?我知道這是一個有效的途徑,因爲當它出現時,我打rake routes
RSpec路由錯誤w /嵌套資源
的routes.rb
scope '/organizations/:organization_id' do
get 'dashboard', to: 'projects#dashboard'
resources :projects, except: [:delete] do
get 'configure', to: 'projects#configure'
post 'configure', to: 'projects#configure'
get 'team', to: 'projects#team'
get 'subprojects', to: 'projects#subprojects'
collection do
get 'search', to: 'projects#search'
get 'find', to: 'projects#find'
post 'create_by_sf_id', to: 'projects#create_by_sf_id'
end
resources :courses do
get 'module_progress', to: 'courses#module_progress'
get 'add_content', to: 'courses#add_content'
get 'summary', to: 'courses#summary'
post 'summary', to: 'courses#summary'
end
resources :tasks
end
end
projects_controller_spec.rb
describe 'GET project_team' do
it 'should render the project team page' do
get :team, organization_id: organization.id, id: project.id
expect(response.code).to eq '200'
end
end
projects_controller.rb
def team
@team = @project.project_team
end
... Aaa和由此產生的錯誤:
1) ProjectsController when authenticating as a customer GET project_team should render the project team page
Failure/Error: get :team, organization_id: organization.id, id: project.id
ActionController::UrlGenerationError:
No route matches {:action=>"team", :controller=>"projects", :id=>"460", :organization_id=>"417"}
# ./spec/controllers/projects_controller_spec.rb:90:in `block (4 levels) in <top (required)>'
這樣做。謝謝! – colincr
當然可以!如果您覺得如此傾向,請隨時接受。 – jvillian