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.
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.
Rails 5 removed this assertion after considering it not
a good testing practice. https://github.com/rails/rails/issues/18950
Rather that add a gem to our Rails 5 matrix to support it,
the assertion is made that the template is rendering using
active support notifications.
Also, to clarify that the action 'render_template' is unrelated to the
event name '!render_template.action_view', I renamed the actions
so that would not look like event names.
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
* 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
```
- 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.
As an example, all serializers implement `#object` as a reference to the
object being esrialized, but this was preventing adding a key to the
serialized representation with the `object` name.
Instead of having attributes directly map to methods on the serializer,
we introduce one layer of abstraction: the `_attributes_map`. This hash
maps the key names expected in the output to the names of the
implementing methods.
This simplifies some things (removing the need to maintain both
`_attributes` and `_attribute_keys`), but does add some complexity in
order to support overriding attributes by defining methods on the
serializer. It seems that with the addition of the inline-block format,
we may want to remove the usage of programatically defining methods on
the serializer for this kind of customization.
Also
- Add reference to config from ActiveModelSerializers.config
- correctly call super in FragmentCacheTest#setup
- rename test rails app from Foo to ActiveModelSerializers::RailsApplication