gpt4 book ai didi

ruby-on-rails - Rails 5 路由规范需要 :path value

转载 作者:行者123 更新时间:2023-11-28 20:28:18 25 4
gpt4 key购买 nike

将 Rails 4.2.8 升级到 5.0 后,我的所有路由规范都失败并显示相同的错误消息:

1) UsersController routing routes to SHOW
Failure/Error: expect(get: '/users/joe-smith').to route_to('users#show', id: 'joe-smith')

The recognized options <{"path"=>"users/joe-smith", "controller"=>"users", "action"=>"show", "id"=>"joe-smith"}> did not match <{"id"=>"joe-smith", "controller"=>"users", "action"=>"show"}>, difference:.
--- expected
+++ actual
@@ -1 +1 @@
-{"id"=>"joe-smith", "controller"=>"users", "action"=>"show"}
+{"path"=>"users/joe-smith", "controller"=>"users", "action"=>"show", "id"=>"joe-smith"}
# ./spec/routing/users_controller_routing_spec.rb:10:in `block (3 levels) in <top (required)>'

Finished in 0.05154 seconds (files took 6.86 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/routing/users_controller_routing_spec.rb:9 # UsersController routing routes to SHOW

规范:

it 'routes to SHOW' do
expect(get: '/users/joe-smith').to route_to('users#show', id: 'joe-smith')
end

有人知道为什么会发生这种情况吗?我在 Rails 5 CHANGELOG 中没有看到任何内容。

最佳答案

更好的解决方法是开始移动到更多 future proof method提供更多值(value)的测试:

require 'rails_helper'
RSpec.describe "Users", type: :request do
let(:user) { create(:user) }

describe "GET /users/:id" do
it "takes a username as the id param" do
get user_path(user.user_name)
expect(response).to be_successful
end
end
end

关于ruby-on-rails - Rails 5 路由规范需要 :path value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43684888/

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