Rails - How do you dynamically call the request methods "get put destroy etc" at runtime in tests
Posted
by adam
on Stack Overflow
See other posts from Stack Overflow
or by adam
Published on 2010-05-29T05:09:31Z
Indexed on
2010/05/29
5:12 UTC
Read the original article
Hit count: 178
I'm always writing tests to check my controller restricts people from certain actions depending on their status i.e. logged in, admin? etc Regardless of whether its a get to :index or a puts to :create the code is always the same. I'm trying to refactor this so that i have one method such as
should_redirect_unauthenticated_to_login_action(request, action)
and call it like so
should_redirect_unauthenticated_to_login_action(:get, :index) => get :index
But not sure how to dynamically call the various response methods rails provides for functional tests which seem to live in the module ActionController
I mucked around with
module = Kernel.const_get("ActionController")
module::TestProcess.get
NoMethodError: undefined method `get' for ActionController::TestProcess:Module
can anyone help (im very new to dynamic calling in ruby)
© Stack Overflow or respective owner