mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
Fix RoutePareser#routes and add spec for it
This commit is contained in:
parent
7ceedab4cb
commit
3b85f09acf
@ -11,7 +11,7 @@ module Rswag
|
||||
def routes
|
||||
::Rails.application.routes.routes.select do |route|
|
||||
route.defaults[:controller] == controller
|
||||
end.each_with_object({}) do |tree, route|
|
||||
end.each_with_object({}) do |route, tree|
|
||||
path = path_from(route)
|
||||
verb = verb_from(route)
|
||||
tree[path] ||= { params: params_from(route), actions: {} }
|
||||
|
||||
50
rswag-specs/spec/rswag/route_parser_spec.rb
Normal file
50
rswag-specs/spec/rswag/route_parser_spec.rb
Normal file
@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Rswag::RouteParser do
|
||||
describe "#routes" do
|
||||
let(:controller) { "api/v1/posts" }
|
||||
subject { described_class.new(controller) }
|
||||
|
||||
let(:routes) do
|
||||
[
|
||||
double(
|
||||
defaults: {
|
||||
controller: controller
|
||||
},
|
||||
path: double(
|
||||
spec: double(
|
||||
to_s: "/api/v1/posts/:id(.:format)"
|
||||
)
|
||||
),
|
||||
verb: "GET",
|
||||
requirements: {
|
||||
action: "show",
|
||||
controller: "api/v1/posts"
|
||||
},
|
||||
segments: ["id", "format"]
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
let(:expectation) do
|
||||
{
|
||||
"/api/v1/posts/{id}" => {
|
||||
params: ["id"],
|
||||
actions: {
|
||||
"get" => {
|
||||
summary: "show post"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
allow(::Rails).to receive_message_chain("application.routes.routes") { routes }
|
||||
end
|
||||
|
||||
it "returns correct routes" do
|
||||
expect(subject.routes).to eq(expectation)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user