我已经开发了before_filter - http://gist.github.com/138659并且在 像
这样的测试 test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:articles)
end
我看到了
test_should_get_index(ArticlesControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.split app/controllers/application_controller.rb:20:in
set_locale' /test/functional/articles_controller_test.rb:5:in
test_should_get_index'
当我添加
时setup do
@request.headers['HTTP_ACCEPT_LANGUAGE'] = "en"
end
没有改变:(你能告诉我一下 - 错了什么?
Rails 2.3.2,Ruby 1.8
答案 0 :(得分:1)
我用
解决了这个问题@request.env['HOST'] = "somesite.com"
@request.env['HTTP_ACCEPT_LANGUAGE'] = "en"