Skip to content

View example group inserts controller path into lookup_context in the wrong order #2729

Open
@sfnelson

Description

@sfnelson

What Ruby, Rails and RSpec versions are you using?

Ruby version: 3.2.3
Rails version: 7.1.3
RSpec version: 3.12.2

Observed behaviour

Testing a controller where the 'prefixes' logic in ActionView::Renderer::AbstractRenderer#merge_prefix_into_object_path applies fails to find view partials when called from inside a nested controller.

This happens because the logic uses @context_prefix = lookup_context.prefixes.first, which in view specs is "", instead of the controller path.

Expected behaviour

@context_prefix = lookup_context.prefixes.first should return the controller's path

Can you provide an example reproduction?

Hard to reproduce as it relates to rails/rails#50916 – the logic in merge_prefix_into_object_path isn't very useful. I've got a monkey patch for that logic that address the issue, which is how I came across this issue.

I believe the logic in view_example_group is faulty because it uses append instead of prepend when setting up the lookup context prefixes.

view.lookup_context.prefixes << _controller_path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions