HighDots Forums  

testing - how do i log in different users and have testsdone?

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss testing - how do i log in different users and have testsdone? in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ct9a
 
Posts: n/a

Default testing - how do i log in different users and have testsdone? - 09-18-2009 , 03:45 AM






hi all,

I googled a bit and tried looking up several rails books to no
success.

I have a users.yml file which contains two users: one with admin
priviledges and one without

My application_controller.rb has a method which checks if a given
user has admin priviledges or not.

I have 3 controllers: Users, UserSessions and Post.
I am using Authlogic.


For my Post functional tests, I would like to know how do I log each
user fixture in and test as accordingly (ie some parts of the site
should not be accessible by non-admin users).


Thank you.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #2  
Old   
ashchan
 
Posts: n/a

Default Re: testing - how do i log in different users and have testsdone? - 09-18-2009 , 10:57 AM






Why not try the famous restful_authentication plugin? Then in your
test_helper.rb add this line:

include AuthenticatedTestSystem

Now you'll have a login_as method, which will do what you need.

--
James Chen
http://ashchan.com

On Sep 18, 3:45*pm, ct9a <anexi... (AT) gmail (DOT) com> wrote:
Quote:
hi all,

*I googled a bit and tried looking up several rails books to no
success.

*I have a users.yml file which contains two users: one with admin
priviledges and one without

*My application_controller.rb has a method which checks if a given
user has admin priviledges or not.

*I have 3 controllers: Users, UserSessions and Post.
*I am using Authlogic.

*For my Post functional tests, I would like to know how do I log each
user fixture in and test as accordingly (ie some parts of the site
should not be accessible by non-admin users).

*Thank you.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #3  
Old   
Colin Law
 
Posts: n/a

Default Re: testing - how do i log in different users and have testsdone? - 09-18-2009 , 11:10 AM



2009/9/18 ct9a <anexiole (AT) gmail (DOT) com>:
Quote:
hi all,

Â*I googled a bit and tried looking up several rails books to no
success.

Â*I have a users.yml file which contains two users: one with admin
priviledges and one without

Â*My application_controller.rb has a method which checks if a given
user has admin priviledges or not.

Â*I have 3 controllers: Users, UserSessions and Post.
Â*I am using Authlogic.


Â*For my Post functional tests, I would like to know how do I log each
user fixture in and test as accordingly (ie some parts of the site
should not be accessible by non-admin users).


Â*Thank you.
I use restful authentication rather than authlogic but I imagine the
principle is the same in that you need to setup the session for the
test as if the user was logged in. The testing rails guide at
http://guides.rubyonrails.org/testing.html has a bit on this. For
example one of my tests has:
get :show, {:id => some_id}, { :user_id => users(:colin).id }
which sets user_id in the session to the appropriate value as if I
were logged in.

In fact I think there is a alternative way of setting the session in
the test setup, so it does not need to be added to every action, but I
forget what it is at the moment.

Colin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #4  
Old   
ct9a
 
Posts: n/a

Default Re: testing - how do i log in different users and have testsdone? - 11-04-2009 , 11:25 PM



anyone who's using Authlogic and got a solution for creating tests
(that can auto login)?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #5  
Old   
Scott Johnson
 
Posts: n/a

Default Re: testing - how do i log in different users and have testsdone? - 11-05-2009 , 01:17 PM



I started with this blog post:

http://iain.nl/2008/11/authlogic-is-awesome/




On Nov 4, 8:25 pm, ct9a <anexi... (AT) gmail (DOT) com> wrote:
Quote:
anyone who's using Authlogic and got a solution for creating tests
(that can auto login)?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #6  
Old   
Marnen Laibow-Koser
 
Posts: n/a

Default Re: testing - how do i log in different users and have tests - 11-05-2009 , 01:29 PM



ct9a wrote:
Quote:
anyone who's using Authlogic and got a solution for creating tests
(that can auto login)?
Check out the specs and Cucumber features for Quorum (
http://github.com/marnen/quorum2 ).

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen (AT) marnen (DOT) org
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.