diff options
| author | Teddy Wing | 2017-06-14 17:50:00 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-14 17:50:00 +0200 |
| commit | b616626283a5e24d2b9996669c0978787229d9db (patch) | |
| tree | 35a985fc954467150f9e38fd5f9294768aec6e36 /script | |
| parent | 986f3bc5a785998d9832bdcdf3e570040fd34185 (diff) | |
| download | chouette-core-b616626283a5e24d2b9996669c0978787229d9db.tar.bz2 | |
TableBuilder: Extract custom action link methods to a new class
Move `#action_links`, `#action_link_method`, and
`#actions_after_policy_check` to a new class. They all depend on an
action and/or a model object, so it made sense to group these together.
Also, these should really be tested, and moved out of a private method
context. They now live in `TableBuilderHelper::CustomLinks`.
The advantage is that we now have these methods grouped together in a
separate module that can be tested separately.
Needed to change some things around now that they're in a class:
* `obj` and `action` are now instance variables
* In order to call Pundit's `policy` method, we have to call it directly
on `Pundit`, since we're no longer in the context of a
helper/controller/view.
* Create a `UserContext` that can be passed to Pundit based on the one
created in `ApplicationController`.
* Rename some methods to make more sense in this new context.
* Move `actions_to_http_methods` to a class constant, so we're not
redefining it in every call to `method_for_action`.
* Use `I18n.t` instead of `t` alone, otherwise getting the translation
doesn't work.
* Move `TableBuilderHelper#polymorphic_url_parts` to a new class
`TableBuilderHelper::URL`. This enables us to use it in both
`CustomLinks` and the `TableBuilderHelper`. We can't use it from
`CustomLinks` if it's a public method in `TableBuilderHelper`, and we
can't use it in `TableBuilderHelper#tbody` if it's a class method in
`TableBuilderHelper`.
There's a problem with the action symbols that aren't directly handled
in `actions_after_policy_check`. The `:show` action was passed by the
workbenches/show.html.slim template, but it doesn't appear in the
resulting output even though it should.
Refs #3479
Diffstat (limited to 'script')
0 files changed, 0 insertions, 0 deletions
