【发布时间】:2012-03-21 16:12:04
【问题描述】:
我在 Rails 3.1 中使用最新的 oauth 插件。我想用 rspec 测试来测试我的 OAuth2 API 控制器。在尝试了一堆事情来授权我的请求之后,我只想存根 oauthenticate 过滤器以摆脱任何身份验证问题。但我仍然得到 401 Unauthorized 。为什么??
users_controller.rb:
class UsersController
oauthenticate
def update
<do something>
end
end
users_controller_spec.rb:
describe UsersController do
describe "POST 'update'" do
before :each do
controller.stub!(:oauthenticate).and_return true
end
it "should be a successful request" do
post :update, { "user_id" => "some id" }
response.should be_ok
end
end
预期 ActionController::TestResponse 的响应代码为 200,但得到了 401。
Rspec testing for oauth provider 没有帮助。使用黄瓜测试设置有效的访问令牌时一切正常授权标头。
【问题讨论】:
标签: ruby-on-rails rspec oauth-2.0