Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Set to collect callbacks in OnPageLayout #1583

Merged
merged 1 commit into from
May 23, 2019

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented May 11, 2019

What is this pull request for?

When using the OnPageLayout mixin outside the ApplicationController
(because one might want to run define those methods only in certain
controllers and not in others), AND using an
ActiveSupport::Concern-style mixin to do that, AND including that
mixin in multiple controllers, one ends up with the callback or block
called multiple times. Using a Set instead of an Array neatly
circumvents this issue, as it will only add new unique callbacks.

Unfortunately, there is not a good way to test this, as running the
on_page_layout class method in any controller will expect the
Alchemy::PagesControllerto have a callback defined, and the test setup
for this spec would make many other specs fail.

Ideally, the Set of Callbacks would not be stored in a module instance
variable on the OnPageLayout module, but on the including controller.
That way the functionality (which is extremely useful!) could be scoped
a little more.

When using the OnPageLayout mixin outside the ApplicationController
(because one might want to run define those methods only in certain
controllers and not in others), AND using an
`ActiveSupport::Concern`-style mixin to do that, AND including that
mixin in multiple controllers, one ends up with the callback or block
called multiple times. Using a `Set` instead of an Array neatly
circumvents this issue, as it will only add new unique callbacks.

Unfortunately, there is not a good way to test this, as running the
`on_page_layout` class method in any controller will expect the
`Alchemy::PagesController`to have a callback defined, and the test setup
for this spec would make many other specs fail.

Ideally, the Set of Callbacks would not be stored in a module instance
variable on the `OnPageLayout` module, but on the including controller.
That way the functionality (which is extremely useful!) could be scoped
a little more.
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Thanks. That makes sense

@tvdeyen tvdeyen added this to the 4.2 milestone May 23, 2019
@tvdeyen tvdeyen merged commit 5ff0e88 into AlchemyCMS:master May 23, 2019
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.

2 participants