this uses the configuration settings rather than calling ActionController::Base to get the configured values.
after the "action_controller.set_configs" initializer has run, the configuration option holds the value Base will get when it loads.
- use hook_for to hook in the serializer and remove load_generators
- move generators so they can be found by rails
- move to_prepare block to railtie config
This commit improves the way the generators are loaded and how
they extend the resource generator.
* The initializer block has been changed to a `generator` block which is only executed when generators are needed.
* The call to `app.load_generators` has been removed. There is no need to load *all* generators.
* The `resource_override.rb` has been changed to use `hook_for` to extend the resource generator.
* The directory for the generators has been moved to match the way Rails looks to load generators.
With `hook_for` it would now be possible for a user to pass `--no-serializer` to skip that option.
The `--serialize` option also now shows up in the generator help with `rails g resource --help`.
These changes follow the way the Draper gem extends the `controller` generator.
In 0.9 (which this implementation is based on), the instrumentation
was `!serialize.active_model_serializers`.
https://github.com/rails-api/active_model_serializers/pull/596/
The '!' in the event name meant the event wasn't meant for
production.
https://github.com/rails/rails/pull/10446/files#r4075679
Since we intend the event for production and have a log subscriber,
if we unsubscribe from `render.active_model_serializers`, we'll
break other tests that are relying on that event being subscribed.
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
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.
* 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
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
```
The ActiveModelSerializers.silence_warnings was used to avoid warnings on the
Ruby interpreter when define a private attr_acessor. This method is not used in
any part of the code and the recommend way to handle this case is to use
protected instead the silence_warnings [1].
This patch remove the method from the project, this way we avoid people using
this by mistake.
[1]: https://bugs.ruby-lang.org/issues/10967
- 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.