# Noob test Q

**URL:** <https://www.ruby-forum.com/t/noob-test-q/164012>\
**Category:** Rails\
**Created:** [March 26, 2009, 10:13pm UTC](https://www.ruby-forum.com/t/noob-test-q/164012 "2009-03-26T22:13:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 26, 2009, 10:13pm UTC](https://www.ruby-forum.com/t/noob-test-q/164012/1 "2009-03-26T22:13:53Z")

</div>

I have been working with restful\_authentication. I have made some  
changes to it and now I’m trying to get all the default tests that  
came with the plugin to pass.

Here’s one of the tests that error out:

def test\_should\_require\_login\_on\_signup  
assert\_no\_difference ‘User.count’ do  
create\_user(:login =\> nil)  
assert assigns(:user).errors.on(:login)  
assert\_response :success  
end  
end

This is the error:  
NoMethodError: You have a nil object when you didn’t expect it!  
You might have expected an instance of ActiveRecord::Base.  
The error occurred while evaluating nil.errors

When using running debugger and checking in on assigns(:user) it  
returns nil, so I assume this is the trouble.

Finally here’s my question, what is “create\_user” doing? Is it  
creating a new User based upon the users.yml fixture that the test  
suit is loading, or is it something else? I couldn’t find reference  
for this “dynamic??” method anywhere.

Thanks

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 27, 2009, 6:04pm UTC](https://www.ruby-forum.com/t/noob-test-q/164012/2 "2009-03-27T18:04:34Z")

</div>

Any thoughts on this?

Basically, I just need to know what “create\_user” is doing? Is it  
creating a new User based upon the users.yml fixture that the test  
suit is loading, or is it something else? I couldn’t find reference  
for this “dynamic??” method anywhere.

def test\_should\_require\_login\_on\_signup  
assert\_no\_difference ‘User.count’ do  
create\_user(:login =\> nil)  
assert assigns(:user).errors.on(:login)  
assert\_response :success  
end  
end

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 27, 2009, 6:16pm UTC](https://www.ruby-forum.com/t/noob-test-q/164012/3 "2009-03-27T18:16:20Z")

</div>

If you look down the end of the file with that code in you will find the  
definition of create\_user. At least in my version anyway. I found it  
by a  
global search, but I realised when it found it that I should have looked  
in  
that file first.

2009/3/27 elliottg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 27, 2009, 7:36pm UTC](https://www.ruby-forum.com/t/noob-test-q/164012/4 "2009-03-27T19:36:42Z")

</div>

It looks like I have a “Filter chain halted” error going on that is  
not allowing the user to be created.

Thanks for all the help.

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 27, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/noob-test-q/164012/5 "2009-03-27T21:33:25Z")

</div>

I can’t help with this as I have tweaked the create code so it is  
non-standard. Is there a before\_filter in UsersController, if so then  
it  
may be failing in there.

2009/3/27 elliottg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 27, 2009, 6:28pm UTC](https://www.ruby-forum.com/t/noob-test-q/164012/6 "2009-03-27T18:28:04Z")

</div>

Doh… I just found it, right after my last post.

Thanks for getting back to me.

I am assuming that somehow @user is being returned or something?  
Because, assigns(:user) is being called on the next line??

Is that the case, and further any ideas why its coming up Nil? Testing  
in script/console test shows that creating a new User works fine and I  
know the fixture data is in the users table as it should be?

Thanks a ton

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 29, 2009, 3:52am UTC](https://www.ruby-forum.com/t/noob-test-q/164012/7 "2009-03-29T03:52:34Z")

</div>

A before\_filter redirect in role\_reqirement\_system#access\_denied is  
halting things before the create action of the user controller could  
be called. Not really sure how test around this as the redirect is a  
key part of how r\_r works. Any thoughts on getting around situations  
like this?

Thanks

---

<div class="post-metadata">

**Author:** ![elliottg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b77776/32.png) [@elliottg](https://www.ruby-forum.com/u/elliottg)\
**Post date:** [March 29, 2009, 10:44am UTC](https://www.ruby-forum.com/t/noob-test-q/164012/8 "2009-03-29T10:44:05Z")

</div>

I don’t know about role\_requirement\_system I am afraid, so only  
guesswork  
follows. If I understand correctly the problem is that the restful  
authentication tests are failing because the role requirement conditions  
are  
not satisfied by the test conditions. Possibly you have to adjust the  
test  
fixtures and possibly test code so that the users in the fixtures have  
appropriate roles to satisfy the tests.

2009/3/29 elliottg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
