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

Comments

Projects
None yet
10 participants
@cwadding

cwadding commented Feb 28, 2012

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

This comment has been minimized.

Show comment
Hide comment
@isaacsanders

isaacsanders May 5, 2012

Contributor

Is this still an issue?

Contributor

isaacsanders commented May 5, 2012

Is this still an issue?

@justinko

This comment has been minimized.

Show comment
Hide comment
@justinko

justinko May 6, 2012

Contributor

Most likely.

Contributor

justinko commented May 6, 2012

Most likely.

@isaacsanders

This comment has been minimized.

Show comment
Hide comment
@isaacsanders

isaacsanders May 6, 2012

Contributor

Repro steps?

Contributor

isaacsanders commented May 6, 2012

Repro steps?

@justinko

This comment has been minimized.

Show comment
Hide comment
@justinko

justinko May 6, 2012

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@isaacsanders

isaacsanders May 7, 2012

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)

Contributor

isaacsanders commented May 7, 2012

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

This comment has been minimized.

Show comment
Hide comment
@justinko

justinko May 7, 2012

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@isaacsanders

isaacsanders May 7, 2012

Contributor

Any thoughts on this @tenderlove?

Contributor

isaacsanders commented May 7, 2012

Any thoughts on this @tenderlove?

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca May 7, 2012

Member

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

Member

rafaelfranca commented May 7, 2012

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

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 13, 2012

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?

Member

schneems commented Aug 13, 2012

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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Aug 13, 2012

Member

If you can, please go ahead with a fix.

Member

rafaelfranca commented Aug 13, 2012

If you can, please go ahead with a fix.

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 19, 2012

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?

Member

schneems commented Aug 19, 2012

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

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 29, 2012

Member

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

Member

schneems commented Aug 29, 2012

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

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Aug 29, 2012

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.

Member

steveklabnik commented Aug 29, 2012

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

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Aug 29, 2012

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.

Member

schneems commented Aug 29, 2012

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

This comment has been minimized.

Show comment
Hide comment
@pixeltrix

pixeltrix Aug 29, 2012

Member

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

Member

pixeltrix commented Aug 29, 2012

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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Mar 23, 2013

Member

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

Member

rafaelfranca commented Mar 23, 2013

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

@msaspence

This comment has been minimized.

Show comment
Hide comment
@msaspence

msaspence Oct 14, 2013

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).

msaspence commented Oct 14, 2013

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

This comment has been minimized.

Show comment
Hide comment
@jmuheim

jmuheim 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

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

This comment has been minimized.

Show comment
Hide comment
@ydaniju

ydaniju Oct 9, 2017

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

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