Skip to content
Permalink
Browse files

Add failing test case for view_renderer leaking to rails (#144) (#146)

* Add failing test case for view_renderer leaking to rails (#144)

* make it works for Rails 6 and prior versions
  • Loading branch information...
robink authored and Spone committed Sep 18, 2019
1 parent 58b0071 commit eb4267b40f927ab2cad840d644353d38a9e36a60
@@ -11,5 +11,4 @@
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require_tree .
@@ -1,13 +1,4 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
//
//= require action_cable
//= require_self
//= require_tree ./channels

(function() {
this.App || (this.App = {});

App.cable = ActionCable.createConsumer();

}).call(this);
@@ -0,0 +1,2 @@
class PagesController < ApplicationController
end
@@ -0,0 +1 @@
<div id="some_partial">hello from partial</div>
@@ -0,0 +1,2 @@
<%= c "bar" do %>hello from bar<% end %>
<%= render partial: "some_partial" %>
@@ -0,0 +1 @@
<%= c "bar" do %>hello from bar<% end %>
@@ -0,0 +1 @@
<%= render partial: "some_partial" %>
@@ -0,0 +1 @@
<div id="view_only">hello from view</div>
@@ -1,3 +1,7 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get 'pages/view_only', to: 'pages#view_only'
get 'pages/partial_render', to: 'pages#partial_render'
get 'pages/komponent_render', to: 'pages#komponent_render'
get 'pages/komponent_partial_render', to: 'pages#komponent_partial_render'
end
@@ -9,7 +9,13 @@ class ComponentRenderer

def initialize(controller, view_flow = nil)
@context = controller.view_context.dup
@view_renderer = @context.view_renderer

if Rails::VERSION::MAJOR >= 6
@view_renderer = @context.view_renderer
else
@view_renderer = @context.view_renderer = @context.view_renderer.dup
end

@lookup_context = @view_renderer.lookup_context = @view_renderer.lookup_context.dup
@view_flow = view_flow
end
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'test_helper'

class PagesControllerTest < ActionController::TestCase
def test_view_only
post(:view_only)
assert_response :ok
assert_select '#view_only', "hello from view"
end

def test_partial_render
post(:partial_render)
assert_response :ok
assert_select '#some_partial', "hello from partial"
end

def test_komponent_render
post(:komponent_render)
assert_response :ok
assert_select '.bar', "hello from bar"
end

def test_komponent_partial_render
post(:komponent_partial_render)
assert_response :ok
assert_select '.bar', "hello from bar"
assert_select '#some_partial', "hello from partial"
end
end

0 comments on commit eb4267b

Please sign in to comment.
You can’t perform that action at this time.