active_model_serializers/test/adapter/json_api
Benjamin Fleischer 3d986377b6 Collapse JSON API success/failure documents in one adapter
Idea per remear (Ben Mills) in the slack:
https://amserializers.slack.com/archives/general/p1455140474000171

remear:

    just so i understand, the adapter in `render json: resource, status: 422, adapter: 'json_api/error',
    serializer: ActiveModel::Serializer::ErrorSerializer` is a different one than, say what i’ve
    specified in a base serializer with `ActiveModel::Serializer.config.adapter = :json_api`. correct?

    and a followup question of, why not same adapter but different serializer?

me:

   With the way the code is written now, it might be possible to not require a special jsonapi adapter.
   However, the behavior is pretty different from the jsonapi adapter.

   this first draft of the PR had it automatically set the adapter if there were errors.  since that
   requires more discussion, I took a step back and made it explicit for this PR

   If I were to re-use the json api adapter and remove the error one, it think the serializable hash
   method would look like

   ```
   def serializable_hash(options = nil)
     return { errors: JsonApi::Error.collection_errors } if serializer.is_a?(ErrorsSerializer)
     return { errors: JsonApi::Error.resource_errors(serializer) } if serializer.is_a?(ErrorSerializer)
     options ||= {}
   ```

   I suppose it could be something more duckish like

   ```
   def serializable_hash(options = nil)
     if serializer.errors? # object.errors.any? || object.any? {|o| o.errors.any? }
       JsonApi::Error.new(serializer).serializable_hash
     else
       # etc
   ```
2016-03-06 12:03:17 -06:00
..
api_objects Fix deprecation warning 2016-02-19 10:13:54 +01:00
belongs_to_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
collection_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
errors_test.rb Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
fields_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
has_many_embed_ids_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
has_many_explicit_serializer_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
has_many_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
has_one_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
json_api_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
linked_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
links_test.rb Merge branch 'master' into domitian-move-namespace-of-adapter-to-active-model-serializers 2016-02-23 23:21:49 -06:00
pagination_links_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
parse_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
relationship_test.rb Fix bug displaying nil for relationship link href 2016-02-15 09:26:53 +01:00
resource_meta_test.rb Address issues in 50950d9533 #1340 2016-02-08 18:14:25 -06:00
toplevel_jsonapi_test.rb Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
type_test.rb Add symbol support for ActiveModel::Serializer.type method 2016-02-19 17:05:13 +01:00