mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
assert response body based on spec examples
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
class BlogsController < ApplicationController
|
||||
wrap_parameters Blog
|
||||
respond_to :json
|
||||
|
||||
# POST /blogs
|
||||
def create
|
||||
render json: {}
|
||||
@blog = Blog.create(params[:blog])
|
||||
respond_with @blog
|
||||
end
|
||||
|
||||
# GET /blogs
|
||||
def index
|
||||
render json: {}
|
||||
@blogs = Blog.all
|
||||
respond_with @blogs
|
||||
end
|
||||
|
||||
# GET /blogs/1
|
||||
def show
|
||||
render json: {}
|
||||
@blog = Blog.find(params[:id])
|
||||
respond_with @blog
|
||||
end
|
||||
end
|
||||
|
||||
10
spec/dummy/app/models/blog.rb
Normal file
10
spec/dummy/app/models/blog.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Blog < ActiveRecord::Base
|
||||
attr_accessible :content, :title
|
||||
|
||||
def as_json(options)
|
||||
{
|
||||
title: title,
|
||||
content: content
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dummy</title>
|
||||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
||||
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,7 @@
|
||||
require File.expand_path('../boot', __FILE__)
|
||||
|
||||
# Pick the frameworks you want:
|
||||
# require "active_record/railtie"
|
||||
require "active_record/railtie"
|
||||
require "action_controller/railtie"
|
||||
require "action_mailer/railtie"
|
||||
require "action_view/railtie"
|
||||
|
||||
25
spec/dummy/config/database.yml
Normal file
25
spec/dummy/config/database.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
#SQLite version 3.x
|
||||
# gem install sqlite3
|
||||
#
|
||||
# Ensure the SQLite 3 gem is defined in your Gemfile
|
||||
# gem 'sqlite3'
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: db/test.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
production:
|
||||
adapter: sqlite3
|
||||
database: db/production.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
@@ -1,5 +1,5 @@
|
||||
Rails.application.routes.draw do
|
||||
mount SwaggerRails::Engine => '/api-docs'
|
||||
resources :blogs, defaults: { :format => :json }
|
||||
|
||||
resources :blogs, only: [ :create, :index, :show ]
|
||||
mount SwaggerRails::Engine => '/api-docs'
|
||||
end
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Ok",
|
||||
"201": {
|
||||
"description": "Created",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Blog"
|
||||
}
|
||||
@@ -58,7 +58,10 @@
|
||||
"200": {
|
||||
"description": "Ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Blog"
|
||||
"type": "array",
|
||||
"item": {
|
||||
"$ref": "#/definitions/Blog"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
spec/dummy/db/migrate/20160218212104_create_blogs.rb
Normal file
10
spec/dummy/db/migrate/20160218212104_create_blogs.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class CreateBlogs < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :blogs do |t|
|
||||
t.string :title
|
||||
t.text :content
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
23
spec/dummy/db/schema.rb
Normal file
23
spec/dummy/db/schema.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# encoding: UTF-8
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20160218212104) do
|
||||
|
||||
create_table "blogs", :force => true do |t|
|
||||
t.string "title"
|
||||
t.text "content"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
end
|
||||
@@ -5,5 +5,14 @@ class V1ContractTest < ActionDispatch::IntegrationTest
|
||||
include SwaggerRails::TestHelpers
|
||||
|
||||
swagger_doc 'v1/swagger.json'
|
||||
swagger_test_all
|
||||
#
|
||||
# test '/blogs post' do
|
||||
# swagger_test '/blogs', 'post'
|
||||
# end
|
||||
|
||||
test '/blogs get' do
|
||||
blog = Blog.create(title: 'Test Blog', content: 'Hello World')
|
||||
|
||||
swagger_test '/blogs', 'get'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user