# Restful Authentication fails its tests

**URL:** <https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210>\
**Category:** Rails\
**Created:** [November 25, 2006, 3:14am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210 "2006-11-25T03:14:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 3:14am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/1 "2006-11-25T03:14:01Z")

</div>

Tonight I installed the ‘restful authentication’ plugin. The first thing  
I always do, after following the ‘setup’ instructions from the  
generator, is run the plugin’s tests. Plus, I copied the proper  
‘include’ line from the session\_controller.rb to  
application\_controller.rb.

The plugin failed several tests on its session\_controller. Has anyone  
else seen this?

cremes$ ruby sessions\_controller\_test.rb  
Loaded suite sessions\_controller\_test  
Started  
.FFF…  
Finished in 0.198387 seconds.

1. Failure:  
test\_should\_fail\_cookie\_login(SessionsControllerTest)  
[sessions\_controller\_test.rb:74]:  
 is not true.

2. Failure:  
test\_should\_fail\_expired\_cookie\_login(SessionsControllerTest)  
[sessions\_controller\_test.rb:67]:  
 is not true.

3. Failure:  
test\_should\_fail\_login\_and\_not\_redirect(SessionsControllerTest)  
[/Users/cremes/Documents/development/ruby/library/config/…/vendor/rails/actionpack/lib/action\_controller/assertions/response\_assertions.rb:26:in  
`assert_response' /Users/cremes/Documents/development/ruby/library/config/../vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:18:in`assert\_response’  
sessions\_controller\_test.rb:29:in  
`test\_should\_fail\_login\_and\_not\_redirect’]:  
Expected response to be a \<:success\>, but was \<302\>

9 tests, 12 assertions, 3 failures, 0 errors

I confirmed that it is allowing logins where the password is clearly  
incorrect.

Also, I ran ‘rake tmp:clear’ to clear out all session files and other  
cruft.

This is on OSX 10.4.8 with Ruby 1.8.4 running Rails 1.2RC1 and the  
latest restful authentication plugin from its home repository.

cr

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 3:40am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/2 "2006-11-25T03:40:06Z")

</div>

That’s funny. I just did the same thing.

It seems to me that logged\_in is returning the symbol :false instead of  
false. On my system, :false evaluates to true.

treybean$ irb  
irb(main):001:0\> a = :false  
=\> :false  
irb(main):002:0\> a  
=\> :false  
irb(main):003:0\> if a  
irb(main):004:1\> puts “a must be true”  
irb(main):005:1\> else  
irb(main):006:1\* puts “a must be false”  
irb(main):007:1\> end  
a must be true  
=\> nil  
irb(main):008:0\>

I wonder if this is a recent change, or possibly something that might  
be fixed my upgrading to Ruby 1.8.5

I’ll post if I figure anything else out.

Trey

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 3:50am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/3 "2006-11-25T03:50:07Z")

</div>

On Friday, November 24, 2006, at 08:40PM, “removed\_email\_address@domain.invalid”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> That’s funny. I just did the same thing.
> 
> It seems to me that logged\_in is returning the symbol :false instead of  
> false. On my system, :false evaluates to true.

Yes, I just tracked this down myself. All over authenticated\_system.rb  
the author uses the symbol :false when I think he means the value false.

For example:

```
def logged_in?
  current_user ||= :false
end

```

Interestingly, changing every occurrence of :false to false doesn’t  
magically make all the tests complete successfully. Tests that used to  
work now fail and the tests that failed now work. 🙂

> I wonder if this is a recent change, or possibly something that might  
> be fixed my upgrading to Ruby 1.8.5

I hope not!

> > ```
> > [/Users/cremes/Documents/development/ruby/library/config/../vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:26:in `assert_response'
> > 
> > ```
> > 
> > This is on OSX 10.4.8 with Ruby 1.8.4 running Rails 1.2RC1 and the latest restful authentication plugin from its home repository.  
> > EOM

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 3:56am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/4 "2006-11-25T03:56:09Z")

</div>

I definitely think Rick meant to use the symbol. After all, he even  
uses this as a condition in current\_user=. I looked at the svn log and  
see that he made these changes yesterday. Regression maybe? My bet is  
still on the version of ruby.

Trey

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 4:14am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/5 "2006-11-25T04:14:11Z")

</div>

On Nov 24, 2006, at 8:52 PM, removed\_email\_address@domain.invalid wrote:

> I definitely think Rick meant to use the symbol. After all, he even  
> uses this as a condition in current\_user=. I looked at the svn log  
> and  
> see that he made these changes yesterday. Regression maybe? My  
> bet is  
> still on the version of ruby.

Any suggestions on a stable tag for restful\_authentication? I’d like  
to give a stable version of it a test drive.

cr

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 9:32am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/6 "2006-11-25T09:32:33Z")

</div>

I use :false, because if I used false or nil it would hit the db again  
after each hit. If someone wants to submit a patch with fixed tests,  
that’d be great. I’m using this code in 2 apps now and it works fine.  
I think there are some instances where it’s expecting current\_user to  
return nil/false. Just use logged\_in? instead.

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

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 3:43pm UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/7 "2006-11-25T15:43:09Z")

</div>

On Nov 25, 2006, at 2:47 AM, Rick O. wrote:

> Oh, apparently != is not the same as ||= . Silly mistake, it’s  
> fixed now.
> 
> [http://bs.techno-weenie.net/!revision/2508](http://bs.techno-weenie.net/!revision/2508)

Rev 2508 works nicely. All tests pass. Thanks for the quick fix.

cr

---

<div class="post-metadata">

**Author:** ![cremes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19b73/32.png) [@cremes](https://www.ruby-forum.com/u/cremes)\
**Post date:** [November 25, 2006, 9:52am UTC](https://www.ruby-forum.com/t/restful-authentication-fails-its-tests/77210/8 "2006-11-25T09:52:35Z")

</div>

On 11/25/06, Rick O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I use :false, because if I used false or nil it would hit the db again  
> after each hit. If someone wants to submit a patch with fixed tests,  
> that’d be great. I’m using this code in 2 apps now and it works fine.  
> I think there are some instances where it’s expecting current\_user to  
> return nil/false. Just use logged\_in? instead.

Oh, apparently != is not the same as ||= . Silly mistake, it’s fixed  
now.

[http://bs.techno-weenie.net/!revision/2508](http://bs.techno-weenie.net/!revision/2508)

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