I need to test two things:
- that certain old paths are correctly redirected to certain new paths
- that the redirect is a 301, not a 302.
I'm using Capybara for my acceptance tests, but that can't handle #2. I can test that the redirect happens, but it happens silently, so I can't see that it was a 301.
Controller tests can't handle #1. The "get", "post" etc. verbs that rspec provides for controller tests only allow you to pass in an action, not a specific path, and the redirect is implemented in a single action based on the path, as below:
# controller
class ExampleController
def redirect301
redirect_to case request.path
when '/old_a'
'/new_a'
when '/old_b'
'/new_b'
end, :status => 301
end
end
# routes.rb
['old_a', 'old_b'].each do |p|
map.connect p, :controller => :example, :action => :redirect301
end
So, what should I do?