active_model_serializers/test
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
..
action_controller Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
active_model_serializers Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
adapter Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
fixtures RFC: Json Api Errors (WIP) 2016-03-06 12:03:14 -06:00
generators Only load generators when needed 2016-01-15 01:52:27 -06:00
include_tree Favor ActiveSupport::TestCase over Minitest::Test 2015-12-22 10:35:51 -06:00
serializers Remove AS::Testing::Stream in favor of Minitest assert_output 2016-02-25 23:21:44 -06:00
support Remove AS::Testing::Stream in favor of Minitest assert_output 2016-02-25 23:21:44 -06:00
active_record_test.rb Favor ActiveSupport::TestCase over Minitest::Test 2015-12-22 10:35:51 -06:00
adapter_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
array_serializer_test.rb Remove AS::Testing::Stream in favor of Minitest assert_output 2016-02-25 23:21:44 -06:00
collection_serializer_test.rb Don't pluralize the CollectionSerializer#root for #json_key 2016-01-12 09:32:43 -08:00
grape_test.rb Favor ActiveSupport::TestCase over Minitest::Test 2015-12-22 10:35:51 -06:00
lint_test.rb RFC: Json Api Errors (WIP) 2016-03-06 12:03:14 -06:00
logger_test.rb Favor ActiveSupport::TestCase over Minitest::Test 2015-12-22 10:35:51 -06:00
poro_test.rb Favor ActiveSupport::TestCase over Minitest::Test 2015-12-22 10:35:51 -06:00
serializable_resource_test.rb Collapse JSON API success/failure documents in one adapter 2016-03-06 12:03:17 -06:00
test_helper.rb Remove AS::Testing::Stream in favor of Minitest assert_output 2016-02-25 23:21:44 -06:00