where is wrong with contoller test?

O

OnRails Ruby

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
there 'person' is instance variables.

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!
 
M

Matthew Rudy

OnRails said:
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
there 'person' is instance variables.

Can I just check how you're using this method.
Is it a controller "action", as in, do you access it directly from a
url?
eg. /controller/send_welcome_message/1

Or is it just a convenience method?

If it is an action, then an action can only be called without an
argument
(it takes input from the http params, and inherits any instance
variables defined in before_filters)

you say "person" is an instance variable.
so it should look like this

def send_welcome_message
do the code involving @person
end

before_filter :get_person
def get_person
@person = Person.find(params[:id])
end

hopefully that'll fix your problem.
 
O

OnRails Ruby

Thanks a lots, matthewrudy and Phlip
I had posted this question on groups google. and got the same answer.

I think that is a function like "def send_welcome_message(person)",
and that is a model method(action) like "def send_welcome_message",
so when I defined "def send_welcome_message(person)", I can call
it in I method(action), then you don't need to test this function.
This idea is right or not?
Thanks help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top