0

我有几条这样的路线:

get '/test1' => 'test#index1', defaults: {common: '123'}
get '/test2' => 'test#index2', defaults: {common: '123'}

他们的规格如下:

specify do
  get('/test1').should route_to controller: 'test', action: 'index1', common: '123'
end
specify do
  get('/test2').should route_to controller: 'test', action: 'index2', common: '123'
end

如何干掉默认值的使用?

我试过with_options这样使用:

with_options defaults: {common: '123'} do |o|
  o.get '/test1' => 'test#index1'
  o.get '/test2' => 'test#index2'
end

但它用消息打破了第一个测试:

Failure/Error: get('/test1').should route_to controller: 'test', action: 'index1', common: '123'
       The recognized options <{"common"=>"123", "controller"=>"test", "action"=>"index2"}> did not match <{"controller"=>"test", "action"=>"index1", "common"=>"123"}>, difference: <{"action"=>"index1"}>.
       <{"controller"=>"test", "action"=>"index1", "common"=>"123"}> expected but was
       <{"common"=>"123", "controller"=>"test", "action"=>"index2"}>.

难道我做错了什么?还是有其他方法?

4

1 回答 1

1

你不需要with_options在这里,defaults也接受块:

defaults common: '123' do
  get '/test1' => 'test#index1'
  get '/test2' => 'test#index2'
end
于 2012-08-06T12:32:47.630 回答