私はrspecを介して1000以上のテストでカバーされた大きなアプリケーションを持っています。
次のようなページをリダイレクトすることを選択しました。
/
/foo
/foo/4/bar/34
...
に :
/en
/en/foo
/fr/foo/4/bar/34
....
だから私は次のようにapplication.rbでbeforeフィルターを作成しました:
if params[:locale].blank?
headers["Status"] = "301 Moved Permanently"
redirect_to request.env['REQUEST_URI'].sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{I18n.locale}#{$2}" }
end
それはうまく機能していますが...それは私のテストの多くを壊しています、例:
it "should return 404" do
Video.should_receive(:failed_encodings).and_return([])
get :last_failed_encoding
response.status.should == "404 Not Found"
end
このテストを修正するには、次のことを行う必要があります。
get :last_failed_encoding, :locale => "en"
しかし...真剣に私はすべてのテストを1つずつ修正したくありません...
私はロケールを次のようなデフォルトのパラメータにしようとしました:
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
...しかし、この作業を行うことができませんでした...何かアイデア??