Commit Graph

70 Commits

Author SHA1 Message Date
Benjamin Fleischer
527c2aed98 Update changelog [ci skip]
For https://github.com/rails-api/active_model_serializers/pull/1458
2016-02-09 22:38:48 -06:00
Benjamin Fleischer
2789cc5221 Test CachedSerializer#fragment_cached? 2016-02-09 22:31:59 -06:00
Benjamin Fleischer
fe6d2da46f Add missing changelog for #1454 [ci skip] 2016-02-08 18:17:33 -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
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
Benjamin Fleischer
020db79a09 Merge pull request #1501 from domitian/testcases-documentation-fix
Added testcases for serializable_resource and fixed a documentation error regarding adapter key constant
2016-02-08 12:31:56 -06:00
bobba surendranath chowdary
68f09e59c4 Fixed a documentation error regarding adapter key constant, added tests
for SerializableResource::use_adapter?
2016-02-08 15:27:56 +05:30
Benjamin Fleischer
a18c99fe87 Fix typo in changelog link ref [ci skip] 2016-02-07 22:19:24 -06: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
Nate Sullivan
3c1fe0fd0f Require ActiveSupport's string/inflections
We depend on string/inflections to define String#underscore.
2016-01-31 13:45:58 -08:00
Benjamin Fleischer
f5ec8ed9d4 Reset Changelog [ci skip] 2016-01-28 21:02:40 -06:00
João M. D. Moura
58ff7535b7 releaseing new version RC4 2016-01-27 10:03:01 -05:00
Alexandre de Oliveira
dfd22ad860 Merge pull request #1444 from bf4/serializer_prehistory
Why rails renderers are only sentinels for a method; not lookups [ci skip]
2016-01-25 19:57:41 -02:00
Alexandre de Oliveira
ef58efdf73 Merge pull request #1418 from brigade/collection-pluralize
Don't pluralize the CollectionSerializer#root for #json_key
2016-01-25 19:46:47 -02:00
Benjamin Fleischer
f056ef34e2 Why rails renderers are only sentinels for a method; not lookups 2016-01-18 23:38:12 -05:00
Benjamin Fleischer
8981683b9f Merge pull request #1352 from bf4/railties
Fix generators (@dgynn); load Railtie only with Rails, ensures caching configured
2016-01-18 23:24:40 -05:00
Lucas Hosseini
30d8414cce Add support for dynamic string-links in JsonApi adapter. 2016-01-15 14:36:42 +01:00
Benjamin Fleischer
58a74d064e Add CHANGELOG 2016-01-15 01:58:14 -06:00
Benjamin Fleischer
47f6db203c Touchup Changelog 2016-01-15 01:05:31 -06:00
CorainChicago
8ffcdc7668 update CHANGELOG 2016-01-15 01:05:31 -06:00
Mauro George
5058694f4a Create assert_response_schema test helper
It is a common pattern to use JSON Schema to validate a API response[1], [2]
and [3].

This patch creates the `assert_response_schema` test helper that helps people do
this kind of validation easily on the controller tests.

[1]: https://robots.thoughtbot.com/validating-json-schemas-with-an-rspec-matcher
[2]: https://github.com/sharethrough/json-schema-rspec
[3]: https://github.com/rails-api/active_model_serializers/issues/1011#issuecomment-127608121
2016-01-15 00:45:56 -06:00
Mauro George
c0b99c980c Bring back assert_serializer for controller testing
The `assert_serializer` test helper was added in 0.9.0.apha1[1],
and was not included in 0.10.

This patch brings back the `assert_serializer` test helper. This is the last
revision[2] that has the helper. The original helper was used as base.

[1]: https://github.com/rails-api/active_model_serializers/pull/596
[2]: 610aeb2e92

- Create the AssertSerializer

- Use the Test namespace

- Make the tests pass on the Rails master
  - Rails 5 does not include `assert_template` but we need this on the tests of
the helper.
  - This add the `rails-controller-testing` to keep support on `assert_template`.

- Only load test helpers in the test environment
2016-01-13 20:54:22 -06:00
Lucas Hosseini
6860318133 Add support for if/unless on associations. 2016-01-13 06:19:47 +01:00
Lucas Hosseini
20a58d7f5c Add support for JSON API deserialization (experimental). 2016-01-13 05:48:06 +01:00
Ben Woosley
251e33a0a1 Don't pluralize the CollectionSerializer#root for #json_key
One of three constituents is used to provide the
CollectionSerializer's #json_key:

1) the :root option - controlled by the caller
2) the #name of the first resource serializer - the root or
   underscored model name
3) the underscored #name of the resources object - generally
   equivalent to the underscored model name of #2

