From c484adb503695b2bf57b673f3a37ecc59cf2c394 Mon Sep 17 00:00:00 2001 From: Bhaskar Shankarling Date: Wed, 19 Dec 2018 15:17:14 +0530 Subject: [PATCH 1/2] Added the spec under spec/issues for the issue id 730 --- ...agger_is_not_detecting_mounted_rack_app.rb | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb diff --git a/spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb b/spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb new file mode 100644 index 00000000..9b43ed06 --- /dev/null +++ b/spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'grape-swagger/entity' + +module API + module V1 + class Welcome < Grape::API + desc 'Greets user' do + detail 'This is the root api and it will greet user on accessing' + end + get "/" do + { + data: [ + { message: "Welcome to notes app" } + ] + } + end + end + end +end + +module API + module V1 + class Base < Grape::API + version :v1, using: :path + + mount Welcome + end + end +end + +module API + class Base < Grape::API + format :json + prefix :api + + mount V1::Base + + add_swagger_documentation hide_documentation_path: true, + version: "V1", + info: { + title: 'User notes app', + description: 'Demo app for user notes' + } + end +end + +describe 'swagger is not detecting mounted rack app' do + let(:app) { API::Base } + + context 'when a rack app is mounted under API::Base' do + + context 'when api/v1/ is called' do + subject do + get '/api/v1' + JSON.parse(last_response.body) + end + + it 'checks if the response is correct' do + expect(subject).to eq({"data"=>[{"message"=>"Welcome to notes app"}]}) + end + end + + context 'when api/swagger_doc is called' do + subject do + get '/api/swagger_doc' + JSON.parse(last_response.body) + end + + it 'checks if the swagger documentation is properly generated' do + expect(subject["paths"]).to_not be_nil + end + end + end +end \ No newline at end of file From d465ba7f0d4d323ecdcba92a4f558dfc10d0e2e4 Mon Sep 17 00:00:00 2001 From: Bhaskar Shankarling Date: Wed, 19 Dec 2018 15:43:47 +0530 Subject: [PATCH 2/2] Made the changes to fix all the offences pointed out by the rubocop while mergin pull request --- ...730_swagger_is_not_detecting_mounted_rack_app.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb b/spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb index 9b43ed06..cf6fd5e6 100644 --- a/spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb +++ b/spec/issues/730_swagger_is_not_detecting_mounted_rack_app.rb @@ -10,10 +10,10 @@ class Welcome < Grape::API desc 'Greets user' do detail 'This is the root api and it will greet user on accessing' end - get "/" do + get '/' do { data: [ - { message: "Welcome to notes app" } + { message: 'Welcome to notes app' } ] } end @@ -39,7 +39,7 @@ class Base < Grape::API mount V1::Base add_swagger_documentation hide_documentation_path: true, - version: "V1", + version: 'V1', info: { title: 'User notes app', description: 'Demo app for user notes' @@ -51,7 +51,6 @@ class Base < Grape::API let(:app) { API::Base } context 'when a rack app is mounted under API::Base' do - context 'when api/v1/ is called' do subject do get '/api/v1' @@ -59,7 +58,7 @@ class Base < Grape::API end it 'checks if the response is correct' do - expect(subject).to eq({"data"=>[{"message"=>"Welcome to notes app"}]}) + expect(subject).to eq('data' => [{ 'message' => 'Welcome to notes app' }]) end end @@ -70,8 +69,8 @@ class Base < Grape::API end it 'checks if the swagger documentation is properly generated' do - expect(subject["paths"]).to_not be_nil + expect(subject['paths']).to_not be_nil end end end -end \ No newline at end of file +end