# Where is wrong with contoller test?

**URL:** <https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615>\
**Category:** Rails\
**Created:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615 "2007-09-17T13:23:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615/1 "2007-09-17T13:23:02Z")

</div>

Hi, everybody!  
I got a strange question when I did a controller test as below  
On controller.rb:

def send\_welcome\_message(person)  
some codes;  
end

the controller\_test.rb:  
def test\_send\_welcome\_message  
post :send\_welcome\_message, :person=\>{:id=\>‘2’, :name=\>‘somebody’}  
assert\_response :success  
end

when I run this test, There always said,

1. Error:  
test\_send\_welcome\_message(TestControllerTest):  
ArgumentError: wrong number of arguments (0 for 1)  
I know there maybe params are set wrong,  
but how can I fix it out? please help, Thanks!

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615/2 "2007-09-17T13:23:27Z")

</div>

On 9/15/07, OnRails [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi, everybody!  
> I got a strange question when I did a controller test as below  
> On controller.rb:
> 
> def send\_welcome\_message(person)  
> some codes;  
> end

Your action method needs to be defined without arguments:

def send\_welcome\_message  
person = params[:person]  
…  
end

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 17, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615/3 "2007-09-17T13:23:58Z")

</div>

Thank you, Bob!  
I depended on your suggestion to do that, It’s OK…  
Now, I want to know why if I use  
def send\_welcome\_message(person)  
this way, I can’t get it?  
anyone can help me? Thanks!

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 18, 2007, 10:12pm UTC](https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615/4 "2007-09-18T22:12:51Z")

</div>

I’m not understanding what you’re saying very well, but I think the  
issue  
boils down to the fact that you can’t pass arguments to a controller  
method  
that way. You couldnt call "  
[http://localhost:3000/controller/send\_welcome\_message(person)](http://localhost:3000/controller/send_welcome_message(person))" from the  
URI  
box. You would post to "  
[http://localhost:3000/controller/send\_welcome\_message](http://localhost:3000/controller/send_welcome_message)" with :person  
parameters in the HTTP request.

On a relate note, I would expect a method called send\_welcome\_message to  
be  
a helper function that maybe set flash[:notice] and redirected. I  
wouldn’t  
expect it to be a controller method. Your issue may be that your doing  
things in the wrong places and confusing yourself.

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 17, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615/5 "2007-09-17T20:05:10Z")

</div>

Hi, everybody.  
I think that is a function like “def send\_welcome\_message(person)”,  
and that is a model method like “def send\_welcome\_message”,  
so when you defined “def send\_welcome\_message(person)”, you can call  
it in your method, then you don’t need to test this function.  
This idea is right or not? Could somebody tell me…

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 18, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/where-is-wrong-with-contoller-test/114615/6 "2007-09-18T22:13:51Z")

</div>

…\*you’re doing things…

Stupid homophones.
