Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Webrat and RESTful Authentication
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
GS  
View profile  
 More options May 18, 4:59 am
From: GS <gabe.sara...@gmail.com>
Date: Mon, 18 May 2009 01:59:38 -0700 (PDT)
Local: Mon, May 18 2009 4:59 am
Subject: Webrat and RESTful Authentication
How does Webrat work with the a session and/or cookie object?

I'm attempting to test that i can log in as a user and then travel to
a nested resource for that user...

the two applicable step definitions i've defined are:

Given /^I am (.+) (.+) and I am on the account_(.+) page$/ do |
first_name, last_name, route_frag|
  @current_account = Account.create!(:first_name =>
first_name, :last_name => last_name, :email =>
"te...@ttkb.net", :password => "tpass123", :title => "Ms.", :login =>
"te...@ttkb.net")
  visit new_session_path
  fill_in :email, @current_account.email
  fill_in :password, @current_account.password
  click_button 'Adult Login'
  s = "/accounts/" + @current_account.id.to_s + "/#{route_frag}"
  visit s
end

Given /^I am (.+) (.+) and I am on the new_account_(.+) page$/ do |
first_name, last_name, route_frag|
  @current_account = Account.create!(:first_name =>
first_name, :last_name => last_name, :email =>
"te...@ttkb.net", :password => "tpass123", :title => "Ms.", :login =>
"te...@ttkb.net")
  visit new_session_path
  fill_in :email, @current_account.email
  fill_in :password, @current_account.password
  check :remember_me
  click_button 'Adult Login'
  s = "/accounts/" + @current_account.id.to_s + "/#{route_frag}/new"
  visit s
end

But when I am not clear how Webrat handles logins, or if it persists a
session between scenarios...

when i try to use these step definitions i get:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.has_role? (NoMethodError)

which is basically throwing an error when it comes across the variable
"current_account" which gets defined as AuthenticatedSystem.rb:
    def current_account
      @current_account ||= (login_from_session || login_from_cookie)
unless @current_account == false
    end

What am I doing wrong?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
GS  
View profile  
 More options May 18, 7:36 pm
From: GS <gabe.sara...@gmail.com>
Date: Mon, 18 May 2009 16:36:25 -0700 (PDT)
Local: Mon, May 18 2009 7:36 pm
Subject: Re: Webrat and RESTful Authentication
if my original post was too much,  maybe..just more simply,

how do I simulate going to a route that requires getting the id of the
current user?
and is that enough if the user is logged in?
if i create a user in a webrat step, for how long is that user around
in my test db? the current scenario? the whole feature?

any answers or pointing me to references would be appreciated.

-gabe

On May 18, 3:59 am, GS <gabe.sara...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
doug livesey  
View profile  
 More options May 18, 7:46 pm
From: doug livesey <biot...@gmail.com>
Date: Tue, 19 May 2009 00:46:07 +0100
Local: Mon, May 18 2009 7:46 pm
Subject: Re: [webrat] Re: Webrat and RESTful Authentication

This is one that I've been struggling with as well.
Initially, I tried (with some help, I should add) adding stubs to my
features, but they were not clearing down properly, so for now I'm having to
run a step called something like 'Given I am logged in as "superuser"' which
actually goes through the login procedure. Worse, I've had to add
rudimentary login functionality to apps that didn't have it (with a plugin,
so not too bad) to simulate this.
So, sorry, I'm not giving any help but sympathy, really, and adding my voice
to the appeal for guidance on this issue.
   Doug.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Wynne  
View profile  
 More options May 19, 3:55 am
From: Matt Wynne <m...@mattwynne.net>
Date: Tue, 19 May 2009 08:55:06 +0100
Local: Tues, May 19 2009 3:55 am
Subject: Re: [webrat] Re: Webrat and RESTful Authentication

On 19 May 2009, at 00:36, GS wrote:

> if my original post was too much,  maybe..just more simply,

> how do I simulate going to a route that requires getting the id of the
> current user?
> and is that enough if the user is logged in?
> if i create a user in a webrat step, for how long is that user around
> in my test db? the current scenario? the whole feature?

You're talking about a Cucumber scenario, right? In that case, the  
session will be around for the life of the scenario. This is a really  
nice thing, as you can assume that one scenario doesn't leak state  
into another.

At songkick, we have hundreds of scenarios that run in a feature with  
the following step at the top:

   Background:
     Given I am logged into my account

That step is implemented like this:

   Given /^I am logged into my account$/ do
     @me = Factory(:user, :password => 'valid_password')
     visit new_session_path
     fill_in :username, @me.username
     fill_in :password, 'valid_password'
     click_button 'Log in'
   end

We like this solution, as there's absolutely no coupling to any  
implementation of sessions within the code, and we get the added  
benefit of knowing that we're testing the path a real user will use to  
log into the site.

The @me instance variable lives for as long as the current scenario,  
no longer. It isn't a reference to the actual instance of User that  
the controllers will use, but a representation of the same object in  
the testing space, which I can use as a useful reference to that user.

Make sense?

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
GS  
View profile  
 More options May 19, 11:27 am
From: GS <gabe.sara...@gmail.com>
Date: Tue, 19 May 2009 08:27:27 -0700 (PDT)
Local: Tues, May 19 2009 11:27 am
Subject: Re: Webrat and RESTful Authentication
so then, am i correct in thinking that within a cucumber scenario a
step such as,

Given I am at MY "some_nested_resource" page

can be implemented as:

Given /^I am at MY "(.+)" page$/ do |route_fragment|
  full_path = "/users/" + @me.id.to_s + "/#{route_fragment}"
  visit full_path
end

and thank you!

On May 19, 2:55 am, Matt Wynne <m...@mattwynne.net> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
doug livesey  
View profile  
 More options May 19, 11:32 am
From: doug livesey <biot...@gmail.com>
Date: Tue, 19 May 2009 16:32:42 +0100
Local: Tues, May 19 2009 11:32 am
Subject: Re: [webrat] Re: Webrat and RESTful Authentication

> Make sense?

Yes, and that's the way I've ended up going, too.
However, due to some session sharing, not all my apps have logins, so this
didn't work for them.
When I couldn't get stubbing the authorise method in my application
controller to work, I have ended up extracting login functionality into a
plugin to include in those apps so that I can use something similar to the
method you propose.
& it works, so that's fine.
Would be nice to just stub the authorise method, though.
   Doug.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google