assert response body based on spec examples

This commit is contained in:
domaindrivendev
2016-02-23 00:30:10 -08:00
parent 071239727a
commit 9ad7a49e6d
16 changed files with 218 additions and 59 deletions

View File

@@ -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

View File

@@ -0,0 +1,10 @@
class Blog < ActiveRecord::Base
attr_accessible :content, :title
def as_json(options)
{
title: title,
content: content
}
end
end

View File

@@ -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>

View File

@@ -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"

View 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

View File

@@ -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

View File

@@ -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"
}
}
}
}

View 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
View 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

View File

@@ -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