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

Missing partial in view specs with template inheritance #5213

Closed
cwadding opened this issue Feb 28, 2012 · 19 comments
Closed

Missing partial in view specs with template inheritance #5213

cwadding opened this issue Feb 28, 2012 · 19 comments

Comments

@cwadding
Copy link

There seems to be a problem when testing a view that renders a partial through template inheritance. The issue has come up and been discussed on the rspec-rails forum where I filed an issue here. However, it seems that it is an issue that should be fixed by rails as discussed in issue #396

@isaacsanders
Copy link
Contributor

Is this still an issue?

@justinko
Copy link
Contributor

justinko commented May 6, 2012

Most likely.

@isaacsanders
Copy link
Contributor

Repro steps?

@justinko
Copy link
Contributor

justinko commented May 6, 2012

rspec/rspec-rails#396 (comment)

P.S. Before commenting with "is this still an issue?" or "Repro steps?", please take the time and thoroughly go through the bug report. There is more than enough information in this particular issue for you to proceed. It is very annoying and disrespectful to the people involved that take the time to submit well documented issues. Thanks.

@isaacsanders
Copy link
Contributor

I am sorry. My intention is to bump as many issues as I can. There are hundreds of issues. Some are solved and no one realizes. It is by removing the noise that we can focus on the real ones. I apologize for not reading the issue more. I will take a look later.

Thank you for your involvement, and I hope that you can forgive me.

On May 6, 2012, at 6:45 PM, Justin Koreply@reply.github.com wrote:

rspec/rspec-rails#396 (comment)

P.S. Before commenting with "is this still an issue?" or "Repro steps?", please take the time and thoroughly go through the bug report. There is more than enough information in this particular issue for you to proceed. It is very annoying and disrespectful to the people involved that take the time to submit well documented issues. Thanks.


Reply to this email directly or view it on GitHub:
#5213 (comment)

@justinko
Copy link
Contributor

justinko commented May 7, 2012

No harm done! I did the same thing when I was given access to RSpec :)

There are hundreds of issues.

I think Rails core needs more members. Or at least a dedicated "issues" team - kind of like how some devs focus on Rails documentation.

A lot of the work with issues is the pain of reproducing, confirming whether it's a bug or not, etc. The issues team could attach failing tests to the issues to help out the "core" devs.

@isaacsanders
Copy link
Contributor

Any thoughts on this @tenderlove?

@rafaelfranca
Copy link
Member

@justinko the Issues team already exists and I'm part of this team. Currently we are 7 people.

@schneems
Copy link
Member

Issue bump, 3 months old. At the risk of repeating the previous conversation has anyone had any luck looking into this issue? Are there any blockers or problems? Would you like me to look into a fix?

@rafaelfranca
Copy link
Member

If you can, please go ahead with a fix.

@schneems
Copy link
Member

I looked into this a good bit, and I believe the behavior seen testing views isolated from controllers should be expected. The mechanism that gives us the ability to put a view in a parent folder is directly due to inheritance on the controller level. Without the controller the view has no concept of inheritance, and therefore it would not know that views/application/ was a valid path prefix for the partial. If you still want to test the view apart from the controller you should render an absolute path when using partials to avoid this dependency on controller inheritance.

<%= render :partial => 'application/foo' %>

instead of

<%= render :partial => 'foo' %>

By explicitly declaring the path of the partial, you are also making your program more robust.

That being said, if we want to "fix" this bug in this one specific case, we can have the default ActionView test controller inherit from ApplicationController so that the application/ folder would be added in as a view search prefix.

We could change this:

  class TestCase < ActiveSupport::TestCase
    class TestController < ActionController::Base

to this:

class ApplicationController < ActionController::Base
end
# ...

  class TestCase < ActiveSupport::TestCase
    class TestController < ApplicationController

Though that only really "solves" this one particular case, and not the overall issue of testing views with partials without their controllers. Thoughts?

@schneems
Copy link
Member

Anyone involved have a comment or question? If not we should close this issue.

@steveklabnik
Copy link
Member

Without the controller the view has no concept of inheritance,

Seems reasonable to me. Sounds like a close is in order, but I'd prefer to hear from someone closer to the issue before actually doing it.

@schneems
Copy link
Member

If it would help, I can submit a PR so the default TestCase::TestController inherits from ApplicationController, but since I won't use that functionality, I need someone to speak up if they want it.

@pixeltrix
Copy link
Contributor

I'm 👎 on the idea of making TestController inherit from ApplicationController - it only really fixes the case where the partials are in application and doesn't support more complicated hierarchies. What you need is a nicer way of setting the prefixes for the lookup context as that is how the inheritance is done, e.g:

require 'test_helper'

# This tests that the PagesController#index template renders
# the partial in the ApplicationController view directory
class PagesIndexTest < ActionView::TestCase
  test "pages/index renders application/header" do
    view.lookup_context.prefixes = %w[pages application]

    render :template => "pages/index"
    assert_template :partial => "application/_header"
  end
end

The hardest part is coming up with the name for the helper - perhaps something like template_inheritance

@rafaelfranca
Copy link
Member

Seems this is not a bug but a feature request so I'm closing this issue.

@msaspence
Copy link

I'm sure how you figure this is a feature request?

If the expected functionality is to be able to test views as if they running in a Rails app this a bug (albeit it with some additional functionality required to resolve).

@jmuheim
Copy link

jmuheim commented Jan 20, 2017

This still is a problem for me. I found a workaround, but it feels clumsy.

Detailed explanation on StackOverflow: Rails view specs: referenced partials of inherited controllers aren't found

@ydaniju
Copy link

ydaniju commented Oct 9, 2017

I can't believe I spent a whole day trying to figure this out.

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

No branches or pull requests

10 participants