Commit Graph

42 Commits

Author SHA1 Message Date
Gary Gordon
651b99f22e Support has_one to be compatible with 0.8.x
Update README and CHANGELOG
2015-03-01 13:47:34 -05:00
Alexandre de Oliveira
77fb050d24 Merge pull request #821 from wjordan/patch-1
Fix explicit serializer for associations
2015-03-01 08:46:27 -05:00
Alexandre de Oliveira
3505bc64a3 Merge pull request #798 from donbobka/feature/fix_lost_test
Fix lost test `test_include_multiple_posts_and_linked`
2015-03-01 08:41:13 -05:00
Will Jordan
f4eb33d6e9 Update test_includes_linked_comments with correct expected result 2015-02-24 18:46:04 -08:00
Joao Moura
8a432ad2b3 Adding cache support to version 0.10.0
It's a new implementation of cache based on ActiveSupport::Cache.
The implementation abstracts the cache in Adapter class on a
private method called cached_object, this method is intended
to be used on Adapters inside serializable_hash method in order
to cache each instance of the object that will be returned by
the serializer.

Some of its features are:
- A different syntax. (no longer need the cache_key method).
- An options argument that have the same arguments of ActiveSupport::Cache::Store, plus a key option that will be the prefix of the object cache on a pattern "#{key}-#{object.id}".
- It cache the objects individually and not the whole Serializer return, re-using it in different requests (as a show and a index method for example.)
2015-02-02 14:53:34 -02:00
Vladimir Lyzo
54d6696e7c Fix lost test test_include_multiple_posts_and_linked 2015-01-31 19:44:22 +03:00
Alexandre de Oliveira
e47231cdc8 Support overriding association methods
You can override associations to define custom scope on them.
2015-01-29 16:52:18 -02:00
Guillermo Iguaran
22202a115a Lets keep the assert_equal without parens for consistency. 2015-01-11 16:21:20 -05:00
Robbie Pitts
b626ec8f14 Spec for linked resource type name demodulization 2015-01-11 16:10:02 -05:00
Alexandre de Oliveira
6eb75af96b Merge pull request #696 from ggordon/explicit_serializer
Explicitly set serializer for associations
2015-01-06 09:57:07 -02:00
Alexandre de Oliveira
87f817943a Merge pull request #700 from arenoir/sparse_fieldsets
sparse fieldsets
2015-01-06 09:38:51 -02:00
Aaron Renoir
2ed52f96a6 merge upstream update fieldset 2014-11-13 17:45:47 -08:00
Alexandre de Oliveira
2f5626d616 Fixes nested has_many links in JSONAPI
When linked resource had has_many links, all of them would use the
association from the first resource, causing all of the items to build
`links` with the same associations.

This fixes it by iterating over the serializers, not just the
attributes array.
2014-11-13 16:38:47 -02:00
Gary Gordon
9f9715801a Explicitly set serializer for associations
Document specifying serializer for assocaition
2014-11-13 10:17:59 -05:00
Alexandre de Oliveira
7333f20285 Use type as key for linked resources
If type is `author` but the association is called `writer`, the linked
resource key should be called `authors`, e.g

    {
      ...
      linked: {
        authors: [{
          ...
        }]
      }
      ...
    }
2014-11-12 20:03:25 -02:00
Alexandre de Oliveira
91b3fba509 Includes links inside of linked resources
According to
http://jsonapi.org/format/#document-structure-resource-objects,

> Resource objects have the same internal structure, regardless of
> whether they represent primary or linked resources.

And then
http://jsonapi.org/format/#document-structure-resource-object-attributes,

> There are four reserved keys in resource objects:
>
> "id"
> "type"
> "href"
> "links"

This commits includes `links` inside of linked resources.
2014-11-12 15:44:54 -02:00
Alexandre de Oliveira
971f501e55 Bugfix: include nested has_many association
Currently, doing `include: author.bio` would work correctly, but not for
has_many associations such as `include: author.roles`. This fixes it.

