-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require 'test_helper' | ||
require 'action_view' | ||
require 'action_pack' | ||
require 'action_controller' | ||
|
||
FIXTURE_LOAD_PATH = File.expand_path("fixtures", __dir__) | ||
|
||
include ActionView::Context | ||
|
||
module ActionController | ||
|
||
class Base | ||
self.view_paths = FIXTURE_LOAD_PATH | ||
|
||
def self.test_routes(&block) | ||
routes = ActionDispatch::Routing::RouteSet.new | ||
routes.draw(&block) | ||
include routes.url_helpers | ||
routes | ||
end | ||
end | ||
|
||
class TestCase | ||
include ActionDispatch::TestProcess | ||
|
||
def self.with_routes(&block) | ||
routes = ActionDispatch::Routing::RouteSet.new | ||
routes.draw(&block) | ||
include Module.new { | ||
define_method(:setup) do | ||
super() | ||
@routes = routes | ||
@controller.singleton_class.include @routes.url_helpers if @controller | ||
end | ||
} | ||
routes | ||
end | ||
end | ||
end | ||
|
||
class TestController < ActionController::Base | ||
|
||
def render_simple_view | ||
render template: "simple_view" | ||
end | ||
end | ||
|
||
class RenderTest < ActionController::TestCase | ||
|
||
tests TestController | ||
|
||
with_routes do | ||
get :render_simple_view, to: "test#render_simple_view" | ||
end | ||
|
||
def setup | ||
# enable a logger so that (e.g.) the benchmarking stuff runs, so we can get | ||
# a more accurate simulation of what happens in "real life". | ||
super | ||
@request.host = "www.scoutapm.com" | ||
|
||
@old_view_paths = ActionController::Base.view_paths | ||
ActionController::Base.view_paths = FIXTURE_LOAD_PATH | ||
end | ||
|
||
def teardown | ||
ActionView::Base.logger = nil | ||
|
||
ActionController::Base.view_paths = @old_view_paths | ||
end | ||
|
||
def test_partial_instrumentation | ||
recorder = FakeRecorder.new | ||
agent_context.recorder = recorder | ||
|
||
instrument = ScoutApm::Instruments::ActionView.new(agent_context) | ||
instrument.install(prepend: true) | ||
|
||
get :render_simple_view | ||
assert_response :success | ||
|
||
assert_equal "simple_view/Rendering", recorder.requests.first.root_layer.name | ||
assert_equal "test/_simple_partial/Rendering", recorder.requests.first.root_layer.children.first.name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title>Simple View</title> | ||
</head> | ||
<body> | ||
<h1>Simple View</h1> | ||
<%= render partial: "simple_partial", locals: { message: 'Simple Partial' } %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<p><%= @message %></p> | ||
</div> |