Commit Graph

468 Commits

Author SHA1 Message Date
Andre Schweighofer
a1ae7dc0d9 Update deprecation warning with correct namespace 2016-03-30 15:51:13 +02:00
Yohan Robert
21cb896802 Move SerializableResource to ActiveModelSerializers namespace
Ref. https://github.com/rails-api/active_model_serializers/pull/1310
2016-03-30 11:33:04 +02:00
Benjamin Fleischer
355e0f6a37 Merge branch 'lserman-master'
Followup needed:
- Update code comments https://github.com/rails-api/active_model_serializers/pull/1622#discussion_r57750471
- Move test class into test scope https://github.com/rails-api/active_model_serializers/pull/1622#discussion_r57659150
2016-03-29 21:50:27 -05:00
Benjamin Fleischer
c7b2916f37 Merge pull request #1547 from bf4/jsonapi_renderer
Basic Jsonapi Renderer registration
2016-03-28 22:23:40 -05:00
Benjamin Fleischer
d364c4f188 Spike Jsonapi Renderer registration 2016-03-28 22:04:16 -05:00
Benjamin Fleischer
ec5dc497b0 Handle render.ams with nil serializer or adapter 2016-03-28 21:33:23 -05:00
Benjamin Fleischer
84197e4dad SerializableResource handles no serializer like controller 2016-03-28 20:04:45 -05:00
Logan Serman
d0389ca765 Fix fragment caching inherited serializers to use distinct per-serializer caches. 2016-03-28 16:26:51 -05:00
Yohan Robert
5af7d96294 Merge pull request #1618 from bf4/RomanKapitonov-master
Empty collection root key from explicit serializer option
2016-03-27 18:38:14 +02:00
Benjamin Fleischer
a74d174420 Include Serializer._type in collection serializer json_key cascade 2016-03-27 10:55:31 -05:00
Roman Kapitonov
2dd0c33461 [FIX] Fetch json key from item serializer if empty collection is passed to collection serializer and each_searializer is specified. 2016-03-27 10:52:25 -05:00
Benjamin Fleischer
2627740806 Silence @_routes warnings 2016-03-27 10:45:57 -05:00
Benjamin Fleischer
fb06a462bb Fix warnings 2016-03-25 10:28:13 -05:00
Benjamin Fleischer
dd60a371ae Simplify caching of value of config.perform_caching 2016-03-24 22:22:19 -05:00
Benjamin Fleischer
c3c69a607a Separate enabling of caching and setting the cache store 2016-03-24 22:20:42 -05:00
Benjamin Fleischer
9953d7abe0 Trigger callback to set serializer#_cache when controller loaded 2016-03-24 22:20:42 -05:00
Ben Mills
c533d1a7fe Provide key case translation 2016-03-15 12:21:10 -06:00
Ben Mills
e8286b6138 Omit meta when blank 2016-03-14 08:36:09 -06:00
Benjamin Fleischer
eda8ff1737 Move serializer caching from adapter 2016-03-13 19:57:59 -05:00
Benjamin Fleischer
fcd394ab09 Merge pull request #1482 from bf4/jsonapify
Document JSON API implementation defs and progress in class
2016-03-13 01:18:31 -06:00
Benjamin Fleischer
bdb997b1d9 Document JSON API implementation defs and progress in class 2016-03-13 00:30:06 -06:00
Benjamin Fleischer
b169ed387b Make serializers serializable, step 1. 2016-03-13 00:26:15 -06:00
Benjamin Fleischer
85658c0230 Add better serialization_scope tests; uncover bug 2016-03-12 19:59:43 -06:00
Ben Morrall
b5dd90c8f9 Fixed pagination issue with last page size 2016-03-10 09:30:29 +11:00
Yohan Robert
efb09051ea Refactor fragment cache methods
Removed extra calls to constantize and DRY'd the code.
2016-03-08 23:51:10 +01:00
Benjamin Fleischer
68d5233b31 Address rubocop warnings 2016-03-08 22:32:34 +01:00
Benjamin Fleischer
a26d3e4425 Rubocop autocorrect 2016-03-08 22:32:34 +01:00
Ben Mills
cc10928472 Provide Rails url_helpers via SerializationContext 2016-03-07 10:40:34 -07:00
Yohan Robert
8dfbc4818d Simplify adapter deprecation and delegation
The Adapter module was refactored a bit to use Active Support delegation
and remove duplicated code.
The CHANGELOG was also added.
2016-03-07 15:09:09 +01:00
Benjamin Fleischer
b50195fde7 Add a deprecation DSL 2016-03-07 01:07:06 -06:00
Benjamin Fleischer
6b4c8df6fb Clean up test deprecation warnings 2016-03-06 23:35:22 -06:00
Benjamin Fleischer
5d7a1a4889 Remove the last of ApiObjects 2016-03-06 23:24:53 -06:00
Yohan Robert
dd94fe2163 Follow up to #1535
- The removed classes and modules were added back with deprecation
  warning and deprecation test were added for them.
- One test was renamed because it contained `__`.
- Some tests were refactored.
- The ActiveModelSerializers::Deserialization module is now called
  Adapter instead of ActiveModelSerializers::Adapter.