Of the three, only the latter 2 are out of the callers control, and
only the latter two are expected to be singular by default. Not
pluralizing the root gives the caller additional flexibility in
defining the desired root, whether conventionally plural,
unconventionally plural (e.g. objects_received:) or singular.
2016-01-12 09:32:43 -08:00
Benjamin Fleischer
7d4f0c5c8a Merge branch 'bf4-consider_association_blocks' 2016-01-03 23:16:49 -06:00
Benjamin Fleischer
41ae5f7b6f Add 1356 to changelog; given credit for 1336 2016-01-03 23:14:38 -06:00
Benjamin Fleischer
81b1654c4e Merge pull request #1388 from bf4/restore_docs_from_older_releases
Restore docs from older releases
2016-01-03 23:10:41 -06:00
Lucas Hosseini
ccb05f11ef Add changelog. 2015-12-30 17:46:29 +01: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
fd98349c54 Add some pre-history [ci skip] 2015-12-23 09:56:07 -06:00
Benjamin Fleischer
965e846bcb Add CHANGELOG from 0.9
https://github.com/rails-api/active_model_serializers/blob/0-9-stable/CHANGELOG.md
2015-12-23 09:45:45 -06:00
Benjamin Fleischer
24549b2eee Update CHANGELOG from 0.8
https://github.com/rails-api/active_model_serializers/blob/0-8-stable/CHANGELOG.md
2015-12-23 09:45:45 -06:00
Benjamin Fleischer
fce856fc83 Merge pull request #1371 from bf4/documentation_updates
[DOCS] Refactor, update, create documentation
2015-12-20 22:30:44 -06:00
Benjamin Fleischer
30fd9d9eb7 Merge pull request #1353 from bf4/disable_serializer_lookup
Allow users to globally opt out of automatic serializer lookup
2015-12-20 20:04:16 -06:00
Benjamin Fleischer
dff607dc41 Merge pull request #1336 from johnhamelink/master
Grape formatter feature requested in #1258 - Rebased and Repushed (#1273)
2015-12-17 20:31:38 -06:00
Benjamin Fleischer
ce17a1b305 [DOCS] Refactor, update, create documentation [ci skip] 2015-12-14 14:38:29 -06:00
Benjamin Fleischer
60ac749edf Cleanup CHANGELOG 2015-12-14 14:21:55 -06:00
Mauro George
488370fc0b Drop support to Ruby 1.9.3 2015-12-14 14:18:29 -06:00
Kara Carrell
850ac3feaf drop support to Ruby 1.9.3 from build matrix 2015-12-14 14:18:06 -06:00
Julian Paas
d85a17bb33 Grape formatter feature requested in #1258
- adds handling for when the returned resource is not serializable via ams
 - fix for when resource is an Array
 - Moves grape include to grape namespace. Changes Enumerable to Array because a plain hash is enumerable.
 - Add integration test
 - Refine scope of Grape version dependency
 - Assert that the response is equal to a manually defined JSON string
 - Add single module to include in Grape projects
 - Create a Serializable Resource to test rails-api from Grape
 - Update docs
 - Fix discrepency between ActiveRecord 4.0 - 4.1 and 4.2
 - Updated Changelog
 - Remove parens from `render`, use `serializable` in all tests.
2015-12-10 10:06:40 +00:00
Johnathan Ludwig
269e11f360 Update links to point to correct PRs 2015-12-04 16:10:29 -05:00
Randy Stauner
90fa377040 Match file paths with spaces in caller regexp 2015-12-02 06:17:34 -07:00
Benjamin Fleischer
28394340d8 Add config.serializer_lookup_enabled that defaults true 2015-11-30 00:20:58 -06:00
Mauro George
51424963da ActiveSupport::Notifications render.active_model_serializers
Squashed commits:

Add Logging

Generates logging when renders a serializer.

Tunning performance on notify_active_support

- Use yield over block.call
- Freeze the event name string

Organize the logger architeture

* Keep only the `ActiveModel::Serializer.logger` to follow the same public API we
  have for example to config, like `ActiveModel::Serializer.config.adapter` and
  remove the `ActiveModelSerializers.logger` API.
* Define the logger on the load of the AMS, following the Rails convention on
  Railties [1], [2] and [3].

This way on non Rails apps we have a default logger and on Rails apps we will
use the `Rails.logger` the same way that Active Job do [4].

[1]: 2ad9afe4ff/activejob/lib/active_job/railtie.rb (L9-L11)
[2]: 2ad9afe4ff/activerecord/lib/active_record/railtie.rb (L75-L77)
[3]: 2ad9afe4ff/actionview/lib/action_view/railtie.rb (L19-L21)
[4]: 2ad9afe4ff/activejob/lib/active_job/logging.rb (L10-L11)

Performance tunning on LogSubscriber#render

Move the definition of locals to inside the `info` block this way the code is
executed only when the logger is called.

Remove not needed check on SerializableResource

Use SerializableResource on ActionController integration

On the ActionController was using a adapter, and since the instrumentation is
made on the SerializableResource we need to use the SerializableResource over
the adapter directly. Otherwise the logger is not called on a Rails app.

Use SerializableResource on the ActionController, since this is the main
interface to create and call a serializer.

Using always the SerializableResource we can keep the adapter code more easy to
mantain since no Adapter will need to call the instrumentation, only the
SerializableResource care about this.

Add docs about logging

Add a CHANGELOG entry

Keep the ActiveModelSerializers.logger

Better wording on Logging docs

[ci skip]

Add doc about instrumentation

[ci skip]

Use ActiveModel::Callbacks on the SerializableResource
2015-11-10 03:09:24 -06:00
Benjamin Fleischer
2c8b9b796d Rename ArraySerializer to CollectionSerializer for clarity 2015-10-21 16:53:26 -05:00
L. Preston Sego III
6018ef16c4 Merge pull request #1225 from beauby/nested-serializer-lookup
Add support for nested serializers
2015-10-09 10:12:08 -04:00
Lucas Hosseini
9147469842 Extend serializer lookup to the parent serializer. 2015-10-08 18:23:54 +02:00
Lucas Hosseini
f4bb4c81b0 Fix duplicate resources between data and included. 2015-10-06 17:25:27 +02:00