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?
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
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