Commit Graph

146 Commits

Author SHA1 Message Date
Ben Mills
3498647d1a Apply key transforms to keys referenced in values 2016-04-04 10:16:04 -06:00
Benjamin Fleischer
fa7b3afbfd Prefer explicitly yielding the serializer, per groyoh 2016-03-30 14:01:28 -05:00
Benjamin Fleischer
ae6805eacd Add serializer to association block context 2016-03-30 11:03:38 -05: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
fb06a462bb Fix warnings 2016-03-25 10:28:13 -05:00
Ben Mills
9e992358d8 Merge pull request #1574 from remear/key-casing
Provide key transformation
2016-03-15 13:42:24 -06:00
Marc Garreau
045fa9bc07 Adds polymorphic tests and documentation 2016-03-15 13:09:59 -06: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
Ben Morrall
b5dd90c8f9 Fixed pagination issue with last page size 2016-03-10 09:30:29 +11: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
Benjamin Fleischer
6b4c8df6fb Clean up test deprecation warnings 2016-03-06 23:35:22 -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
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
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
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
c2eace3468 Fix deprecation warning
Fix the "Calling deprecated ArraySerializer... Please use
CollectionSerializer" warning that appeared when running the specs. This
happened because on of the test called ArraySerializer instead of
CollectionSerializer.
2016-02-19 10:13:54 +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
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
Benjamin Fleischer
1cc2e04cf6 Address issues in 50950d9533 #1340
- Add changelog entry
- Remove superseded and incorrect tests
- Fix array serialization test
2016-02-08 18:14:25 -06:00
Benjamin Fleischer
50950d9533 Merge branch 'beauby-resource-level-meta'
Followup concerns:
- https://github.com/rails-api/active_model_serializers/pull/1340/files#r47451387
- https://github.com/rails-api/active_model_serializers/pull/1340/files#r48116963
- https://github.com/rails-api/active_model_serializers/pull/1340#discussion_r47451387
- https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-164306882
- https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-166202978
- https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-173028896
2016-02-08 18:00:51 -06:00
Benjamin Fleischer
5b953ff40f Address concerns from #1018 commit c59668e 2016-02-08 17:55:15 -06:00
Benjamin Fleischer
c59668e7a8 Merge branch 'leandrocp-add-top-level-links'
Needs followup
- https://github.com/rails-api/active_model_serializers/pull/1018#discussion_r51733900
- https://github.com/rails-api/active_model_serializers/pull/1018#discussion_r51734779
- https://github.com/rails-api/active_model_serializers/pull/1018#discussion_r51735145
- https://github.com/rails-api/active_model_serializers/pull/1018#discussion_r51735218
2016-02-08 17:44:05 -06:00
Leandro Cesquini Pereira
37e4f1c30c Update top-level link with PR #1247
update according rubocop rules
2016-02-03 10:16:22 -02:00
Leandro Cesquini Pereira
1844c162f1 Adds support for top-level links to JsonApi adapter
http://jsonapi.org/format/#document-top-level

fix failing tests

support for top-level links limited to jsonapi adapter

Move docs from README to docs/ dir

move links to json-api adapter & create Links class to hold links data
2016-02-03 10:16:22 -02:00
Lucas Hosseini
061f1c0f59 Add support for relationship-level links and meta. 2016-01-21 02:36:54 +01:00
Rafael Chacón
207c85f0fd Add tests for meta on resource objects. 2016-01-20 00:49:46 +01:00
Lucas Hosseini
30d8414cce Add support for dynamic string-links in JsonApi adapter. 2016-01-15 14:36:42 +01:00
Lucas Hosseini
20a58d7f5c Add support for JSON API deserialization (experimental). 2016-01-13 05:48:06 +01: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
ce17a1b305 [DOCS] Refactor, update, create documentation [ci skip] 2015-12-14 14:38:29 -06:00
Benjamin Fleischer
a9ce4fb766 Move caching initialization to Railtie
Also
- Add reference to config from ActiveModelSerializers.config
- correctly call super in FragmentCacheTest#setup
- rename test rails app from Foo to ActiveModelSerializers::RailsApplication
2015-11-25 21:56:01 -06:00
tchak
31172b1be5 rename context to serialization_context 2015-11-07 20:32:27 +01:00
Lucas Hosseini
3804dcc238 Add support for resource-level JSON API links. 2015-11-03 23:50:16 +01:00
L. Preston Sego III
17be650538 Revert "rename context to serialization_context and add url helpers" 2015-10-29 08:16:47 -04:00
L. Preston Sego III
a063cbea21 Merge pull request #1289 from tchak/serialization_context
rename context to serialization_context and add url helpers
2015-10-29 07:56:47 -04:00
Lucas Hosseini
13ef8fed1b Fix fields option to restrict relationships as well. 2015-10-24 21:28:13 +02:00
tchak
d08ee5994f rename context to serialization_context and add url helpers 2015-10-22 22:28:54 +02: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
João Moura
da7e6dc795 Merge pull request #1247 from beauby/jsonapi-toplevel-links
Add support for toplevel JSON API links.
2015-10-10 17:52:08 -03:00