spec.plugins.view.js
This file
Path
spec/spec.plugins.view.js
190 lines · 5.9 KiB · JavaScript
Last changed by
Merge branch 'partials'visionmediabefore adoption28f2ad0
History of this fileTake it
The walk stopped after 200 commits: lines older than c5491c9 point at it.
Benchmarksvisionmediabefore adoptionc5491c9
lines 1–13why, one step back12describe 'Express'3 before_each4 reset()5 end6 7 describe 'View'8 describe 'set("views")'9 it 'should default to <root>/views'10 set('root', 'spec')11 set('views').should.eql 'spec/views'12 end13 endCloses #52visionmediabefore adoption161c9f9
line 14why, one step back14 Merge branch 'partials'visionmediabefore adoption28f2ad0
lines 15–52why, one step back15 describe '#partial()'16 before_each17 set('views', 'spec/fixtures')18 end19 20 describe 'given a valid view name'21 it 'should render a partial'22 get('/', function(){23 this.render('list.haml.html', { locals: { items: ['foo', 'bar'] }})24 })25 get('/').body.should.include '<ul>'26 get('/').body.should.include '<li>foo'27 get('/').body.should.include '<li>bar'28 end29 30 it 'should render collections'31 get('/', function(){32 return this.partial('item.haml.html', {33 collection: ['foo', 'bar']34 })35 })36 get('/').body.should.include '<li>foo'37 get('/').body.should.include '<li>bar'38 end39 40 it 'should render collections with a given object name'41 get('/', function(){42 return this.partial('video.haml.html', {43 collection: ['im a movie', 'im another movie'],44 as: 'vid'45 })46 })47 get('/').body.should.include '<li>im a movie'48 get('/').body.should.include '<li>im another movie'49 end50 end51 end52 Closes #52visionmediabefore adoption161c9f9
lines 53–120why, one step back53 describe '#render()'54 before_each55 set('views', 'spec/fixtures')56 end57 58 describe 'given a valid view name'59 describe 'and layout of the same type exists'60 it 'should render the layout and view'61 get('/', function(){62 this.render('hello.haml.html')63 })64 get('/').body.should.include '<html><body>'65 get('/').body.should.include '<h2>Hello'66 end67 68 it 'should default context to the current request'69 get('/', function(){70 this.title = 'Welcome'71 this.render('page.haml.html', { layout: false })72 })73 get('/').body.should.include '<title>Welcome'74 end75 76 it 'should set the content type based on the last path segment'77 get('/', function(){78 this.render('hello.haml.html')79 })80 get('/').headers['content-type'].should.eql 'text/html'81 end82 end83 84 describe 'and layout of the same type does not exist'85 it 'should throw an error'86 get('/', function(){87 this.render('hello.haml.html', { layout: 'front' })88 })89 -{ get('/') }.should.throw_error 'No such file or directory'90 end91 end92 93 describe 'given a custom layout name'94 it 'should render the layout and view'95 get('/', function(){96 this.title = 'Express'97 this.render('hello.haml.html', { layout: 'page' })98 })99 get('/').body.should.include '<title>Express'100 get('/').body.should.include '<h2>Hello'101 end102 end103 104 describe 'when layout: false'105 it 'should render the view only'106 get('/', function(){107 this.render('hello.haml.html', { layout: false })108 })109 get('/').body.should.not.include '<body>'110 get('/').body.should.include '<h2>Hello'111 end112 end113 114 describe 'when "cache view contents" is enabled'115 it 'should read the views into memory only once'116 enable('cache view contents')117 get('/', function(){118 this.render('hello.haml.html')119 })120 get('/cached', function(){Merge branch 'async-cache'visionmediabefore adoption7606f1b
lines 121–124why, one step back121 var self = this122 this.cache.get('view:spec/fixtures/hello.haml.html', function(val){123 self.halt(200, val ? 'yes' : 'no')124 })Closes #52visionmediabefore adoption161c9f9
lines 125–188why, one step back125 })126 get('/cached').body.should.eql 'no'127 get('/')128 get('/cached').body.should.eql 'yes'129 get('/')130 get('/cached').body.should.eql 'yes'131 end132 end133 134 describe 'when engine cannot be found'135 it 'should throw an error'136 get('/', function(){137 this.render('user.invalid.html')138 })139 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"140 end141 end142 143 describe 'when locals are passed'144 it 'should have direct access to locals'145 get('/user', function(){146 this.render('user.haml.html', {147 locals: {148 name: 'tj',149 email: 'tj@vision-media.ca'150 }151 })152 })153 get('/user').body.should.include '<h1>tj'154 get('/user').body.should.include '<p>tj@vision-media.ca'155 end156 157 it 'should have direct access to locals within the layout'158 get('/user', function(){159 this.render('user.haml.html', {160 layout: 'layout.user',161 locals: {162 name: 'tj',163 email: 'tj@vision-media.ca'164 }165 })166 })167 get('/user').body.should.include '<title>Viewing tj'168 get('/user').body.should.include '<h1>tj'169 get('/user').body.should.include '<p>tj@vision-media.ca'170 end171 end172 173 describe 'when context is passed'174 it 'should evaluate in context to that object'175 get('/article', function(){176 this.render('article.haml.html', {177 context: {178 name: 'Writing a Node.js Web Application'179 }180 })181 })182 get('/article').body.should.include '<h2>Writing a Node.js Web Application'183 end184 end185 186 end187 188 endBenchmarksvisionmediabefore adoptionc5491c9
lines 189–190why, one step back189 end190end