The problem was basically that we were not handling arrays for has_many linked,
as happens for ArraySerializers.
2014-11-11 14:35:00 -02:00
Gary Gordon
d97b2f5005 Fix infinite recursion
The method for testing whether to include an association was causing
an infinite loop when two models referenced each other.
2014-11-07 10:03:31 -05:00
Aaron Renoir
fc1562c04a add fields to adapter initialize function, pull in master, add tests using includes with fields 2014-11-05 18:10:37 -08:00
Aaron Renoir
c9c58e31e5 merge upstream/master 2014-11-05 16:47:15 -08:00
Gary Gordon
d5bae0c2f0 Include 'linked' member for json-api collections
The options passed to the render are partitioned into adapter options
and serializer options. 'include' and 'root' are sent to the adapter,
not sure what options would go directly to serializer, but leaving this
in until I understand that better.
2014-11-03 17:13:55 -05:00
Guillermo Iguaran
3bba334cf8 JSON-API: Don't include linked section if associations are empty 2014-10-31 14:30:59 -05:00
Guillermo Iguaran
2d21a8e83f Add type when association name is different than objects type 2014-10-31 01:54:13 -05:00
Guillermo Iguaran
19ac139880 Handle correctly null associations
null belongs_to associations are now serialized as nil instead
of raise an error during serialization.
2014-10-30 09:35:05 -05:00
Aaron Renoir
be54e0bc4f remove serializer dependency from fieldset 2014-10-27 15:24:19 -07:00
Aaron Renoir
34f08477e4 fix tests, but need to understand how the serializer class attribute _associations was getting changed. 2014-10-26 14:41:14 -07:00
Aaron Renoir
39bee48ae6 implement sparse fieldsets http://jsonapi.org/format/#fetching-sparse-fieldsets 2014-10-26 13:04:14 -07:00
Edgars Jekabsons
f9b7c74235 Renamed embed test to have "test" suffix
Fixed reference to association options
2014-10-22 15:30:44 +03:00
Guillermo Iguaran
7c030314cb Serialize ids as strings in JSON-API adapter 2014-10-15 18:56:49 -05:00
Guillermo Iguaran
557b56a50e Refactor adapters to implement support for array serialization 2014-10-15 17:35:50 -05:00
Guillermo Iguaran
188336522f Add support for embed: :ids option for in associations 2014-10-10 16:48:55 -05:00
Alex Genco
0eed2b051a Add "_test" suffix to JsonApi::HasManyTest filename.
"rake test" was previously skipping this file because it didn't have the
proper suffix.
2014-09-14 13:02:09 -07:00
Tema Bolshakov and Dmitry Myaskovskiy
ff37b6260d test for json adapter 2014-08-29 19:40:01 +04:00
Tema Bolshakov
e45e5a82b7 Remove 'Adapter' suffix from adapters since they are in Adapter:: namespace 2014-08-29 11:40:56 +04:00
Tema Bolshakov
6bb4501f67 JsonApi adapter: serialize association 2014-08-29 11:37:27 +04:00
Tema Bolshakov
6496b08464 rename simple adapter to json 2014-08-29 11:01:39 +04:00
Tema Bolshakov
c1fdfc1cdc First try to implement ArraySerializer 2014-08-28 19:16:24 +04:00
Tema Bolshakov
597765e3b0 start implementing json_api adapter to understand how associations should work 2014-08-28 18:55:27 +04:00
Tema Bolshakov
2c7906e9ff Test for NullAdapter#serializable_hash 2014-08-27 09:15:54 +04:00
Tema Bolshakov
7b7d4d8907 Test for SimpleAdapter#serializable_hash 2014-08-27 09:15:07 +04:00
Tema Bolshakov
56725b45a6 Add NullAdapater 2014-08-27 08:41:45 +04:00
Tema Bolshakov
f00fe5595d * Rename NullAdapter to SimpleAdapter
* Introduce abstract Adapter class
* Organaze test structure to match convemtions
2014-08-27 08:21:08 +04:00