开发者

send browser string in rails functional tests

The application should set the locale based on browser settings, but I don't realize how to test it. I don't know what code sample could I provide to explain, but the test is something like this:

def test_locale_settings
    get :index, {}, {:user_id => 1} # send browser settings to english
    assert_select '.nav .we开发者_JAVA百科lcome', :text => 'Welcome'
    get :index, {}, {:user_id => 1} # send browser settings to spanish
    assert_select '.nav .welcome', :text => 'Bienvenido'
end


Not sure if this works, but give it a try:

def test_locale_settings
    @request.env["HTTP_ACCEPT_LANGUAGE"] = "en"
    get :index, {}, {:user_id => 1} # send browser settings to english
    assert_select '.nav .welcome', :text => 'Welcome'

    @request.env["HTTP_ACCEPT_LANGUAGE"] = "es"
    get :index, {}, {:user_id => 1} # send browser settings to spanish
    assert_select '.nav .welcome', :text => 'Bienvenido'
end

Of course your application will need to know how to parse the format of the HTTP Accept Language header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