Skip to content

Migrate view helpers to app/helpers path#8202

Merged
javierjulio merged 22 commits into
masterfrom
helpers-migration
Jan 1, 2024
Merged

Migrate view helpers to app/helpers path#8202
javierjulio merged 22 commits into
masterfrom
helpers-migration

Conversation

@javierjulio

@javierjulio javierjulio commented Jan 1, 2024

Copy link
Copy Markdown
Member

This migrates the view helpers from lib to the app/helpers directory like done in other gems and for a modern Rails approach. These methods were already being set as view helpers but this makes it a little easier to test through a plain helper spec and gives us autoloading in development. We'll be adding new helper methods for common actions (e.g. can view show resource link, etc.) so these changes will help.

This is a single method and used in the layout. No need to call with_indifferent_access anymore as it supports that access already.
@javierjulio javierjulio self-assigned this Jan 1, 2024
@codecov

codecov Bot commented Jan 1, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9db27b6) 99.03% compared to head (7aa0a90) 99.12%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8202      +/-   ##
==========================================
+ Coverage   99.03%   99.12%   +0.09%     
==========================================
  Files         149      144       -5     
  Lines        4127     4104      -23     
==========================================
- Hits         4087     4068      -19     
+ Misses         40       36       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Removing the `require "active_admin/view_helpers/method_or_proc_helper"` in `lib/active_admin/filters.rb` hid a loading bug with `lib/active_admin/resource.rb` since some of its classes use helper methods from method_or_proc_helper (e.g. scopes, action_items, etc.) but included the module without requiring it. We now require it at the top of the resource file.

This brings together the original form_helper and fields_for file which the latter oddly didn't declare a different module but used form helper instead.

Since the filter form helper spec included a lot of tests, we'll keep this spec separate from form helper despite being in the same one.
No need to include this in the page controller since specific to index view scopes/filters.
Several methods in DisplayHelper are only used internally and private so now marked as private.

The pretty_format spec is now included in the display helper spec.
This was updated in https://github.com/activeadmin/activeadmin/pull/5611/files#diff-bafdb16f12eab7769801ce340a4bd6930e82b9cb8546db3f11ec5f7b6e50986e so the module used extend self but we can use helpers here since its in a controller. The helper module was already being included in the base controller.

We can't remove the `extend self` portion yet without additional changes.
The MethodOrProcHelper still has to live in lib for now as having a hard time getting it to work in app/helpers with its use in resource/menu item classes.
This way we remove the only reference to a MethodOrProcHelper method (in this case render_or_call_method_or_proc_on) which is considered a private API from a view template that the host app can copy.
In Devise templates, the active_admin_namespace helper won't be available so we need to use active_admin_application but in the admin itself, we have to use the namespace to support site title that can be configured by namespace.

We didn't have tests beforehand, even previous release, to cover this case so this adds a feature spec that was failing pre-fix and passing post-fix.
These are already covered by feature specs but helps to have some simple unit tests in place.
@javierjulio javierjulio merged commit 601337e into master Jan 1, 2024
@javierjulio javierjulio deleted the helpers-migration branch January 1, 2024 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant