Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a different post to a different controller in Rails Functional Test

I want to make a post request to a different controller inside my functional test which is intended for a particular controller. However the post method in ActiveController class just takes the method to be called, it doesn't take the controller name to be called. Any ideas how to invoke a different controller?

like image 239
Snehal Avatar asked May 12 '10 02:05

Snehal


1 Answers

When you create tests for controllers using ActiveSupport::TestCase, you can set which controller to test when you don't want it inferred.

So you could add another class to your test for the current controller, set the controller to test against within the new class, and implement your test cases.

You didn't provide code so I can't provide a coded solution but here's a blog post regarding testing all methods on controller under RSpec: http://blog.wolfman.com/articles/2007/7/28/rspec-testing-all-actions-of-a-controller

[Personally, I moved away from RSpec/TestUnit for controller tests beyond route checks and fuzzy testing. I much prefer integration testing (e.g. Cucumber) for something that involves multiple parts of the system.]

like image 68
databyte Avatar answered Sep 30 '22 16:09

databyte