API documentation and spec setup
This commit is contained in:
parent
99ecb75c83
commit
900cc91197
7 changed files with 226 additions and 0 deletions
19
spec/api/v1/swagger_spec.rb
Normal file
19
spec/api/v1/swagger_spec.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
require 'apivore'
|
||||
|
||||
# we want to load a local file in YAML-format instead of a served JSON file
|
||||
class SwaggerCheckerFile < Apivore::SwaggerChecker
|
||||
def fetch_swagger!
|
||||
YAML.load(File.read(swagger_path))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'API v1', type: :apivore, order: :defined do
|
||||
include ApiHelper
|
||||
|
||||
subject { SwaggerCheckerFile.instance_for Rails.root.join('doc', 'swagger.v1.yml') }
|
||||
|
||||
it 'tests all documented routes' do
|
||||
is_expected.to validate_all_paths
|
||||
end
|
||||
end
|
||||
15
spec/factories/doorkeeper.rb
Normal file
15
spec/factories/doorkeeper.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require 'factory_bot'
|
||||
require 'doorkeeper'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :oauth2_application, class: Doorkeeper::Application do
|
||||
name { Faker::App.name }
|
||||
redirect_uri 'https://example.com:1234/app'
|
||||
end
|
||||
|
||||
factory :oauth2_access_token, class: Doorkeeper::AccessToken do
|
||||
application factory: :oauth2_application
|
||||
end
|
||||
|
||||
end
|
||||
18
spec/support/api_helper.rb
Normal file
18
spec/support/api_helper.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
module ApiHelper
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
let(:user) { create(:user) }
|
||||
let(:api_access_token) { create(:oauth2_access_token, resource_owner_id: user.id).token }
|
||||
let(:api_authorization) { "Bearer #{api_access_token}" }
|
||||
end
|
||||
|
||||
# Add authentication to parameters for {Swagger::RspecHelpers#validate}
|
||||
# @param params [Hash] Query parameters
|
||||
# @return Query parameters with authentication header
|
||||
# @see Swagger::RspecHelpers#validate
|
||||
def api_auth(params = {})
|
||||
{'_headers' => {'Authorization' => api_authorization }}.deep_merge(params)
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue