Mark Havekes
4b0c230d76
add failing test and suggestion
2019-06-04 10:27:02 +02:00
Wasif Hossain
807e160b9c
Add missing frozen string literal comment
2019-04-23 04:34:09 +06:00
Wasif Hossain
a9cb097109
Refactoring
2019-04-23 04:34:02 +06:00
Benjamin Fleischer
06fcd34807
Follows https://github.com/rails-api/active_model_serializers/pull/2100
2019-04-23 04:33:56 +06:00
Krzysztof Rybka
873cf4add2
Add frozen_string_literal pragma to ruby files
2018-12-17 16:54:56 +01:00
Konstantin Munteanu
0d3999c36d
Support conditions in link statements
2018-10-25 09:45:34 +02:00
Benjamin Fleischer
00a47d3da4
Prove CI broken ( #2220 )
...
* Remove appveyor rubygems/bundler stuff
* Try specifying different jdbc adapter
* Attempt to fix failing JRuby test I cannot reproduce
```
bundle exec rake ci
Picked up _JAVA_OPTIONS: -Xmx2048m -Xms512m
/home/travis/.rvm/rubies/jruby-9.1.9.0/bin/jruby -w -I"lib:lib:test" -r./test/test_helper.rb -w -I"/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/rake-11.3.0/lib" "/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/rake-11.3.0/lib/rake/rake_test_loader.rb" "test/**/*_test.rb"
ActiveModelSerializers::Adapter::JsonApi::PaginationLinksTest#test_raises_descriptive_error_when_serialization_context_unset [/home/travis/build/rails-api/active_model_serializers/test/adapter/json_api/pagination_links_test.rb:186]:
[] exception expected, not
Class: <ActiveModelSerializers::Adapter::JsonApi::PaginationLinks::MissingSerializationContextError>
Message: <" JsonApi::PaginationLinks requires a ActiveModelSerializers::SerializationContext.\n Please pass a ':serialization_context' option or\n override CollectionSerializer#paginated? to return 'false'.\n">
---Backtrace---
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/adapter/json_api/pagination_links.rb:14:in `block in initialize'
org/jruby/RubyHash.java:1187:in `fetch'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/adapter/json_api/pagination_links.rb:13:in `initialize'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/adapter/json_api.rb:520:in `pagination_links_for'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/adapter/json_api.rb:147:in `success_document'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/adapter/json_api.rb:59:in `serializable_hash'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/adapter/base.rb:59:in `as_json'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/serializable_resource.rb:8:in `as_json'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:69:in `block in as_json'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:117:in `call'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:555:in `block in compile'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:505:in `call'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:498:in `block in around'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:343:in `block in simple'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:22:in `block in instrument_rendering'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:79:in `block in notify_render'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in `block in instrument'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in `instrument'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:78:in `notify_render'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:21:in `block in instrument_rendering'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:97:in `tag_logger'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:20:in `block in instrument_rendering'
org/jruby/RubyBasicObject.java:1724:in `instance_exec'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:441:in `block in make_lambda'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:342:in `block in simple'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:497:in `block in around'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:505:in `call'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:778:in `_run_render_callbacks'
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/travis/build/rails-api/active_model_serializers/lib/active_model_serializers/logging.rb:68:in `block in as_json'
/home/travis/build/rails-api/active_model_serializers/test/adapter/json_api/pagination_links_test.rb:187:in `block in test_raises_descriptive_error_when_serialization_context_unset'
Command failed with status (1): [ruby -w -I"lib:lib:test" -r./test/test_helper.rb -w -I"/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/rake-11.3.0/lib" "/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/rake-11.3.0/lib/rake/rake_test_loader.rb" "test/**/*_test.rb" ]
/home/travis/build/rails-api/active_model_serializers/vendor/bundle/jruby/2.3.0/gems/rake-11.3.0/exe/rake:27:in `<main>'
Tasks: TOP => ci => default => test
(See full trace by running task with --trace)
```
2017-11-13 08:34:56 -06:00
Benjamin Fleischer
3c5e11bb0f
Merge pull request #2216 from rails-api/serialize_resource_with_nil_id
...
Fix: Serialize resource type for unpersisted records (blank id)
2017-11-01 10:36:22 -05:00
Benjamin Fleischer
196216b250
Merge pull request #2212 from rails-api/remove_legacy_embeds
...
Remove legacy has_many_embed_ids test [ci skip]
2017-10-31 14:54:02 -05:00
Benjamin Fleischer
51f2643f40
Style
2017-10-31 14:48:27 -05:00
Benjamin Fleischer
9745a2f735
Fix: ResourceIdentifier.for_type_with_id can serialize unpersisted resources
2017-10-31 14:47:55 -05:00
Benjamin Fleischer
5916014b48
Fix: resource object identifier with nil id excludes id
2017-10-31 14:34:30 -05:00
Benjamin Fleischer
92dde58f5f
Assert serializer-defined types are not inflected
2017-10-31 14:31:33 -05:00
Benjamin Fleischer
82e90091fd
Put the similar jsonapi type tests together
2017-10-31 14:29:09 -05:00
Benjamin Fleischer
b439fe69c6
Refactor jsonapi type/id tests to be more explicit
2017-10-31 14:26:05 -05:00
Benjamin Fleischer
1fd324947f
Remove legacy has_many_embed_ids test
2017-10-29 22:50:59 -05:00
Benjamin Fleischer
0fcb8a6cce
Fix polymorphic belongs_to tests; passes on v0.10.5
2017-10-29 19:26:14 -05:00
Dennis Stumm
4d7c2457d7
Fix deserialization of polymorphic relationships ( #2200 )
...
* Classify the relationship type for polymorphic associations
2017-10-07 17:03:38 -05:00
Alexandre de Oliveira
1e4d117b99
Merge pull request #2149 from mecampbellsoup/more-pagination-links-by-default
...
Always include self, first, last pagination links
2017-06-14 15:47:30 -03:00
mecampbellsoup
402883d84f
Fix Travis lint offenses
2017-06-14 13:35:00 -04:00
mecampbellsoup
92e9a66e97
Amend tests to always include all pagination keys
2017-06-13 12:35:55 -04:00
mecampbellsoup
d8e983604b
Clarify naming of expected response w/ pagination but empty data
2017-06-05 17:51:38 -04:00
mecampbellsoup
7387266c37
Always display self, first, last pagination links
2017-06-05 17:26:41 -04:00
Christian
a89e78c655
Allow referencing sideloaded include by key. ( #2136 )
...
* If a `key` is set on the reflection use the `key` instead of `name`.
This ensures that associations with a key set are still included.
2017-05-18 15:59:14 -05:00
Benjamin Fleischer
93ca27fe44
Merge 0-10-stable into master (to fix breaking change). ( #2023 )
...
* Merge pull request #1990 from mxie/mx-result-typo
Fix typos and capitalization in Relationship Links docs [ci skip]
* Merge pull request #1992 from ojiry/bump_ruby_versions
Run tests by Ruby 2.2.6 and 2.3.3
* Merge pull request #1994 from bf4/promote_architecture
Promote important architecture description that answers a lot of questions we get
Conflicts:
docs/ARCHITECTURE.md
* Merge pull request #1999 from bf4/typos
Fix typos [ci skip]
* Merge pull request #2000 from berfarah/patch-1
Link to 0.10.3 tag instead of `master` branch
* Merge pull request #2007 from bf4/check_ci
Test was failing due to change in JSON exception message when parsing empty string
* Swap out KeyTransform for CaseTransform (#1993 )
* delete KeyTransform, use CaseTransform
* added changelog
Conflicts:
CHANGELOG.md
* Merge pull request #2005 from kofronpi/support-ruby-2.4
Update jsonapi runtime dependency to 0.1.1.beta6
* Bump to v0.10.4
* Merge pull request #2018 from rails-api/bump_version
Bump to v0.10.4 [ci skip]
Conflicts:
CHANGELOG.md
* Merge pull request #2019 from bf4/fix_method_redefined_warning
Fix AMS warnings
* Merge pull request #2020 from bf4/silence_grape_warnings
Silence Grape warnings
* Merge pull request #2017 from bf4/remove_warnings
Fix mt6 assert_nil warnings
* Updated isolated tests to assert correct behavior. (#2010 )
* Updated isolated tests to assert correct behavior.
* Added check to get unsafe params if rails version is great than 5
* Merge pull request #2012 from bf4/cleanup_isolated_jsonapi_renderer_tests_a_bit
Cleanup assertions in isolated jsonapi renderer tests a bit
* Add Model#attributes helper; make test attributes explicit
* Fix model attributes accessors
* Fix typos
* Randomize testing of compatibility layer against regressions
* Test bugfix
* Add CHANGELOG
* Merge pull request #1981 from groyoh/link_doc
Fix relationship links doc
Conflicts:
CHANGELOG.md
2017-01-10 02:28:50 -06:00
Benjamin Fleischer
c25f2f3863
Fix model attributes accessors
2017-01-10 00:41:08 -06:00
Benjamin Fleischer
d5babdd060
Add Model#attributes helper; make test attributes explicit
2017-01-07 21:50:11 -06:00
Benjamin Fleischer
a5423dab20
Merge pull request #2017 from bf4/remove_warnings
...
Fix mt6 assert_nil warnings
2017-01-07 16:26:34 -06:00
Benjamin Fleischer
4dfbe2747b
Fix test bug found by assert_nil
2017-01-06 22:49:50 -06:00
Benjamin Fleischer
6acb4055c9
Fix MT6 assert_nil warnings
2017-01-06 22:06:23 -06:00
Benjamin Fleischer
80af763d2e
Make test attributes explicit
...
- Organize test poros with associations and by serializer
- Freeze derived attributes/associations against mutation
- Cleanup PORO fixtures
2016-12-04 19:33:39 -06:00
Benjamin Fleischer
772b7999c5
Better AMS Model attributes interface
2016-11-21 09:14:26 -06:00
Benjamin Fleischer
c69855bfaa
Improve readability of relationships test ( #1904 )
...
* Really fix intermittent relationship test failures
* Unify the two JSON API relationship test files
I accidentally introduced the duplication when
merging
https://github.com/rails-api/active_model_serializers/pull/1543#issuecomment-193118782
and they've evolved separately since then.
They both have some value and need to be combined.
* Resolve duplicate tests from diverged tests files
* No longer test Association/Relationship interface directly
2016-09-26 09:23:40 -04:00
Lee Richmond
2145540795
Add include_data :if_sideloaded ( #1931 )
...
For JSONAPI, `include_data` currently means, "should we populate the
'data'" key for this relationship. Current options are true/false.
This adds the `:if_sideloaded` option. This means "only
populate the 'data' key when we are sideloading this relationship." This
is because 'data' is often only relevant to sideloading, and causes a
database hit.
Addresses https://github.com/rails-api/active_model_serializers/issues/1555
2016-09-25 12:57:19 -04:00
Lee Richmond
a77dfdaa85
Ensure valid jsonapi when blank relationship ( #1930 )
...
If you specify include_data false, and do not have any links for this
relationship, we would output something like:
`{ relationships: { comments: {} } }`
This is not valid jsonapi. We will now render
`{ relationships: { comments: { meta: {} } } }`
Instead.
Relevant jsonapi spec: http://jsonapi.org/format/#document-resource-object-relationships
2016-09-19 14:10:50 -04:00
Lee Richmond
19b5abf66e
Disable pagination links via config
2016-09-06 15:06:54 -04:00
Benjamin Fleischer
1d4cd6f104
Fix intermittent test failures by not mutating global state
...
e.g.
https://ci.appveyor.com/project/bf4/active-model-serializers/build/415/job/qs8895cvla8fl0rf
1) Failure:
ActiveModel::Serializer::Adapter::JsonApi::RelationshipTest#test_relationship_including_data_explicit
[C:/projects/active-model-serializers/test/adapter/json_api/relationships_test.rb:186]:
--- expected
+++ actual
@@ -1 +1 @@
-{:data=>{:id=>"1337", :type=>"authors"}, :meta=>{:name=>"Dan Brown"}}
+{:data=>{:id=>"1337", :type=>"authors"
https://travis-ci.org/rails-api/active_model_serializers/jobs/156678147
1) Failure:
ActiveModel::Serializer::Adapter::JsonApi::RelationshipTest#test_relationship_with_everything
[/home/travis/build/rails-api/active_model_serializers/test/adapter/json_api/relationships_test.rb:200]:
--- expected
+++ actual
@@ -1 +1 @@
-{:data=>[{:id=>"1337", :type=>"likes"}],
:links=>{:related=>{:href=>"//example.com/likes/1337",
:meta=>{:ids=>"1337"}}}, :meta=>{:liked=>true}}
+{:data=>[{:id=>"1337", :type=>"likes"}],
:links=>{:related=>{:href=>"//example.com/likes/1337",
:meta=>{:ids=>"1337"}}}}
2016-08-31 19:24:21 -05:00
Benjamin Fleischer
20e394d512
Refactor Association into Field like everything else ( #1897 )
...
* Make assocations asserts easier to understand
* Refactor Association into Field like everything else
* Make assocation serializer/links/meta lazier
* Push association deeper into relationship
* Simplify association usage in relationships
* Better naming of reflection parent serializer
* Easier to read association method
2016-08-31 09:35:41 -04:00
Ian C. Anderson
2423ca4999
Support key transformation for Attributes adapter ( #1889 )
...
The `:attributes` adapter is the default one, but it did not support
key transformation. This was very surprising behavior, since the
"Configuration Options" page in the guides didn't mention that this
behavior was not supported by the attributes adapter.
This commit adds key transform support to the attributes adapter, and
adds documentation about the default transform for the attributes
adapter (which is `:unaltered`).
This commit also handles arrays when transforming keys, which was needed
in the case where you're serializing a collection with the Attributes
adapter. With the JSON adapter, it was always guaranteed to pass a hash
to the KeyTransform functions because of the top-level key. Since there
is no top-level key for the Attributes adapter, the return value could
be an array.
2016-08-25 15:21:27 -04:00
Benjamin Fleischer
455068d455
Merge pull request #1884 from bf4/simplify_relationship
...
* Simplify Relationship
2016-08-17 16:18:14 -05:00
L. Preston Sego III
a319fef239
Add tests for fields option demonstrating usage on both attributes and relationships ( #1839 )
...
* add test for fields whitelisting relationships, and use the JSON API Include Directive to do the heavy lifting
2016-08-17 16:12:12 -05:00
Benjamin Fleischer
abb15b9622
Simplify Relationship
2016-08-17 15:58:11 -05:00
L. Preston Sego III
6de3f31b6e
Namespace separator setting for json-api and tests ( #1874 )
...
Adds jsonapi_namespace_separator configuration
Also:
* Enable getting type from record class without serializer
Needs Followup:
- https://github.com/rails-api/active_model_serializers/pull/1874#discussion_r74607042
- https://github.com/rails-api/active_model_serializers/pull/1874#discussion_r74607734
2016-08-12 12:54:42 -05:00
L. Preston Sego III
aa4d89ab47
remove dynamic class creation where not needed ( #1850 )
...
* remove dynamic class creation where not needed
2016-07-18 14:11:09 -05:00
Yohan Robert
9a206a1f5d
Remove nil relationships links ( #1833 )
2016-07-12 14:02:34 +02:00
Alexey Dubovskoy
800221ed90
re: RuboCop - replace rocket style hashes
2016-06-21 22:08:27 +01: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
Alexey Dubovskoy
004f1437d8
re: RuboCop - hash indention corrections
2016-06-20 22:13:21 +01:00
Alexey Dubovskoy
f15f6850de
re: RuboCop: Bulk minor style corrections
2016-06-20 22:12:16 +01:00