[Rails] Re: Testing controller

2009-08-13 Thread Phlip
Jim Burgess wrote: > I wrote some tests for my controller which all worked as they should > until I added http authentication using 'before_filter :authenticate' Google (or use Google CodeSearch) and find login_as Put it in your def setup, or in the top of each test: login_as :bob Such a m

[Rails] Re: Testing controller

2009-08-13 Thread Sijo Kg
Hi Jim Burgess You can do same also like user @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user.email,"password") And you can move it to a function as I said above Sijo -- Posted via http://www.ruby-forum.com/. --~--~-~--

[Rails] Re: Testing controller

2009-08-13 Thread Jim Burgess
Hi Sijo, Thanks for your reply. It certainly put me on the right track. I solved the problem slightly differently, by adding: def setup super @request.env['HTTP_AUTHORIZATION'] = 'Basic ' + Base64::encode64("user:pass") end (where 'user' is the user name and 'pass' is the password). to my

[Rails] Re: Testing controller

2009-08-13 Thread Sijo Kg
Hi Once I have answered this Suppose if you are using a session varible person_id it can be done like for example in test_helper just write a def like def login_as(person) @request.session[:person_id] = person ? person.id : nil end And from your test call this by passing administrator