You should not stub the authentication method in a story. The story  
should test the whole application framework, that way your story might  
look like this:

Given a user from company x
When logging in
And requesting some page
Then the application should do all the stuff it should

In the given step you set your host, user name and password and you  
create that user.
In the when steps you make the login request and then you can start  
doing the stuff you really want to test here as you'll have the  
session you want at that moment.


Regards
Ivo Dancet

Op 6-mrt-08, om 16:12 heeft Bastien het volgende geschreven:

> Thanks David, this works just fine. I would rather do some stubbing
> there if it's possible though. I tried :
>
> ApplicationController.stub!
> (:user_authentication_required).and_return(true)
>
> (which is the filter called before each action that checks whether the
> user is logged in or not)
> But it doesn't work. When I do this  :
>
> class ApplicationController
>   def user_authentication_required
>      return true
>   end
> end
>
> it works fine (but I find it quite dirty to redefine my method that
> way). Aren't this two solutions supposed to give me the same result ?
> Is something wrong with my stubbing ?
>
> On Mar 6, 3:33 pm, Ivo Dancet <[EMAIL PROTECTED]> wrote:
>> I think you can also use:
>>
>> post "/authentication/login",
>>  { :login => user_email,
>>   :password => password },
>>  :host => "company.example.com"
>>
>> Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven:
>>
>>
>>
>>> I've just begin using rspec stories, and i m encountering some
>>> problems. In my application i have different subdomains in which
>>> specific users can log in, for example an admin will go to
>>> admin.myapp.com/authenticate/login, and an user belonging to a
>>> specific company will log in company.myapp.com/authenticate/login,  
>>> and
>>> of course both have a different login process.
>>
>>> To perform some actions the user has to be logged in, and this is
>>> where the problem comes, how to test these actions ?
>>
>>> - Is there a way to set a user as logged in ? (that would definitely
>>> be very convenient)
>>
>>> So far I have tried to do the following :
>>
>>> post "/authenticate/login",
>>>  {:login => user_email,
>>>  :password => password }
>>
>>> but the problem is that it doesn't use the correct subdomain and the
>>> login, as expected in that case, fails, so how to define the correct
>>> subdomain ?
>>
>>> Thank you in advance for your help.
>>> _______________________________________________
>>> rspec-users mailing list
>>> [EMAIL PROTECTED]
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>> _______________________________________________
>> rspec-users mailing list
>> [EMAIL PROTECTED]://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to