-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Check if path is a Resolver before decorating it #1551
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
Conversation
@@ -81,7 +81,11 @@ def append_view_path(new_path) | |||
private | |||
|
|||
def _path_decorator(path) | |||
EmptyTemplateResolver.new(path) | |||
if path.is_a?(::ActionView::Resolver) | |||
path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? If the point here is nullify view rendering surely it's better to continue to ignore this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #1535 switched form using EmptyTemplatePathSetDecorator
, a subclass of ActionView::Resolver
, to using EmptyTemplateResolver
, a subclass of ActionView::FileSystemResolver
. This means that when I have called prepend_view_path
with a Resolver
instance instead of a string/path argument, I run into this error: path already is a Resolver class
from FileSystemResolver#initialize
: https://github.com/rails/rails/blob/v4.2.5.1/actionview/lib/action_view/template/resolver.rb#L324-L329
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit, I wasn’t entirely sure what EmptyTemplateResolver
does. It seems to change the found templates to templates that look identical, but that always render an empty string when call
ed.
I guess the same behavior can be applied if path
is an instance of ActionView::Resolver
. But we need to change the superclass of EmptyTemplateResolver
to be ActionView::Resolver
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we're trying to do is prevent the templates rendering, maybe this fix should be bypassing that check within empty template resolver?
/cc @pixeltrix is this actually something we want? |
I pushed another commit, which moves the type check into the Is @pixeltrix Your opinion would be very welcome. (I will rebase, obviously, before a merge) |
if path.is_a?(::ActionView::Resolver) | ||
super("") | ||
elsif ::Rails::VERSION::STRING < '3.1' | ||
super(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bquorning ok, I have some questions. Is this to solve the performance regression? If so, can you provide a benchmark which shows if this is faster? If not, does this fix some regression that was introduced? If so, can you provide a spec or other example for that case? |
@samphippen I meant to fix a regression. After #1535, it is no longer possible to call e.g. I’m not really sure where to add the spec. |
@bquorning could you write a spec literally anywhere in spec/ and push it up. Once I see it I can likely advise on where it should end up. |
The best thing to do is what we do in def _path_decorator(path)
case path
when Pathname, String
EmptyTemplateResolver.new(path.to_s)
else
path
end
end That should minimise the risk of any breakage by us messing about with the internals. @samphippen we fixed the performance regression in 3.4.2 AFAIK - if there's another please point me to it. |
👍 thanks @pixeltrix, @bquorning can you update the implementation to follow @pixeltrix's advice. Thanks! |
Hmm, I don’t agree @pixeltrix. If the point is (as @JonRowe mentioned earlier) to nullify view rendering, then my custom resolver (here: |
On the other hand, the current |
When you prepend or append view paths, you can choose to do so with either a path (which may be looked up on the file system) or an instance of `ActionView::Resolver` which will then know how to do the lookup. We should only wrap paths (`String` or `Pathname` instances) in an `EmptyTemplateResolver`.
a440806
to
b2d22e4
Compare
# Delegates find_all to the submitted path set and then returns templates | ||
# with modified source | ||
# Delegates find_templates to the submitted path set and then returns | ||
# templates with modified source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it’s ok that I fixed the documentation here, too?
PR updated & rebased. |
@bquorning I still think it'd be good to get a spec for this. If in doubt, just make a new spec file in the spec/ directory. Let me know if you need any other help with that 😄 |
@bquorning I think burdening rspec-rails with the responsibility of nullifying the rendering of all custom template resolvers is a bit much to ask 😄 One possible option would be to look at somewhere else to nullify the rendering - I'll see if there's somewhere we can hook in. |
I’ve tried reading RSpec’s specs for Example and ExampleGroup, in order to add a spec to your controller_example_group_spec. But I cannot figure out how to get a I pushed what I’ve got so far. |
To write a spec for this you need to do whatever behaviour causes a Resolver to be passed down to this method, hooks are irrelevant for that. |
b17a13c
to
b2d22e4
Compare
While it would be nice to have spec coverage this change, I cannot seem to wrap my head around it. Testing a test framework is very meta :-) |
@samphippen If I remove view_rendering worked for me before #1535, and it works for again after the change in this PR. Any change of merging it without test coverage? |
I don't think that's a good idea, I'm convinced this breaks the default usage which is no view rendering. |
How come? Isn’t the default usage to prepend with a |
This isn't accessed directly, but by your controllers when specs are setup so we don't know what we'll receive, but we know we want to return an EmptyTemplateResolver so as to nullify the lookup, this is the direct opposite. I worked up #1557 as an alternative which skips the check added by changing the superclass of the resolver. |
It is not. An
I’ll take a look at #1557. |
By the way, the specs added in #1557 are all passing on this branch. |
Which is an undesired change in the behaviour.
Yes, the specs were regression checks to ensure errors weren't raised, it's actually quite hard to test this in isolation and I don't want to pollute the features for regression checks. |
Closing in favour of #1557. |
When you prepend or append view paths, you can choose to do so with either a path (which may be looked up on the file system) or an instance of
ActionView::Resolver
which will then know how to do the lookup. We should not wrapActionView::Resolver
instances in anEmptyTemplateResolver
.I’m not sure where/whether to add a spec.
cc @pixeltrix (related to #1535)