2013-01-07 28 views
0

我正在使用Rails 3.1.0和Rspec 2.12.2。我想有,我們通過jQuery張貼到一個動作:命名的路徑在rspec中未被識別

/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 

具有以下命名路線:

的routes.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$ 

THX

回答

1

控制器規格不使用路由的determing叫什麼 - 他們只是叫你指定的方法。

+0

thx - 這看起來正確。我使用控制器而不是請求規範的唯一原因是處理cookie。有沒有更好的方法來處理這個問題? – timpone

+0

我認爲你仍然可以在請求規範中規定cookie的內容。 –

+0

好的,thx - 我會研究它(也許是另一個?) – timpone