# Restful-Authentication Rspec Failure Rails 2.0.2

**URL:** <https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603>\
**Category:** Rails\
**Created:** [December 30, 2007, 10:28pm UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603 "2007-12-30T22:28:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 30, 2007, 10:28pm UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603/1 "2007-12-30T22:28:59Z")

</div>

I am trying the Restful-Authentication (latest version, downloaded  
today) and upon running the generator, doing the migration, prepping  
the test system and putting the resources in routes.rb I get a Rspec  
test failure:

‘SessionsController logins and redirects’ FAILED  
expected not nil, got nil

routes.rb has:  
map.resources :users  
map.resources :sessions

nothing else was changed or done. there is only one other controller/  
model in the system and rspec tested it with no errors.

Is this a known bug? Should I just be using something else? I have  
used this several times on 1.2.6 with no problem.

Thanks

Don F.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 31, 2007, 2:14am UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603/2 "2007-12-31T02:14:47Z")

</div>

Check your routes again.

You are showing:

> routes.rb has:  
> map.resources :users  
> map.resources :sessions

It should be:  
map.resources :users  
map.resource :session

Note the singular form for session. Each user can only have one  
session at a time so it’s singular.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 31, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603/3 "2007-12-31T21:58:07Z")

</div>

I tried that before and just did. Same error.

code around the failure is:  
it ‘logins and redirects’ do  
post :create, :login =\> ‘quentin’, :password =\> ‘test’  
session[:user].should\_not be\_nil # -\> Error is on this line  
response.should be\_redirect  
end

Error is:  
1)  
‘SessionsController logins and redirects’ FAILED  
expected not nil, got nil  
/Users/dhf/NetBeansProjects/snrbad/spec/controllers/  
sessions\_controller\_spec.rb:12:

Finished in 0.145385 seconds

9 examples, 1 failure

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 1, 2008, 12:18am UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603/4 "2008-01-01T00:18:22Z")

</div>

> It’s only a restful\_auth issue if it does this on a brand new app.

It does this to me on a brand new app.

> Please do send a patch if you uncover a bug.

— functional\_spec.rb.orig 2007-12-31 17:33:13.000000000 -0500  
+++ functional\_spec.rb 2007-12-31 18:13:20.000000000 -0500  
@@ -9,20 +9,20 @@

it ‘logins and redirects’ do  
post :create, :login =\> ‘quentin’, :password =\> ‘test’

- session[:\<%= file\_name %\>].should\_not be\_nil

- session[:\<%= file\_name %\>\_id].should\_not be\_nil  
response.should be\_redirect  
end

it ‘fails login and does not redirect’ do  
post :create, :login =\> ‘quentin’, :password =\> ‘bad password’

- session[:\<%= file\_name %\>].should be\_nil

- session[:\<%= file\_name %\>\_id].should be\_nil  
response.should be\_success  
end

it ‘logs out’ do  
login\_as :quentin  
get :destroy

- session[:\<%= file\_name %\>].should be\_nil

- session[:\<%= file\_name %\>\_id].should be\_nil  
response.should be\_redirect  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 31, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603/5 "2007-12-31T23:14:41Z")

</div>

On Dec 31, 2007 12:57 PM, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Error is:  
> 1)  
> ‘SessionsController logins and redirects’ FAILED  
> expected not nil, got nil  
> /Users/dhf/NetBeansProjects/snrbad/spec/controllers/  
> sessions\_controller\_spec.rb:12:
> 
> Finished in 0.145385 seconds
> 
> 9 examples, 1 failure

Changes in your app can cause these test failures. I very recently  
used the rspec version when it was committed and had no problems.  
It’s only a restful\_auth issue if it does this on a brand new app.  
Please do send a patch if you uncover a bug.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 1, 2008, 6:36am UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603/6 "2008-01-01T06:36:13Z")

</div>

Thanks. I thought I had tried everything before I submitted the  
problem. I even had done but did not mention what Rick had recommended  
and it failed also.

When will then plugin be updated so I do not have to make the changes  
on each project?

Don F.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 1, 2008, 3:06am UTC](https://www.ruby-forum.com/t/restful-authentication-rspec-failure-rails-2-0-2/124603/7 "2008-01-01T03:06:32Z")

</div>

On Dec 31, 2007 3:17 PM, Bryan L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @@ -9,20 +9,20 @@
> 
> - session[:\<%= file\_name %\>].should be\_nil  
> end  
> Oh awesome, someone gets reprimanded for not testing before committing  
> 🙂 Thanks.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
