# where is wrong with contoller test?

**URL:** <https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204>\
**Category:** rubyonrails-talk\
**Created:** [September 16, 2007, 12:27am UTC](https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204 "2007-09-16T00:27:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OnRails](https://avatars.discourse-cdn.com/v4/letter/o/51bf81/32.png) [@OnRails](https://discuss.rubyonrails.org/u/OnRails)\
**Post date:** [September 16, 2007, 12:27am UTC](https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204/1 "2007-09-16T00:27:14Z")

</div>

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

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

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

when I run this test, There always said, &nbsp;&nbsp;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:** ![Bob\_Showalter](https://avatars.discourse-cdn.com/v4/letter/b/c57346/32.png) [@Bob\_Showalter](https://discuss.rubyonrails.org/u/Bob_Showalter)\
**Post date:** [September 16, 2007, 1:42am UTC](https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204/2 "2007-09-16T01:42:34Z")

</div>

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

Your action method needs to be defined without arguments:

&nbsp;&nbsp;&nbsp;def send\_welcome\_message &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;person = params[:person] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;&nbsp;end

---

<div class="post-metadata">

**Author:** ![OnRails](https://avatars.discourse-cdn.com/v4/letter/o/51bf81/32.png) [@OnRails](https://discuss.rubyonrails.org/u/OnRails)\
**Post date:** [September 16, 2007, 2:23am UTC](https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204/3 "2007-09-16T02:23:59Z")

</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://avatars.discourse-cdn.com/v4/letter/o/51bf81/32.png) [@OnRails](https://discuss.rubyonrails.org/u/OnRails)\
**Post date:** [September 17, 2007, 6:03pm UTC](https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204/4 "2007-09-17T18:03:20Z")

</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:** ![Ryan1](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Ryan1](https://discuss.rubyonrails.org/u/Ryan1)\
**Post date:** [September 18, 2007, 8:11pm UTC](https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204/5 "2007-09-18T20:11:17Z")

</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:** ![Ryan1](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Ryan1](https://discuss.rubyonrails.org/u/Ryan1)\
**Post date:** [September 18, 2007, 8:13pm UTC](https://discuss.rubyonrails.org/t/where-is-wrong-with-contoller-test/18204/6 "2007-09-18T20:13:00Z")

</div>

…\*you’re doing things…

Stupid homophones.
