check map#contains matches json schema in spec

This commit is contained in:
Devin Howard 2016-02-09 11:20:27 +08:00
parent 0b98e446ca
commit 7956e6d289
6 changed files with 62 additions and 0 deletions

View file

@ -43,6 +43,7 @@ group :test do
gem 'factory_girl_rails' gem 'factory_girl_rails'
gem 'shoulda-matchers' gem 'shoulda-matchers'
gem 'simplecov', require: false gem 'simplecov', require: false
gem 'json-schema'
end end
group :production do #this is used on heroku group :production do #this is used on heroku

View file

@ -36,6 +36,7 @@ GEM
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.3.8)
arel (6.0.3) arel (6.0.3)
aws-sdk (1.66.0) aws-sdk (1.66.0)
aws-sdk-v1 (= 1.66.0) aws-sdk-v1 (= 1.66.0)
@ -105,6 +106,8 @@ GEM
jquery-ui-rails (5.0.5) jquery-ui-rails (5.0.5)
railties (>= 3.2.16) railties (>= 3.2.16)
json (1.8.3) json (1.8.3)
json-schema (2.6.0)
addressable (~> 2.3.8)
kaminari (0.16.3) kaminari (0.16.3)
actionpack (>= 3.0.0) actionpack (>= 3.0.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
@ -251,6 +254,7 @@ DEPENDENCIES
jquery-rails jquery-rails
jquery-ui-rails jquery-ui-rails
json json
json-schema
kaminari kaminari
paperclip paperclip
pg pg

View file

@ -15,6 +15,14 @@ RSpec.describe MapsController, type: :controller do
end end
end end
describe 'GET #contains' do
it 'returns json matching schema' do
get :contains, { id: map.to_param, format: :json }
# get "maps/#{map.id}/contains"
expect(response.body).to match_json_schema(:map_contains)
end
end
describe 'GET #show' do describe 'GET #show' do
it 'assigns the requested map as @map' do it 'assigns the requested map as @map' do
get :show, { id: map.to_param } get :show, { id: map.to_param }

0
spec/schemas/map.json Normal file
View file

View file

@ -0,0 +1,42 @@
{
"name": "Map Contents",
"type": "object",
"properties": {
"map": {
"type": "object"
},
"topics": {
"type": "array",
"items": {
"type": "object"
}
},
"synapses": {
"type": "array",
"items": {
"type": "object"
}
},
"mappings": {
"type": "array",
"items": {
"type": "object"
}
},
"mappers": {
"type": "array",
"items": {
"type": "object"
}
}
},
"required": [
"map",
"topics",
"synapses",
"mappings",
"mappers"
]
}

View file

@ -0,0 +1,7 @@
RSpec::Matchers.define :match_json_schema do |schema|
match do |json|
schema_directory = Rails.root.join('spec', 'schemas').to_s
schema_path = "#{schema_directory}/#{schema}.json"
JSON::Validator.validate!(schema_path, json)
end
end