rails/rails-controller-testing

:identifiers in Rails 6 seem to fall into the wrong subscriber.

ragaskar opened this issue · 4 comments

I have a bit of code that is render-ing a template like so:

render file: Rails.root.join('public', 'webpack_assets', 'index.html'), layout: false

This was previously being tested (with Rails 5) with an

assert_template(file: Rails.root.join('public', 'webpack_assets', 'index.html'))

This no longer works in Rails 6.1.1.4 (the assert_template actual is '[]' instead of the value of Rails.root.join('public', 'webpack_assets', 'index.html')). It seems like the payload containing the :identifier key falls into the subscription for render_template.action_view where it appears to be expected in the !render_template.action_view subscription.

Hopefully this makes sense, sorry for not providing more details, haven't gotten a chance to dig in more yet. If I get a moment I'll validate the change in Rails and propose a fix.

I'm running into a similar problem. The template renders fine in normal use, but there is an error thrown when testing with render_template:

     Failure/Error: expect(response).to render_template(file: "#{Rails.root}/public/404.html")
       Expected [] to include "/app/public/404.html".

Render code:

  def render_not_found
    respond_to do |format|
      format.html { render file: 'public/404.html', status: :not_found, layout: false }
      format.json { render json: { code: 404, error: 'not found' }, status: :not_found }
    end
  end

@ragaskar did you ever find a workaround or a fix for this?

I dug in a little bit and found that PR #46 has some discussion and a proposed fix: tconst@7c8f078. I rebased it onto the newest commit in airdrummingfool@d5c05e7.

@airdrummingfool can you open a PR for that?

@rafaelfranca sure, done. See #76.