README.md in jsonapi_mapper-0.1.3 vs README.md in jsonapi_mapper-0.1.4
- old
+ new
@@ -144,9 +144,57 @@
attributes: {
persons: {handle: :name, dog: :pet, parental_figure: :parent},
pets: {nickname: :name},
}
}).save_all
+
+
+ # If any resource in your document has errors, you can get a collection
+ # with pointers to the specific fields and the type and id of the resource
+ # that has the error.
+ document = {
+ data: [
+ { type: 'pets', attributes: { age: 3 } },
+ { type: 'pets', attributes: { age: 6 } },
+ ],
+ included: [
+ { type: 'pets', id: '@1', attributes: { age: 4 } }
+ ]
+ }
+ mapper = JsonapiMapper.doc(document,
+ { pets: [:nickname, country: 'uruguay'] },
+ { types: { pets: PetDog }, attributes: { pets: {nickname: :name} } }
+ )
+
+ # all_valid? triggers all validations and sets up errors.
+ mapper.all_valid?.should be_falsey
+
+ # Then all errors are presented like so, honoring remapped names too.
+ mapper.all_errors.should == {
+ errors: [
+ { status: 422,
+ title: "can't be blank",
+ detail: "can't be blank",
+ code: "can_t_be_blank",
+ meta: {type: "pets"},
+ source: {pointer: "/data/0/attributes/nickname"}
+ },
+ { status: 422,
+ title: "can't be blank",
+ detail: "can't be blank",
+ code: "can_t_be_blank",
+ meta: {type: "pets"},
+ source: {pointer: "/data/1/attributes/nickname"}
+ },
+ { status: 422,
+ title: "can't be blank",
+ detail: "can't be blank",
+ code: "can_t_be_blank",
+ meta: {type: "pets"},
+ source: {pointer: "/included/0/attributes/nickname"}
+ }
+ ]
+ }
```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.