Commit Graph

44 Commits

Author SHA1 Message Date
Avon
3ad2457aaf Bugfix/redefine associations on inherited serializers (#1848)
* replace reflection collection type with hash to prevent duplicated associations in some cases

* include tests

* Fix robucup offenses

* Improve test

* Remove usless requirement

* improve tests

* remove custom_options option from Post and InheritedPost serializer

* Improve tests

* update changelog

* update changelog
2016-07-17 16:25:43 -04:00
Alexey Dubovskoy
13015680a7 re: RuboCop - get rid of redundant curly braces around a hash parameter 2016-06-20 22:14:39 +01:00
Alexey Dubovskoy
024b2d51d3 re: RuboCop - replace rocket style hashes 2016-06-20 22:14:12 +01:00
Fumiaki MATSUSHIMA
aa087a22b5 String/Lambda support for conditional attributes/associations 2016-04-26 21:37:25 +09:00
Benjamin Fleischer
a26d3e4425 Rubocop autocorrect 2016-03-08 22:32:34 +01:00
Lucas Hosseini
061f1c0f59 Add support for relationship-level links and meta. 2016-01-21 02:36:54 +01:00
Lucas Hosseini
7af198653d Add tests for conditional attributes/associations. 2016-01-13 06:20:05 +01:00
Ben Woosley
0a6c133d25 Tidy up the tests
* Use assert_nil where appropriate
* Lead with the expected value in collection_serializer_test.rb, etc
 so that expected/actual in test failure messages are not reversed
2016-01-07 11:21:19 -08:00
Benjamin Fleischer
7d4f0c5c8a Merge branch 'bf4-consider_association_blocks' 2016-01-03 23:16:49 -06:00
Benjamin Fleischer
d7de53ce30 Consider evaluating association in serializer context
For discussion:

Consider evaluating association in serializer context

That way, associations are really just anything that
can be conditionally included.  They no longer
have to actually be methods on the object or serializer.

e.g.

```diff
has_many :comments do
- last(1)
+ Comment.active.for_serialization(object).last(1)
end
```
2015-12-29 22:16:42 -06:00
Benjamin Fleischer
419faf03b9 Favor ActiveSupport::TestCase over Minitest::Test
- Better minitest 4/5 support
- Better DSL
- Already available with no changes
- Consistent interface
2015-12-22 10:35:51 -06:00
Benjamin Fleischer
9909908962 Merge pull request #1384 from bf4/fix_ci_failures
Fix db state leaking across tests
2015-12-21 17:23:04 -06:00
Benjamin Fleischer
58937f4969 Clear out created db records after test 2015-12-20 15:02:16 -06:00
Benjamin Fleischer
ce17a1b305 [DOCS] Refactor, update, create documentation [ci skip] 2015-12-14 14:38:29 -06:00
Benjamin Fleischer
386a567dfc Evaluate association blocks as scopes on the association 2015-12-04 13:58:22 -06:00
Benjamin Fleischer
e2903643c5 Encapsulate serialized_associations; test inline associations 2015-12-02 17:20:22 -06:00
Benjamin Fleischer
2c8b9b796d Rename ArraySerializer to CollectionSerializer for clarity 2015-10-21 16:53:26 -05:00
Benjamin Fleischer
124faaa829 Add PORO serializable base class: ActiveModelSerializers::Model 2015-10-14 21:33:02 -05:00
Lucas Hosseini
9147469842 Extend serializer lookup to the parent serializer. 2015-10-08 18:23:54 +02:00
Benjamin Fleischer
839d1ab21c Remove dead code 2015-09-21 09:41:54 -05:00
Benjamin Fleischer
228cc1c92a Rubocop: Consistent spacing 2015-09-03 20:51:40 -05:00
Benjamin Fleischer
bdfe13c527 Style/StringLiterals single quote all the things 2015-09-03 20:50:45 -05:00
Lucas Hosseini
c5446d759f Remove traces of embed option. 2015-08-31 01:26:22 +02:00
Benjamin Fleischer
d315151e8a Fix warnings
JRuby-specific: fix 'warning: (...) interpreted as grouped expression'
2015-08-26 09:22:02 -05:00
Артём Большаков
2952a332e0 Associations refactoring
* Move all associations related code from Serializer class to Associations module
* Introduce Reflection class hierarchy
* Introduce Association class
* Rid off Serializer#each_association
* Introduce Serializer#associations enumerator
2015-07-30 11:20:29 +03:00
Rodrigo Ra
df63b59512 Add key option to serializer associations 2015-07-05 19:47:58 -03:00
Benjamin Fleischer
17d560eae4 Account for different handling of symbol keys in Rails 4.0
Comparing as a JSON string vs. as the Hash that is convert to JSON
works around the different Hash representations.

This likely has to do with the introduction of
config.action_dispatch.perform_deep_munge in Rails 4.1
See Rails issue 13420

  1) Failure:
  ActiveModel::Serializer::Adapter::Json::HasManyTestTest#test_has_many_with_no_serializer
  [active_model_serializers/test/adapter/json/has_many_test.rb:36]:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -{:id=>42, :tags=>[{"attributes"=>{"id"=>1, "name"=>"#hash_tag"}}]}
  +{:id=>42, :tags=>[{"attributes"=>{:id=>1, :name=>"#hash_tag"}}]}

  2) Failure:
  ActiveModel::Serializer::AssociationsTest#test_has_many_with_no_serializer
  [active_model_serializers/test/serializers/associations_test.rb:74]:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -[{"attributes"=>{"name"=>"#hashtagged"}}]
  +[{"attributes"=>{:name=>"#hashtagged"}}]
2015-06-26 02:16:35 -03:00
João Moura
741c4a4b51 updating tests to work with new virtual_value implementation 2015-06-26 02:16:35 -03:00
Benjamin Fleischer
cf77786da2 Fix #955 2015-06-26 02:16:34 -03:00
Justin Aiken
3710c32cee Add some failing tests around has_many assocs...
..where no serializer is defined for the thing that is has_many'd
2015-06-26 02:16:34 -03:00
Yohan Robert
02ffff599f Serializers now inherit attributes 2015-04-23 13:25:36 +02:00
Alexandre de Oliveira
af81a403e3 Passes serializer options down into associations 2015-03-11 16:37:14 -03:00
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
e47231cdc8 Support overriding association methods
You can override associations to define custom scope on them.
2015-01-29 16:52:18 -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
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
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
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
Tema Bolshakov and Dmitry Myaskovskiy
71a43a432a Pass options to associations 2014-08-29 20:16:11 +04:00
Tema Bolshakov
c1fdfc1cdc First try to implement ArraySerializer 2014-08-28 19:16:24 +04:00
Tema Bolshakov
466c7d5dd8 Wrap association into Serializers 2014-08-28 18:46:19 +04:00
Tema Bolshakov
fa4ee9d645 Add Serializer#associations 2014-08-27 11:21:01 +04:00
Jordan Faust
00f7cab864 Add DSL for assocations 2014-08-23 15:20:48 -05:00