Basic functionality via minitest

This commit is contained in:
domaindrivendev
2016-02-16 17:32:05 -08:00
parent 007b82a9e4
commit f9225a8a22
12 changed files with 445 additions and 14 deletions

View File

@@ -2,4 +2,6 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
wrap_parameters format: [ :json ]
end

View File

@@ -0,0 +1,14 @@
class BlogsController < ApplicationController
def create
render json: {}
end
def index
render json: {}
end
def show
render json: {}
end
end

View File

@@ -6,7 +6,7 @@ require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
require "rails/test_unit/railtie"
Bundler.require(*Rails.groups)
require "swagger_rails"

View File

@@ -1,4 +1,5 @@
Rails.application.routes.draw do
mount SwaggerRails::Engine => '/api-docs'
resources :blogs, only: [ :create, :index, :show ]
end

View File

@@ -2,43 +2,117 @@
"swagger": "2.0",
"info": {
"version": "0.0.0",
"title": "[Enter a description for your API here]",
"description": "The docs below are powered by the default swagger.json that gets installed with swagger_rails. You'll need to update it to describe your API. See here for the complete swagger spec - https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md"
"title": "Dummy app for testing swagger_rails"
},
"paths": {
"/a/sample/resource": {
"/blogs": {
"post": {
"tags": [
"a/sample/resource"
],
"description": "Create a new sample resource",
"description": "Creates a new Blog",
"parameters": [
{
"name": "body",
"name": "X-Forwarded-For",
"in": "header",
"type": "string",
"default": "client1"
},
{
"name": "blog",
"in": "body",
"schema": {
"$ref": "#/definitions/CreateSampleResource"
"$ref": "#/definitions/Blog"
}
}
],
"responses": {
"200": {
"description": "Ok"
"description": "Ok",
"schema": {
"$ref": "#/definitions/Blog"
}
},
"400": {
"description": "Invalid Request",
"schema": {
"$ref": "#/definitions/RequestError"
}
}
}
},
"get": {
"description": "Searches Bloggs",
"parameters": [
{
"name": "published",
"in": "query",
"type": "boolean",
"default": "true"
},
{
"name": "keywords",
"in": "query",
"type": "string",
"default": "Ruby on Rails"
}
],
"responses": {
"200": {
"description": "Ok",
"schema": {
"$ref": "#/definitions/Blog"
}
}
}
}
},
"/blogs/{id}": {
"get": {
"description": "Retrieves a specific Blog by unique ID",
"parameters": [
{
"name": "id",
"in": "path",
"type": "string",
"default": "123"
}
],
"responses": {
"200": {
"description": "Ok",
"schema": {
"$ref": "#/definitions/Blog"
}
}
}
}
}
},
"definitions": {
"CreateSampleResource": {
"Blog": {
"properties": {
"name": {
"title": {
"type": "string"
},
"date_time": {
"content": {
"type": "string",
"format": "date-time"
}
},
"example": {
"title": "Test Blog",
"content": "Hello World"
}
},
"RequestError": {
"type": "object",
"additionalProperties": {
"type": "array",
"item": {
"type": "string"
}
},
"example": {
"title": [ "is required" ]
}
}
}

View File

@@ -0,0 +1,9 @@
require 'test_helper'
require 'swagger_rails/testing/test_helpers'
class V1ContractTest < ActionDispatch::IntegrationTest
include SwaggerRails::TestHelpers
swagger_doc 'v1/swagger.json'
swagger_test_all
end

View File

@@ -0,0 +1,7 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Add more helper methods to be used by all tests here...
end