Forum: Ruby on Rails Salted Hash Login Generator problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F779209a7f02c754eda7b505898347f9?d=identicon&s=25 Rob Balfour (robtotheb)
on 2006-04-13 16:33
Im trying to install salted and get errors when running the rake test...

/usr/bin/ruby1.8 -Ilib:test
"/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader .rb"
"test/unit/localization_test.rb" "test/unit/user_test.rb"
Loaded suite
/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader
Started
........F....E
Finished in 0.108794 seconds.

  1) Failure:
test_auth(UserTest) [./test/unit/user_test.rb:9]:
<nil> expected but was
<#<User:0xb75d7210
 @attributes=
  {"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889",
   "delete_after"=>nil,
   "security_token"=>nil,
   "role"=>nil,
   "lastname"=>nil,
   "firstname"=>nil,
   "id"=>"1000001",
   "deleted"=>"0",
   "token_expiry"=>nil,
   "verified"=>"1",
   "salted_password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92",
   "login"=>"bob",
   "email"=>"bob@test.com"}>>.

  2) Error:
test_passwordchange(UserTest):
NoMethodError: You have a nil object when you didn't expect it!
The error occured while evaluating nil.change_password
    ./test/unit/user_test.rb:17:in `test_passwordchange'

14 tests, 27 assertions, 1 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 -Ilib:test
"/usr/lib/ruby...]
41cc103c665b417e70a7c9d558fccf86?d=identicon&s=25 John Quinley (johnquinley)
on 2006-04-13 17:01
Hi Rob,

I just encountered the exact same problem. The test code that is failing
is this:
assert_equal @bob, User.authenticate("bob", "atest")

But I could not find anywhere where @bob was being set. The only thing I
could think of was that
perhaps the author used some sort of extension that would generate these
objects from the fixtures. There is another place where an @longbob is
assumed to exist as well.

I haven't had a chance to track this down any farther, so I changed the
line to this:
assert_not_nil User.authenticate("bob", "atest")

to get past the first error. Then I went to bed, leaving the other error
intact while I did a little more research on this. Does anyone else know
anything about this? It woud look like the author was able to get an
@bob and @longbob generated simply from the fixture. Is there a way to
do this?

John Quinley

Rob Balfour wrote:
> Im trying to install salted and get errors when running the rake test...
>
> /usr/bin/ruby1.8 -Ilib:test
> "/usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader .rb"
> "test/unit/localization_test.rb" "test/unit/user_test.rb"
> Loaded suite
> /usr/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake/rake_test_loader
> Started
> ........F....E
> Finished in 0.108794 seconds.
>
>   1) Failure:
> test_auth(UserTest) [./test/unit/user_test.rb:9]:
> <nil> expected but was
> <#<User:0xb75d7210
>  @attributes=
>   {"salt"=>"7f8b036f9b647d46d22abdbfc8113f44a88f9889",
>    "delete_after"=>nil,
>    "security_token"=>nil,
>    "role"=>nil,
>    "lastname"=>nil,
>    "firstname"=>nil,
>    "id"=>"1000001",
>    "deleted"=>"0",
>    "token_expiry"=>nil,
>    "verified"=>"1",
>    "salted_password"=>"ef94c16f6c124a4e84cc215c164767bfa25f6e92",
>    "login"=>"bob",
>    "email"=>"bob@test.com"}>>.
>
>   2) Error:
> test_passwordchange(UserTest):
> NoMethodError: You have a nil object when you didn't expect it!
> The error occured while evaluating nil.change_password
>     ./test/unit/user_test.rb:17:in `test_passwordchange'
>
> 14 tests, 27 assertions, 1 failures, 1 errors
> rake aborted!
> Command failed with status (1): [/usr/bin/ruby1.8 -Ilib:test
> "/usr/lib/ruby...]
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-04-13 19:02
(Received via mailing list)
John Quinley wrote:

> I just encountered the exact same problem. The test code that is failing
> is this:
> assert_equal @bob, User.authenticate("bob", "atest")
>
> But I could not find anywhere where @bob was being set. The only thing I
> could think of was that
> perhaps the author used some sort of extension that would generate these
> objects from the fixtures. There is another place where an @longbob is
> assumed to exist as well.

To my knowledge these tests have never worked. A couple of the unit
tests fail out of the box, but all the functional tests fail. Perhaps
they worked on Rails 0.5 or something, I don't know. I first looked at
them at around Rails 0.12.

On the plus side, even though the tests fail, the code itself seems to
work.

When I was looking at this a few months ago I was able to make both the
unit and functional tests pass with some effort and to improve the
coverage of the tests. At the time I was new to ruby and rails, so I
ended up learning quite a bit in this exercise, but if I knew then what
I know now, I would have moved to acts_as_authenticated weeks earlier.

Almost everything in rails just works or is within a couple of
configuration steps from working. That is not the case for these tests.

--

Ray
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2006-04-13 22:12
John Quinley wrote:
> Hi Rob,
>
> I just encountered the exact same problem. The test code that is failing
> is this:
> assert_equal @bob, User.authenticate("bob", "atest")
>
...
>> 14 tests, 27 assertions, 1 failures, 1 errors
>> rake aborted!
>> Command failed with status (1): [/usr/bin/ruby1.8 -Ilib:test
>> "/usr/lib/ruby...]

If I remember right it has to do with some changes to the Rails test
code, about the way it loads fixtures.  I think it was a change from
0.14 to 1.0 but I don't recall exactly.

I'll look into it to see what I did, but I know I went into the tests on
my installation of SHLG and did some fiddling to get them up to date,
for my own satisfaction.

Jeff Coleman
This topic is locked and can not be replied to.