Class: ActionView::Base
Overview
test/rails/render_tree.rb adds debug rendering to ActionView::Base#render.
Debug rendering prints out a tree of calls to render allowing you to easily visualize where rendering occurs in unfamiliar code.
Constant Summary collapse
- RENDERS =
List of render types for ActionView::Base#render
[:partial, :template, :file, :action, :text, :inline, :nothing, :update]
Instance Method Summary collapse
-
#plain_render ⇒ Object
:nodoc:.
-
#render(*args) ⇒ Object
Add debug output to rendering.
Instance Method Details
#plain_render ⇒ Object
:nodoc:
9 |
# File 'lib/test/rails/render_tree.rb', line 9 alias plain_render render |
#render(*args) ⇒ Object
Add debug output to rendering.
When you include lib/rails/render_tree a tree of renders will be displayed in the console. This is especially useful when writing tests.
This test:
require 'test/test_helper'
require 'test/rails/render_tree'
class ThingsViewTest < Test::Rails::ViewTestCase
fixtures :goals
def test_body
assigns[:goal] = goals(:first)
assigns[:related_goals_moved] = []
assigns[:related_goals_instead] = []
render :partial => 'things/body'
assert_tag :tag => 'div', :attributes => { :id => 'entriesbucket' }
end
end
Will give this output when run:
$ ruby test/views/things_view_test.rb -n test_body
Loaded suite test/views/things_view_test
Started
"things/_body"
:partial => "widgets/goals_gallery_teaser"
"widgets/_goals_gallery_teaser"
:partial => "entries_bucket"
"things/_entries_bucket"
:partial => "things/ask_a_question"
"things/_ask_a_question"
"widgets/forms/related_goals"
.
Finished in 1.293523 seconds.
1 tests, 1 assertions, 0 failures, 0 errors
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/test/rails/render_tree.rb', line 62 def render(*args) @level ||= 0 print ' ' * @level case args.first when String then p args.first when Hash then hash = args.first if hash.include? :collection and hash.include? :partial then puts "%p => %p" % [:collection, hash[:partial]] else found = hash.keys & RENDERS if found.length == 1 then puts "%p => %p" % [found.first, hash[found.first]] else raise "Dunno: %p" % [hash] end end else raise "Dunno: %p" % [args] end @level += 1 result = plain_render(*args) @level -= 1 result end |