Skip to content

Commit

Permalink
Test that the helper can able use JSON Pointers in non-hyper schemata
Browse files Browse the repository at this point in the history
  • Loading branch information
maurogeorge committed Dec 3, 2015
1 parent e34c8ab commit 0852b49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/active_model_serializers/test/schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def test_that_assert_with_a_hyper_schema
assert_response_schema('hyper_schema.json')
end

def test_simple_json_pointers
get :show
assert_response_schema('simple_json_pointers.json')

This comment has been minimized.

Copy link
@malandrina

malandrina Dec 4, 2015

One last thought: We've found on json_matchers that it's useful to test the negative case because sometimes pointers aren't dereferenced as expected and we get false positives when we only test the "happy path". This RSpec test is a good example of what I'm suggesting.

This comment has been minimized.

Copy link
@maurogeorge

maurogeorge Dec 9, 2015

Author Owner

I think I found a issue on json_schema trying to reproduce this steps.

With a response:

{"name":1,"description":"Description 1"}

And passing the file

{
  "properties": {
    "name": {
      "$ref": "test/support/schemas/custom/show.json#/properties/name"
    },
    "description": {
      "$ref": "test/support/schemas/custom/show.json#/properties/description"
    }
  }
}
# test/support/schemas/custom/show.json

{
  "properties": {
    "name" : { "type" : "string" },
    "description" : { "type" : "string" }
  }
}

This is valid on json_schema, as you can see the name on response is a integer and in the schema is a string. If I change the schema to this:

{
  "properties": {
    "name" : { "type" : "string" },
    "description": {
      "$ref": "test/support/schemas/custom/show.json#/properties/description"
    }
  }
}

I got the expected error.

This makes sense to you? If positive I can create a issue to this on the json_schema.

This comment has been minimized.

Copy link
@malandrina

malandrina Dec 10, 2015

Yes, that makes sense to me. Hopefully the maintainer of json_schema will have some insight regarding this behavior.

This comment has been minimized.

Copy link
@maurogeorge

maurogeorge Dec 10, 2015

Author Owner

I created the issue brandur/json_schema#41, lets wait for a feedback.

This comment has been minimized.

Copy link
@bf4

bf4 Dec 21, 2015

@maurogeorge nice work!

This comment has been minimized.

Copy link
@maurogeorge

maurogeorge Dec 21, 2015

Author Owner

@malandrina In the end this is not a bug but a design decision brandur/json_schema#41 (comment).

@bf4 thanks ❤️

end

def test_that_assert_with_a_custom_schema_directory
original_schema_path = ActiveModel::Serializer.config.schema_path
ActiveModel::Serializer.config.schema_path = 'test/support/custom_schemas'
Expand Down
10 changes: 10 additions & 0 deletions test/support/schemas/simple_json_pointers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"properties": {
"name": {
"$ref": "test/support/schemas/custom/show.json#/properties/name"
},
"description": {
"$ref": "test/support/schemas/custom/show.json#/properties/description"
}
}
}

0 comments on commit 0852b49

Please sign in to comment.