All,
I want to create a mock action to test a filter in a functional test,
e.g.:
# Simplified example
def test_my_filter
# Singleton action
def @controller.foo
assert # something
end
ActionController::Routing::Routes.draw do |map|
map.connect '':controller/foo'', :action =>
''foo''
end
get :foo
end
My log files show that no action responds to foo, so I think I''m not
doing the routing properly. I''m trying this in
ApplicationControllerTest, if that matters. Is anything obviously wrong
here?
Thanks for taking the time to read this,
Brian
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-07 21:11 UTC
Re: Can I add a singleton action to @controller in a test?
On 7 May 2008, at 20:32, Brian Hartin wrote:> > My log files show that no action responds to foo, so I think I''m not > doing the routing properly. I''m trying this in > ApplicationControllerTest, if that matters. Is anything obviously > wrong > here?The routing stuff is irrelevant as routing isn''t used in functional tests (the tests know that since you''ve got @controller you want to invoke actions from there). If you look at the action controller code, rails decides whether or not a action exists by looking at the class'' instance methods, so singleton methods don''t get a look in. could you not just define a method in the class (and undef it afterwards if you want) or ever create a controller class on the fly just with that action it Fred -- My ramblings: http://www.spacevatican.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian Hartin
2008-May-08 17:13 UTC
Re: Can I add a singleton action to @controller in a test?
Frederick Cheung wrote: [...]> > The routing stuff is irrelevant as routing isn''t used in functional > tests (the tests know that since you''ve got @controller you want to > invoke actions from there). If you look at the action controller code, > rails decides whether or not a action exists by looking at the class'' > instance methods, so singleton methods don''t get a look in. could you > not just define a method in the class (and undef it afterwards if you > want) or ever create a controller class on the fly just with that > action it > > Fred > -- > My ramblings: http://www.spacevatican.orgI did the latter and it worked very well. Thanks Fred! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---