spec.plugins.view.js
This file
Path
spec/spec.plugins.view.js
218 lines · 6.7 KiB · JavaScript
Last changed by
Merge branch 'ejs'visionmediabefore adoption2d132cd
History of this fileTake it
The walk stopped after 200 commits: lines older than c429e88 point at it.
Updated --version of node tested against in readmevisionmediabefore adoptionc429e88
line 1why, one step back1Merge branch 'ejs'visionmediabefore adoption2d132cd
lines 2–3why, one step back2ejs = require('ejs')3Updated --version of node tested against in readmevisionmediabefore adoptionc429e88
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–46why, one step back42 end43 44 describe 'given a valid view name'45 it 'should render a partial'46 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 47why, one step back47 this.render('list.html.haml', { locals: { items: ['foo', 'bar'] }})Merge branch 'partials'visionmediabefore adoption28f2ad0
lines 48–55why, one step back48 })49 get('/').body.should.include '<ul>'50 get('/').body.should.include '<li>foo'51 get('/').body.should.include '<li>bar'52 end53 54 it 'should render collections'55 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 56why, one step back56 return this.partial('item.html.haml', {Merge branch 'partials'visionmediabefore adoption28f2ad0
lines 57–65why, one step back57 collection: ['foo', 'bar']58 })59 })60 get('/').body.should.include '<li>foo'61 get('/').body.should.include '<li>bar'62 end63 64 it 'should render collections with a given object name'65 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 66why, one step back66 return this.partial('video.html.haml', {Merge branch 'partials'visionmediabefore adoption28f2ad0
lines 67–73why, one step back67 collection: ['im a movie', 'im another movie'],68 as: 'vid'69 })70 })71 get('/').body.should.include '<li>im a movie'72 get('/').body.should.include '<li>im another movie'73 endMerge branch 'partial-index-and-length'visionmediabefore adoptionb2093d6
lines 74–76why, one step back74 75 it 'should pass __isFirst__, __isLast__, and __index__ to partials as locals'76 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 77why, one step back77 return this.partial('article.html.haml', {Merge branch 'partial-index-and-length'visionmediabefore adoptionb2093d6
lines 78–84why, one step back78 collection: ['a', 'b', 'c']79 })80 })81 get('/').body.should.include '<li class="first">a'82 get('/').body.should.include '<li class="1">b'83 get('/').body.should.include '<li class="last">c'84 endMerge branch 'partials'visionmediabefore adoption28f2ad0
lines 85–87why, one step back85 end86 end87 Closes #52visionmediabefore adoption161c9f9
lines 88–92why, one step back88 describe '#render()'89 before_each90 set('views', 'spec/fixtures')91 end92 Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
lines 93–95why, one step back93 describe 'given a callback'94 it 'should be passed the rendered content'95 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 96why, one step back96 this.render('hello.html.haml', {}, function(err, content){Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
line 97why, one step back97 if (err) this.error(err)Merge branch 'rename-halt'visionmediabefore adoption531990b
line 98why, one step back98 else this.respond(203, content)Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
lines 99–100why, one step back99 })100 })Merge branch 'better-haml'visionmediabefore adoptionbdf9f88
line 101why, one step back101 get('/').body.should.include '<html>\n<body>'Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b
lines 102–105why, one step back102 get('/').status.should.eql 203103 end104 end105 Closes #52visionmediabefore adoption161c9f9
lines 106–109why, one step back106 describe 'given a valid view name'107 describe 'and layout of the same type exists'108 it 'should render the layout and view'109 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 110why, one step back110 this.render('hello.html.haml')Closes #52visionmediabefore adoption161c9f9
line 111why, one step back111 })Merge branch 'better-haml'visionmediabefore adoptionbdf9f88
line 112why, one step back112 get('/').body.should.include '<html>\n<body>'Closes #52visionmediabefore adoption161c9f9
lines 113–118why, one step back113 get('/').body.should.include '<h2>Hello'114 end115 116 it 'should default context to the current request'117 get('/', function(){118 this.title = 'Welcome'Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 119why, one step back119 this.render('page.html.haml', { layout: false })Closes #52visionmediabefore adoption161c9f9
lines 120–125why, one step back120 })121 get('/').body.should.include '<title>Welcome'122 end123 124 it 'should set the content type based on the last path segment'125 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 126why, one step back126 this.render('hello.html.haml')Closes #52visionmediabefore adoption161c9f9
line 127why, one step back127 })Merge branch 'etag'visionmediabefore adoptionb5d6f1a
line 128why, one step back128 get('/').headers['Content-Type'].should.eql 'text/html'Closes #52visionmediabefore adoption161c9f9
lines 129–134why, one step back129 end130 end131 132 describe 'and layout of the same type does not exist'133 it 'should throw an error'134 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 135why, one step back135 this.render('hello.html.haml', { layout: 'front' })Closes #52visionmediabefore adoption161c9f9
line 136why, one step back136 })Updated ext submodulevisionmediabefore adoption8108876
line 137why, one step back137 -{ get('/') }.should.throw_error 'ENOENT, No such file or directory'Closes #52visionmediabefore adoption161c9f9
lines 138–144why, one step back138 end139 end140 141 describe 'given a custom layout name'142 it 'should render the layout and view'143 get('/', function(){144 this.title = 'Express'Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 145why, one step back145 this.render('hello.html.haml', { layout: 'page' })Closes #52visionmediabefore adoption161c9f9
lines 146–154why, one step back146 })147 get('/').body.should.include '<title>Express'148 get('/').body.should.include '<h2>Hello'149 end150 end151 152 describe 'when layout: false'153 it 'should render the view only'154 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 155why, one step back155 this.render('hello.html.haml', { layout: false })Closes #52visionmediabefore adoption161c9f9
lines 156–164why, one step back156 })157 get('/').body.should.not.include '<body>'158 get('/').body.should.include '<h2>Hello'159 end160 end161 162 describe 'when engine cannot be found'163 it 'should throw an error'164 get('/', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 165why, one step back165 this.render('user.html.invalid')Closes #52visionmediabefore adoption161c9f9
lines 166–173why, one step back166 })167 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"168 end169 end170 171 describe 'when locals are passed'172 it 'should have direct access to locals'173 get('/user', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 174why, one step back174 this.render('user.html.haml', {Closes #52visionmediabefore adoption161c9f9
lines 175–186why, one step back175 locals: {176 name: 'tj',177 email: 'tj@vision-media.ca'178 }179 })180 })181 get('/user').body.should.include '<h1>tj'182 get('/user').body.should.include '<p>tj@vision-media.ca'183 end184 185 it 'should have direct access to locals within the layout'186 get('/user', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 187why, one step back187 this.render('user.html.haml', {Closes #52visionmediabefore adoption161c9f9
lines 188–203why, one step back188 layout: 'layout.user',189 locals: {190 name: 'tj',191 email: 'tj@vision-media.ca'192 }193 })194 })195 get('/user').body.should.include '<title>Viewing tj'196 get('/user').body.should.include '<h1>tj'197 get('/user').body.should.include '<p>tj@vision-media.ca'198 end199 end200 201 describe 'when context is passed'202 it 'should evaluate in context to that object'203 get('/article', function(){Merge branch 'flip-views'visionmediabefore adoption6b13fc9
line 204why, one step back204 this.render('article.html.haml', {Closes #52visionmediabefore adoption161c9f9
lines 205–216why, one step back205 context: {206 name: 'Writing a Node.js Web Application'207 }208 })209 })210 get('/article').body.should.include '<h2>Writing a Node.js Web Application'211 end212 end213 214 end215 216 endUpdated --version of node tested against in readmevisionmediabefore adoptionc429e88
lines 217–218why, one step back217 end218end