check map#contains matches json schema in spec
This commit is contained in:
parent
0b98e446ca
commit
7956e6d289
6 changed files with 62 additions and 0 deletions
1
Gemfile
1
Gemfile
|
@ -43,6 +43,7 @@ group :test do
|
|||
gem 'factory_girl_rails'
|
||||
gem 'shoulda-matchers'
|
||||
gem 'simplecov', require: false
|
||||
gem 'json-schema'
|
||||
end
|
||||
|
||||
group :production do #this is used on heroku
|
||||
|
|
|
@ -36,6 +36,7 @@ GEM
|
|||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
addressable (2.3.8)
|
||||
arel (6.0.3)
|
||||
aws-sdk (1.66.0)
|
||||
aws-sdk-v1 (= 1.66.0)
|
||||
|
@ -105,6 +106,8 @@ GEM
|
|||
jquery-ui-rails (5.0.5)
|
||||
railties (>= 3.2.16)
|
||||
json (1.8.3)
|
||||
json-schema (2.6.0)
|
||||
addressable (~> 2.3.8)
|
||||
kaminari (0.16.3)
|
||||
actionpack (>= 3.0.0)
|
||||
activesupport (>= 3.0.0)
|
||||
|
@ -251,6 +254,7 @@ DEPENDENCIES
|
|||
jquery-rails
|
||||
jquery-ui-rails
|
||||
json
|
||||
json-schema
|
||||
kaminari
|
||||
paperclip
|
||||
pg
|
||||
|
|
|
@ -15,6 +15,14 @@ RSpec.describe MapsController, type: :controller do
|
|||
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
|
||||
it 'assigns the requested map as @map' do
|
||||
get :show, { id: map.to_param }
|
||||
|
|
0
spec/schemas/map.json
Normal file
0
spec/schemas/map.json
Normal file
42
spec/schemas/map_contains.json
Normal file
42
spec/schemas/map_contains.json
Normal 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"
|
||||
]
|
||||
}
|
||||
|
||||
|
7
spec/support/schema_matcher.rb
Normal file
7
spec/support/schema_matcher.rb
Normal 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
|
Loading…
Reference in a new issue