Tôi có điều này tuyến đường (phải thừa nhận là gớm ghiếc) trong Rails:Làm thế nào để yêu cầu (GET/POST) tuyến đường trong RSpec rằng có một ký tự đại diện
scope '/software' do post '/:software_id/:attachment_id/event/*event' => 'software#post_event', as: 'post_event' end
(tôi sẽ thay đổi nó nhưng đối với một API legacy)
Và tôi đang viết một bài kiểm tra RSpec cho nó.
rake routes
mang lại cho tôi:
post_event POST /software/:software_id/:attachment_id/event/*event(.:format) api/version1301/software#post_event
thử nghiệm của tôi trông như thế này:
describe "post_event" do it "should respond with 204" do params = { attachment_id: @attachment.uid, software_id: @license.id } post :post_event, params response.code.should eq "204" end end
Nhưng tôi nhận được lỗi định tuyến sau:
Failure/Error: post :post_event, params ActionController::RoutingError: No route matches {:format=>"json", :name_path=>:api, :attachment=>"7b40ab6a-d522-4a86-b0de-dfb8081e4465", :software_id=>"0000001", :attachment_id=>"7b40ab6a-d522-4a86-b0de-dfb8081e4465", :controller=>"api/version1301/software", :action=>"post_event"} # ./spec/controllers/api/version1301/software_controller_spec.rb:62:in `block (4 levels) in '
Làm thế nào để bạn xử lý các tuyến đường với ký tự đại diện (sự kiện)?
Đã xảy ra sự cố tương tự với động cơ được gắn bên trong phạm vi: phạm vi "* lang" {mount XX :: Engine, tại: '/'}. Tôi đã phải vượt qua trong 'lang: "vi"' để 'get' trong thử nghiệm để làm cho nó hoạt động .... mà đã cho tôi 2 ngày để tìm ..... –
Gần đây tôi đã viết [thông số kỹ thuật định tuyến ] (https://www.relishapp.com/rspec/rspec-rails/docs/routing-specs) cho tất cả các tuyến đường không phải là RESTful mà tôi gặp phải. Đã lưu một số nhức đầu. – Epigene