如何使用ActionController :: TestCase#post来使用带有http basic auth的Rest API?
答案 0 :(得分:1)
假设您使用的是Rails 3,您可以通过调用ActionController :: HttpAuthentication :: Basic中的encoding_credentials来设置请求env HTTP_AUTHORIZATION
。
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials("username", "password")