Hi Tim,

We usually use this in our integration tests to make a faster login:

  visit '/dev/set_current_user?login=tecnicos%40unoycero.com'

So I guess you could try this in your controller tests:

  get '/dev/set_current_user?login=ew%40nowhere.com'

About the "set_current_user" URL. This is used by Hobo in the user changer select. This appears only in development mode and allows you to change user quickly. It turns out that it works in test mode too, and for us it has been really helpful.

Regards,
Ignacio

El 01/05/13 13:58, Tim Griffin escribió:
Hi all;

Being one of those RonR/Hoboists learning a lot of testing
/after/ having written the application (>cough<), I'm experiencing a
little head-scratching about testing a controller other than the
UsersController.

Could anyone enlighten me as to how to properly test a controller in
Hobo that requires a user to be logged in?

For example, with a TitlesController, the #index action in my
application is only available to an authenticated user. So, I want to
test as follows:

describe "TitlesController" do

   it "Authenticated user must see Titles index" do
     # User needs to be logged in. How?
     get :index
     it { must render_template(:index) }
     it { must respond_with(:success) }
   end

end

But, anything I do inside the it..do..end block works with the context
of the TitlesController.

So, even if I do this:

   it "Authenticated user must see Titles index" do
     post :login, :controller => :users, :login => "m
<mailto:[email protected]>[email protected]", :password => "Test123"
     get :index

or

   it "Authenticated user must see Titles index" do
     post "http://localhost:3000/login";, :login => "n
<mailto:[email protected]>[email protected]", :password => "Test123"
     get :index


the post directives pretty much get garbled thinking that the login post
is for the TitlesController:

      0001 Authenticated user must see Titles index
            ERROR
         No route matches {:login=>"[email protected]",
:password=>"Test123", :controller=>"titles",
:action=>"http://localhost:3000/login <http://localhost:3000/login>"}


So, what's the best way to get the user authenticated within a specific
controller test?

I know I can do this:

   it "Authenticated user must see Titles index" do
     session = ActionDispatch::Integration::Session.new(Rails.application)
     session.post ('http://localhost:3000/login'), :login =>
"[email protected]", :password => "Test123"
     session.get('http://localhost:3000/titles')
     titles_html = session.response.body
     assert(titles_html ... )
   end


But, is building my own session in each test the only way to circumvent
the assumed context of the TitlesController for a login?

Many thanks,
Tim




--
You received this message because you are subscribed to the Google
Groups "Hobo Users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



--
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre

--
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to