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! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 9/15/07, OnRails <zzzlai-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> 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; > endYour action method needs to be defined without arguments: def send_welcome_message person = params[:person] ... 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!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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! On Sep 15, 6:42 pm, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/15/07, OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> 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 > > > > > 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!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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.. On Sep 15, 7:23 pm, OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> 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! > > On Sep 15, 6:42 pm, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 9/15/07, OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> 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 > > > > 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!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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)" from the URI box. You would post to " 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. On 9/17/07, OnRails <zzzlai-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > > 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.. > > On Sep 15, 7:23 pm, OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > 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! > > > > On Sep 15, 6:42 pm, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 9/15/07, OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> 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 > > > > > > 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! > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
...*you''re doing things... Stupid homophones. On 9/18/07, Ryan Angilly <angilly-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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%28person%29>" > from the URI box. You would post to "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. > > > On 9/17/07, OnRails <zzzlai-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > > > > > 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.. > > > > On Sep 15, 7:23 pm, OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org > wrote: > > > 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! > > > > > > On Sep 15, 6:42 pm, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On 9/15/07, OnRails < zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> 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 > > > > > > > > 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! > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---