Skip to content

error when Rails view renders a partial #1

@eostrom

Description

@eostrom

First off, I'm running Cucover on a Spree project, and a lot of the code is in an extension (like a plugin), not in RAILS_ROOT/app. I don't think that's an issue, but I thought I should mention it.

I get a lot of this error:

undefined method `filename' for nil:NilClass (ActionView::TemplateError)  
  cucover (0.1.4) lib/cucover/rails.rb:17:in `render'

The line is:

    filename = args[0][:file].filename

This seems to work fine for views and layouts rendered by the controller: args[0][:file] is a Template object that knows exactly what file it's rendering.

The problem is when the view in turn renders a partial. In this case, there's no :file, just :partial, and the value isn't a Template, it's just a string like "shared/footer". In some cases, args[0] isn't a hash at all, it's just a string.

I made Cucover get past this line with the following code:

    source = args[0]
    filename = if source[:file]
                 source[:file].filename
               elsif source[:partial]
                 source[:partial] =~ /[^\/]+$/
                 source[:partial].sub(/[^\/]+$/, "_#{$&}")
               else
                 source
               end

... but I suspect Cucover won't properly detect when files are changed, because it only has a string like "shared/footer" and not the actual path to the file that was rendered.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions