i18n redirection breaks my tests ....
- by Mike
I have a big application covered by more than a thousand tests via rspec.
We just made the choice to redirect any page like :
/
/foo
/foo/4/bar/34
...
TO :
/en
/en/foo
/fr/foo/4/bar/34
....
So I made a before filter in application.rb like so :
if params[:locale].blank?
headers["Status"] = "301 Moved Permanently"
redirect_to request.env['REQUEST_URI'].sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{I18n.locale}#{$2}" }
end
It's working great but ... It's breaking a lot of my tests, ex :
it "should return 404" do
Video.should_receive(:failed_encodings).and_return([])
get :last_failed_encoding
response.status.should == "404 Not Found"
end
To fix this test, I should do :
get :last_failed_encoding, :locale => "en"
But ... seriously I don't want to fix all my test one by one ...
I tried to make the locale a default parameter like this :
class ActionController::TestCase
alias_method(:old_get, :get) unless method_defined?(:old_get)
def get(path, parameters = {}, headers = nil)
parameters.merge({:locale => "fr"}) if parameters[:locale].blank?
old_get(path, parameters, headers)
end
end
... but couldnt make this work ...
Any idea ??