- The changelog was added for #1535
2016-03-06 23:15:39 -06:00
NullVoxPopuli
d03db81070 add an extra format token to the primary data string so that JRuby doesn't break 2016-03-06 20:05:25 -06:00
Benjamin Fleischer
e6ae34b84c Update documentation with Yard links 2016-03-06 20:05:25 -06:00
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
Benjamin Fleischer
96107c56aa Require explicit adapter/serializer to render JSON API errors
- Separate collection errors from resource errors in adapter
- Refactor to ErrorsSerializer; first-class json error methods
- DOCS
- Rails 4.0 requires assert exact exception class, boo
2016-03-06 12:03:17 -06:00
Benjamin Fleischer
dfe162638c Generalize detection of serializable resource with errors 2016-03-06 12:03:17 -06:00
Benjamin Fleischer
0ba944dabf RFC: Json Api Errors (WIP)
- ActiveModelSerializers::JsonPointer
- ActiveModel::Serializer::Adapter::JsonApi::Error
- ActiveModel::Serializer::Adapter::JsonApi::Error.attributes
- Fix rubocop config
2016-03-06 12:03:14 -06:00
Benjamin Fleischer
e35390623d Improve adapter test coverage per groyoh 2016-02-25 23:08:20 -06:00
Benjamin Fleischer
25c9df0b97 Merge branch 'master' into domitian-move-namespace-of-adapter-to-active-model-serializers
Conflicts:
	CHANGELOG.md
	lib/active_model/serializer/adapter/attributes.rb
	lib/active_model/serializer/adapter/cached_serializer.rb
	lib/active_model/serializer/adapter/fragment_cache.rb
	lib/active_model/serializer/adapter/json_api.rb
	lib/active_model/serializer/adapter/json_api/link.rb
	test/adapter/fragment_cache_test.rb
	test/adapter/json_api/links_test.rb
	test/adapter/json_api/resource_type_config_test.rb
2016-02-23 23:21:49 -06:00
bobba surendranath chowdary
252f9c4ae9 Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace
Changed the namespace in adapters and folder to active_model_serializers from active_model::serializer

Changed namespace of adapters in serializers and other folders

Moved adapter_for_test file to active_model_serializers folder and changed namespace of adapter inside the test file

Require ActiveSupport's string/inflections

We depend on string/inflections to define String#underscore.

Refactor JsonApi adapter to avoid redundant computations.

Update readme.md to link to v0.10.0.rc4

changed namespace of adapter folder testcases

Changed all namespaces of adapter under active_moder_serializers

Namespaced IncludeTree which is from serializer module, so needed to namespace it properly

Fixed wrong namsepacing of fieldset

namespace change in deserializer json_api

Fixed the namespace for collection serializer when used inside adapter, changed namespace for adapter to new namespace which I had forgotten previously

Modified logging test and adapter test cases to make the testcases pass

Changed the yardoc links,as old links are not taking to documentation pages,proper links for 0.10,0.9 and 0.8 in rubydoc

Rubocop errors are fixed by underscore naming unused variables

Moved the require of adapter to serializable resource

Remoeved adapter dependency inside serializer and added warning to Serializer::adapter method

Fixed frament cache test which is calling Serializer.adapter

Changed the name of lookup_adapter_from_config to configured_adapter

Changed the docs which will show the new namespace of adapters

Rubocop fix
2016-02-23 21:49:58 -06:00
Yohan Robert
727d7631ae Add symbol support for ActiveModel::Serializer.type method
The ActiveModel::Serializer.type method now accepts symbol as paremeter:
class AuthorSerializer < ActiveModel::Serializer
  type :profile
end
The test file for the type was also refactored.
2016-02-19 17:05:13 +01:00
Yohan Robert
3cbc0541c1 Fix bug displaying nil for relationship link href
When using the relationship link with a block, calling "meta" without "href", e.g.
has_one :bio do
  link :related do
    meta id: 1
  end
end

results in in a nil "href", e.g.
{ links: { posts: { related: { href: nil, meta: { id: 1 } }  } } }.
According to JSONAPI, we should be able to use meta without href
(http://jsonapi.org/format/#document-links).
2016-02-15 09:26:53 +01:00
Benjamin Fleischer
2b673634d9 Merge branch 'groyoh-association-blocks' 2016-02-12 14:52:21 -06:00
Benjamin Fleischer
54aa6aa499 Merge branch 'LcpMarvel-support_read_multi'
Followup:
- Changelog
2016-02-11 00:48:48 -06:00
Yohan Robert
b1fd43303c Fix relationship behavior when using block
When using the relationships DSL with a block e.g.
has_one :bio do
  link :self, "some_link"
end
the "data" field would be rendered with a nil value even though the bio
is not nil. This happened because the block return value was set to nil
but used as a value for the "data" field.
2016-02-10 21:04:37 +01:00
Yohan Robert
2c4193851b Follow up to #1454
PR #1454 was merged with some missing fixes. All these fixes are
addressed by this commit:
- Rename ActiveModel::Serializer::Adapter::JsonApi::Association to
ActiveModel::Serializer::Adapter::JsonApi::Relationship
- Move ActiveModel::Serializer::Adapter:: JsonApi::Relationship and
ActiveModel::Serializer::Adapter::JsonApi::ResourceIdentifier to
ActiveModel::Serializer::Adapter::JsonApi::ApiObjects module
- Add unit test for
ActiveModel::Serializer::Adapter::JsonApi::Relationship
- Add unit test for
ActiveModel::Serializer::Adapter::JsonApi::ResourceIdentifier
2016-02-10 12:57:54 +01:00
Benjamin Fleischer
a40998273d Merge branch 'CheckMateIO-bugfix/fagment-caching-breaks-type-setting'
Squashed commits that were done in other PR

Follow up needs:
- Changelog
2016-02-09 22:35:45 -06:00
Brian McManus
d67f7da114 Preserve the serializer type when fragment caching
We were not previously cloning the type setting into the dynamically
generated cached/non-cached serializers for a given fragment-cached
serializer. This led to the type generated for JsonApi having the wrong
value when fragment caching is enabled by adding either :except or :only
options to cache.

This pulls the type setting from the fragment-cached serializer forward
onto the dynamic caching classes so it is preserved in the output.
2016-02-09 22:35:32 -06:00