开发者

How do you test namespace post :post routes?

开发者 https://www.devze.com 2023-02-14 21:24 出处:网络
I have these route # routes.rb name开发者_JAVA百科space :admin do resources :departments end And following code in controller test. It fails because post :create is not heading to admin_departments

I have these route

# routes.rb
name开发者_JAVA百科space :admin do
  resources :departments
end

And following code in controller test. It fails because post :create is not heading to admin_departments_path. What is the correct way to write this?

# test/functional/admin/departments_controller_test.rb 
# ActionController::RoutingError: No route matches (FAIL)
post :create, :department => @new_department.attributes


Controller tests are needlessly painful and too closely coupled to implementation. Don't use them.

The correct way to do this is to write a Cucumber scenario that posts something to the form, then checks that you ended up on the page you wanted to.

0

精彩评论

暂无评论...
验证码 换一张
取 消