我正在使用 Rails 3.1.0 和 Rspec 2.12.2。我想要一个我们通过 jQuery 发布到的操作:
/path/api/save-reply
我有以下规格:
describe 'test adding new mb post' do
it 'shall add a new mb post' do
post :save_reply, mb_detail: 'here is my detail', timestamp_id: 123, parent_id: 50, depth: 0
end
end
使用以下命名路线:
路线.rb
post '/api/save-reply' => 'api_mb#save_mb_reply', :as => :save_reply, :defaults => { :format => 'json' }
并得到以下错误:
1) ApiMbController test adding new mb post shall add a new mb post
Failure/Error: post :save_reply, mb_detail: 'here is my detail', timestamp_id: 123, parent_id: 50, depth: 0
AbstractController::ActionNotFound:
The action 'save_reply' could not be found for ApiMbController
# ./spec/controllers/api_mb_controller_spec.rb:16:in `block (3 levels) in <top (required)>'
规范不应该调用正确的路径“save_mb_reply”而不是尝试“save_reply”吗?我究竟做错了什么?
如果我运行:
Mon Jan 07$ bundle exec rake routes | grep save_reply
save_reply POST /arc/v1/api/save-reply(.:format) {:format=>"json", :controller=>"api_mb", :action=>"save_mb_reply"}
Mon Jan 07$
提前谢谢