Skip to content

Conversation

@FeLvi-zzz
Copy link

@FeLvi-zzz FeLvi-zzz commented May 6, 2025

resolve #5117
resolve #5311

background

we disable comments, but routes are still drawn.

what to do

  • skip registering ActiveAdmin::Comment if namespace.comments is disabled and resources in namespace are disabled
    • this prevents drawing routes for comments
    • something for model (scope, before_save) are unneeded as well

@FeLvi-zzz FeLvi-zzz marked this pull request as draft May 6, 2025 05:18
@FeLvi-zzz FeLvi-zzz marked this pull request as ready for review May 6, 2025 05:24
@tagliala
Copy link
Contributor

tagliala commented May 6, 2025

Hello,

thanks for this PR

Any chance to add a spec to cover this scenario?

@FeLvi-zzz
Copy link
Author

@tagliala
Hello,

yes, but which file should I add a spec into?
I couldn't find an appropriate one, it looks like there is nothing testing like namespace.register ActiveAdmin::Comment.
I would appreciate if you could let me know where to add.

@tagliala
Copy link
Contributor

tagliala commented May 6, 2025

This looks like a routes spec. There is one under resource

Asking @javierjulio for confirmation

@javierjulio
Copy link
Member

@tagliala I'm not sure actually. @FeLvi-zzz let's give that a try please and we'll go from there.

@FeLvi-zzz
Copy link
Author

@tagliala @javierjulio
I tried to add a spec in spec/unit/comments_spec.rb.
What do you two think about this?

@javierjulio javierjulio force-pushed the not-to-register-activeadmin-comment-if-disabled branch from 375a190 to 34d50b3 Compare October 5, 2025 16:00
@javierjulio
Copy link
Member

@mgrunberg @tagliala what do you think of the this approach and the tests? I think it would help to have as if the feature is not used then the routes should not exist and this seems to handle the case where it's only enabled for a specific namespace or resource. Any improvements or concerns?

@codecov
Copy link

codecov bot commented Oct 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (f79eabd) to head (d81db47).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8710   +/-   ##
=======================================
  Coverage   99.08%   99.08%           
=======================================
  Files         139      139           
  Lines        4046     4047    +1     
=======================================
+ Hits         4009     4010    +1     
  Misses         37       37           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tagliala
Copy link
Contributor

tagliala commented Oct 6, 2025

Sorry, I'm not familiar with the comments implementation.

I can see there is a global switch and a per-resource switch, so this is why it is not checking for config.comments = false.

I also assume that the global config can be override at namespace / model level, so you can have comments false at global level, except for models or namespaces which explicitly set comments to true

I do not have suggestions for the specs

@mgrunberg
Copy link
Contributor

I'm not very familiar with the comments code either, but in a quick review, I'm ok with the approach and specs.

I'm just wondering if it's possible to reduce the usage of stubs/doubles. It's not a strong opinion. It's just that the spec has Namespace & Resource creation examples. I'm aware that we are trying to call a hook and the setup for that could not be easy.

@FeLvi-zzz
Copy link
Author

I reduced excessive stubs (thanks to @mgrunberg !).

Could anyone run tests?

@FeLvi-zzz
Copy link
Author

Oops, tests which I created look flaky...
I'll fix them 🙇

@tagliala
Copy link
Contributor

Hello, this is still failing. Can you also please rabse on master?

@FeLvi-zzz FeLvi-zzz force-pushed the not-to-register-activeadmin-comment-if-disabled branch from cb979b8 to d81db47 Compare November 1, 2025 05:35
Comment on lines +224 to +226
# Manually trigger the before_load, after_load event
ActiveSupport::Notifications.instrument ActiveAdmin::Application::BeforeLoadEvent, { active_admin_application: application }
ActiveSupport::Notifications.instrument ActiveAdmin::Application::AfterLoadEvent, { active_admin_application: application }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't review here, I can'tell if this has side effects

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any other ideas how to test this behavior without too many stubs, do you have the other better one?
If there is no way, many stubs or less ones, which is better?

ref. #8710 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: comment routes appear even when comments are disabled

4 participants