I'm trying to generate an easy macro for a Rails app that uses Devise for authentication. Basically I want to ensure that when a user accesses a page that requires authentication, they're redirected to the login page. So something like this:
it_requires_authentication_for :index, :new, :create, :update
The desired results here should be obvious. My problem however is that I can't think of the best way to map each action to its appropriate http method (:get, :post etc...)
I started out with this:
def it_should_require_authentication_for(*actions)
actions.each do |action|
it "should require authentication for #{action}" do
get action.to_sym
response.should redirect_to( new_user_session_path )
end
end
end
Which of course only does the get. Can someone tell me how I might provide this macro for all actions? I'm assuming I need to somehow test if the action routes properly for a particular method, but I'm just not really sure.
Any help is greatly appreciated.