spec.plugins.view.js
This file
Path
spec/spec.plugins.view.js
272 lines · 8.8 KiB · JavaScript
Last changed by
Merge branch 'integration'visionmediabefore adoption8d4ef6e
History of this fileTake it
The walk stopped after 200 commits: lines older than d0a8bb5 point at it.
Release 0.7.2visionmediabefore adoptiond0a8bb5
line 1why, one step back1Merge branch 'ejs'visionmediabefore adoption2d132cd
lines 2–3why, one step back2ejs = require('ejs')3Release 0.7.2visionmediabefore adoptiond0a8bb5
lines 4–15why, one step back4describe 'Express'5 before_each6 reset()7 end8 9 describe 'View'10 describe 'set("views")'11 it 'should default to <root>/views'12 set('root', 'spec')13 set('views').should.eql 'spec/views'14 end15 endCloses #52visionmediabefore adoption161c9f9
line 16why, one step back16 Merge branch 'integration'visionmediabefore adoption7d100da
lines 17–22why, one step back17 describe 'set("partials")'18 it 'should default to <views>/partials'19 set('root', 'spec')20 set('partials').should.eql 'spec/views/partials'21 set('views', 'magicland')22 set('partials').should.eql 'magicland/partials'Merge branch 'ejs'visionmediabefore adoption2d132cd
lines 23–34why, one step back23 end24 end25 26 describe 'ejs'27 it 'should work without options'28 var str = '<h2><%= "Title" %></h2>'29 ejs.render(str).should.eql '<h2>Title</h2>'30 end31 32 it 'should work with locals'33 var str = '<h2><%= title %></h2>'34 ejs.render(str, { locals: { title: 'Title' }}).should.eql '<h2>Title</h2>'Merge branch 'integration'visionmediabefore adoption7d100da
lines 35–37why, one step back35 end36 end37 Merge branch 'partials'visionmediabefore adoption28f2ad0
lines 38–40why, one step back38 describe '#partial()'39 before_each40 set('views', 'spec/fixtures')Merge branch 'integration'visionmediabefore adoption7d100da
line 41why, one step back41 set('partials', 'spec/fixtures/partials')Merge branch 'partials'visionmediabefore adoption28f2ad0
lines 42–44why, one step back42 end43 44 describe 'given a valid view name'Merge branch 'integration'visionmediabefore adoption8d4ef6e
lines 45–48why, one step back45 describe 'with EJS'46 it 'should render a partial'47 get('/', function(){48 this.render('list.html.ejs', { locals: { items: ['foo', 'bar'] }})Merge branch 'partials'visionmediabefore adoption28f2ad0
line 49why, one step back49 })Merge branch 'integration'visionmediabefore adoption8d4ef6e
lines 50–59why, one step back50 get('/').body.should.include '<ul>'51 get('/').body.should.include '<li>foo'52 get('/').body.should.include '<li>bar'53 end54 55 it 'should render collections'56 get('/', function(){57 return this.partial('item.html.ejs', {58 collection: ['foo', 'bar']59 })Merge branch 'partials'visionmediabefore adoption28f2ad0
line 60why, one step back60 })Merge branch 'integration'visionmediabefore adoption8d4ef6e
lines 61–85why, one step back61 get('/').body.should.include '<li>foo'62 get('/').body.should.include '<li>bar'63 end64 65 it 'should render collections with a given object name'66 get('/', function(){67 return this.partial('video.html.ejs', {68 collection: ['im a movie', 'im another movie'],69 as: 'vid'70 })71 })72 get('/').body.should.include '<li>im a movie'73 get('/').body.should.include '<li>im another movie'74 end75 76 it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'77 get('/', function(){78 return this.partial('article.html.ejs', {79 collection: ['a', 'b', 'c']80 })81 })82 get('/').body.should.include '<li class="first">a'83 get('/').body.should.include '<li class="1">b'84 get('/').body.should.include '<li class="last">c'85 endMerge branch 'partials'visionmediabefore adoption28f2ad0
line 86why, one step back86 endMerge branch 'integration'visionmediabefore adoption8d4ef6e
lines 87–90why, one step back87 describe 'with Haml'88 it 'should render a partial'89 get('/', function(){90 this.render('list.html.haml', { locals: { items: ['foo', 'bar'] }})Merge branch 'partial-index-and-length'visionmediabefore adoptionb2093d6
line 91why, one step back91 })Merge branch 'integration'visionmediabefore adoption8d4ef6e
lines 92–127why, one step back92 get('/').body.should.include '<ul>'93 get('/').body.should.include '<li>foo'94 get('/').body.should.include '<li>bar'95 end96 97 it 'should render collections'98 get('/', function(){99 return this.partial('item.html.haml', {100 collection: ['foo', 'bar']101 })102 })103 get('/').body.should.include '<li>foo'104 get('/').body.should.include '<li>bar'105 end106 107 it 'should render collections with a given object name'108 get('/', function(){109 return this.partial('video.html.haml', {110 collection: ['im a movie', 'im another movie'],111 as: 'vid'112 })113 })114 get('/').body.should.include '<li>im a movie'115 get('/').body.should.include '<li>im another movie'116 end117 118 it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'119 get('/', function(){120 return this.partial('article.html.haml', {121 collection: ['a', 'b', 'c']122 })123 })124 get('/').body.should.include '<li class="first">a'125 get('/').body.should.include '<li class="1">b'126 get('/').body.should.include '<li class="last">c'127 endMerge branch 'partial-index-and-length'visionmediabefore adoptionb2093d6
line 128why, one step back128 endMerge branch 'partials'visionmediabefore adoption28f2ad0
lines 129–131why, one step back129 end130 end131 Closes #52visionmediabefore adoption161c9f9
lines 132–136why, one step back132 describe '#render()'133 before_each134 set('views', 'spec/fixtures')135 end136 Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
lines 137–139why, one step back137 describe 'given a callback'138 it 'should be passed the rendered content'139 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 140why, one step back140 this.render('hello.html.haml', {}, function(err, content){Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
line 141why, one step back141 if (err) this.error(err)Merge branch 'rename-halt'visionmediabefore adoption531990b
line 142why, one step back142 else this.respond(203, content)Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
lines 143–144why, one step back143 })144 })Merge branch 'better-haml'visionmediabefore adoptionbdf9f88
line 145why, one step back145 get('/').body.should.include '<html>\n<body>'Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
lines 146–149why, one step back146 get('/').status.should.eql 203147 end148 end149 Closes #52visionmediabefore adoption161c9f9
lines 150–153why, one step back150 describe 'given a valid view name'151 describe 'and layout of the same type exists'152 it 'should render the layout and view'153 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 154why, one step back154 this.render('hello.html.haml')Closes #52visionmediabefore adoption161c9f9
line 155why, one step back155 })Merge branch 'better-haml'visionmediabefore adoptionbdf9f88
line 156why, one step back156 get('/').body.should.include '<html>\n<body>'Closes #52visionmediabefore adoption161c9f9
lines 157–162why, one step back157 get('/').body.should.include '<h2>Hello'158 end159 160 it 'should default context to the current request'161 get('/', function(){162 this.title = 'Welcome'Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 163why, one step back163 this.render('page.html.haml', { layout: false })Closes #52visionmediabefore adoption161c9f9
lines 164–169why, one step back164 })165 get('/').body.should.include '<title>Welcome'166 end167 168 it 'should set the content type based on the last path segment'169 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 170why, one step back170 this.render('hello.html.haml')Closes #52visionmediabefore adoption161c9f9
line 171why, one step back171 })Merge branch 'etag'visionmediabefore adoptionb5d6f1a
line 172why, one step back172 get('/').headers['Content-Type'].should.eql 'text/html'Closes #52visionmediabefore adoption161c9f9
lines 173–178why, one step back173 end174 end175 176 describe 'and layout of the same type does not exist'177 it 'should throw an error'178 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 179why, one step back179 this.render('hello.html.haml', { layout: 'front' })Closes #52visionmediabefore adoption161c9f9
line 180why, one step back180 })Updated ext submodulevisionmediabefore adoption8108876
line 181why, one step back181 -{ get('/') }.should.throw_error 'ENOENT, No such file or directory'Closes #52visionmediabefore adoption161c9f9
lines 182–188why, one step back182 end183 end184 185 describe 'given a custom layout name'186 it 'should render the layout and view'187 get('/', function(){188 this.title = 'Express'Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 189why, one step back189 this.render('hello.html.haml', { layout: 'page' })Closes #52visionmediabefore adoption161c9f9
lines 190–195why, one step back190 })191 get('/').body.should.include '<title>Express'192 get('/').body.should.include '<h2>Hello'193 end194 end195 Merge branch 'integration'visionmediabefore adoption289487c
lines 196–205why, one step back196 describe 'given a full layout name'197 it 'should render a layout of a different engine'198 get('/', function(){199 this.render('hello.html.haml', { layout: 'layout.html.ejs' })200 })201 get('/').body.should.include '<h2>Hello'202 get('/').body.should.include '<p>'203 end204 end205 Closes #52visionmediabefore adoption161c9f9
lines 206–208why, one step back206 describe 'when layout: false'207 it 'should render the view only'208 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 209why, one step back209 this.render('hello.html.haml', { layout: false })Closes #52visionmediabefore adoption161c9f9
lines 210–218why, one step back210 })211 get('/').body.should.not.include '<body>'212 get('/').body.should.include '<h2>Hello'213 end214 end215 216 describe 'when engine cannot be found'217 it 'should throw an error'218 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 219why, one step back219 this.render('user.html.invalid')Closes #52visionmediabefore adoption161c9f9
lines 220–227why, one step back220 })221 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"222 end223 end224 225 describe 'when locals are passed'226 it 'should have direct access to locals'227 get('/user', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 228why, one step back228 this.render('user.html.haml', {Closes #52visionmediabefore adoption161c9f9
lines 229–240why, one step back229 locals: {230 name: 'tj',231 email: 'tj@vision-media.ca'232 }233 })234 })235 get('/user').body.should.include '<h1>tj'236 get('/user').body.should.include '<p>tj@vision-media.ca'237 end238 239 it 'should have direct access to locals within the layout'240 get('/user', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 241why, one step back241 this.render('user.html.haml', {Merge branch 'integration'visionmediabefore adoption289487c
line 242why, one step back242 layout: 'layout-user',Closes #52visionmediabefore adoption161c9f9
lines 243–257why, one step back243 locals: {244 name: 'tj',245 email: 'tj@vision-media.ca'246 }247 })248 })249 get('/user').body.should.include '<title>Viewing tj'250 get('/user').body.should.include '<h1>tj'251 get('/user').body.should.include '<p>tj@vision-media.ca'252 end253 end254 255 describe 'when context is passed'256 it 'should evaluate in context to that object'257 get('/article', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 258why, one step back258 this.render('article.html.haml', {Closes #52visionmediabefore adoption161c9f9
lines 259–270why, one step back259 context: {260 name: 'Writing a Node.js Web Application'261 }262 })263 })264 get('/article').body.should.include '<h2>Writing a Node.js Web Application'265 end266 end267 268 end269 270 endRelease 0.7.2visionmediabefore adoptiond0a8bb5
lines 271–272why, one step back271 end272end