gpt4 book ai didi

ruby - ActionController::Rspec 中的 RoutingError 即使 Controller 和操作存在

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:08 25 4
gpt4 key购买 nike

我在为我的 Omniauth 授权 Controller 编写测试时遇到了 Rspec 的问题。

这是我的 routes.rb

MyWebApp::Application.routes.draw do

get "static/index"

match "login" => 'user_sessions#new'

match 'logout' => 'user_sessions#destroy'

match "api" => "api#content", :via => :get
match "api/node_tree" => "api#node_tree", :via => :get

match "/auth/:provider/callback" => "oauth_authorizations#create"
match "/auth/failure" => "oauth_authorizations#failure"
match "/auth/:provider" => "oauth_authorizations#blank"

resources :users do
resources :apps do
resources :nodes
end
end

resources :user_sessions
end

oauth_authorization_controller_spec.rb

it "should create a new authorization entry for the user" do
expect {get :create }.to change(Authorization, :count).by(1)
end

oauth_authorization_controller.rb

class OauthAuthorizationsController < ApplicationController

def create

end

end

当我运行我的规范时,出现以下错误

Failures: 

1) OauthAuthorizationsController when a current user session already exists should create a new authorization entry for the user
Failure/Error: expect {get :create }.to change(Authorization, :count).by(1)
ActionController::RoutingError:
No route matches {:controller=>"oauth_authorizations", :action=>"create"}

谁能帮我找出这背后的原因,因为从 Controller 代码中可以清楚地看出,{:controller=>"oauth_authorizations", :action=>"create"} 确实存在。

最佳答案

尝试用帖子替换 get http 动词:

  expect {post :create }.to change(Authorization, :count).by(1)

关于ruby - ActionController::Rspec 中的 RoutingError 即使 Controller 和操作存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14092237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com