[rspec-users] step definitons to check login

Zach Dennis zach.dennis at gmail.com
Tue Dec 16 20:40:58 EST 2008


On Tue, Dec 16, 2008 at 8:30 PM, Zach Dennis <zach.dennis at gmail.com> wrote:
> On Tue, Dec 16, 2008 at 7:48 PM, Andrew Premdas <apremdas at gmail.com> wrote:
>> So I can confirm that I'm logged in, that the user is who I say he is, etc.
>>
>> e.g
>>
>> Then /^I should be logged in$/ do
>>   controller.logged_in?.should be_true
>> end
>>
>> makes sense?
>
> I know why you're doing it, but I just want to know *why* you're doing
> it? Can you not tell through the application itself that someone is
> logged in, logged out, and verify their identity without having to
> expose the internals?

I'm not trying to be pedantic or facetious. I'm really trying to
explore the use case,


>
>
>>
>> 2008/12/16 Zach Dennis <zach.dennis at gmail.com>
>>>
>>> On Tue, Dec 16, 2008 at 6:47 PM, Andrew Premdas <apremdas at gmail.com>
>>> wrote:
>>> > Doing this for Restful-Authentication I add the following in
>>> > features/support/env.rb
>>> >
>>> > # Make visible for testing
>>> > ApplicationController.send(:public, :logged_in?, :current_user,
>>> > :authorized?)
>>>
>>> Why do you need these available for cucumber scenarios?
>>>
>>>
>>> >
>>> > Hopefully something similar will work with Authlogic
>>> >
>>> > Andrew
>>> >
>>> > 2008/12/16 James Byrne <lists at ruby-forum.com>
>>> >>
>>> >> I am working with the authlogic gem and trying to create a simple login
>>> >> test from cucumber features. The feature statement is:
>>> >>
>>> >> Given the user is not logged in
>>> >>
>>> >> The step definition for this is confounding me.  In the
>>> >> application_controller the authlogic tutorial recommends the following:
>>> >>
>>> >> private
>>> >>    def require_user
>>> >>      unless current_user
>>> >>        store_location
>>> >>        flash[:notice] = "You must sign in to access this page"
>>> >>        redirect_to new_user_session_url
>>> >>        return false
>>> >>      end
>>> >>    end
>>> >>
>>> >>    def require_no_user
>>> >>      if current_user
>>> >>        store_location
>>> >>        flash[:notice] = "You must be logged out to access this page"
>>> >>        redirect_to account_url
>>> >>        return false
>>> >>      end
>>> >>
>>> >> As these are private methods they are not directly accessible from the
>>> >> step definitions and I am at a loss as to how to proceed.  I could
>>> >> augment the application controller with a public user_authenticated
>>> >> method:
>>> >>
>>> >>  def user_authenticated
>>> >>     return true if current_user
>>> >>     false
>>> >>  end
>>> >>
>>> >> But it seems wrong to alter the application code for no other purpose
>>> >> than to ease testing.  Is there another approach that I should be
>>> >> using?
>>> >> --
>>> >> Posted via http://www.ruby-forum.com/.
>>> >> _______________________________________________
>>> >> rspec-users mailing list
>>> >> rspec-users at rubyforge.org
>>> >> http://rubyforge.org/mailman/listinfo/rspec-users
>>> >
>>> >
>>> > _______________________________________________
>>> > rspec-users mailing list
>>> > rspec-users at rubyforge.org
>>> > http://rubyforge.org/mailman/listinfo/rspec-users
>>> >
>>>
>>>
>>>
>>> --
>>> Zach Dennis
>>> http://www.continuousthinking.com
>>> http://www.mutuallyhuman.com
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>>
>
>
>
> --
> Zach Dennis
> http://www.continuousthinking.com
> http://www.mutuallyhuman.com
>



-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com


More information about the rspec-users mailing list