1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
require 'test_helper'
require 'camping'
Camping.goes :Partials
Camping.goes :TiltPartials
module Partials::Controllers
class Index
def get
render :index
end
end
class Partial
def get
render :_partial
end
end
class Nolayout
def get
render :index, :layout => false
end
end
class Forcelayout
def get
render :_partial, :layout => true
end
end
class Nested
def get
render :nested
end
end
end
# Copy over all controllers
module TiltPartials::Controllers
Partials::Controllers.constants.each do |const|
const_set(const, Partials::Controllers.const_get(const).dup)
end
end
module Partials::Views
def layout
body do
yield
end
end
def index
h1 "Index"
_partial
end
def _partial
p "Partial"
end
def nested
h1 "Nested"
regular
end
def regular
p "Regular"
end
end
class Partials::Test < TestCase
def test_underscore_partial
get '/'
assert_body "<body><h1>Index</h1><p>Partial</p></body>"
end
def test_underscore_partial_only
get '/partial'
assert_body "<p>Partial</p>"
end
def test_nolayout
get '/nolayout'
assert_body "<h1>Index</h1><p>Partial</p>"
end
def test_forcelayout
get '/forcelayout'
assert_body "<body><p>Partial</p></body>"
end
def test_nested
get '/nested'
assert_body "<body><h1>Nested</h1><p>Regular</p></body>"
end
end
class TiltPartials::Test < Partials::Test
end
__END__
@@ layout.str
<body>#{yield.strip}</body>
@@ index.str
<h1>Index</h1>#{render(:_partial).strip}
@@ _partial.str
<p>Partial</p>
@@ nested.str
<h1>Nested</h1>#{render(:regular).strip}
@@ regular.str
<p>Regular</p>
|