Skip to content
Myr

spec.plugins.view.js

This file

Path

spec/spec.plugins.view.js

180 lines · 5.5 KiB · JavaScript

Last changed by

Merge branch 'pre-cache-views'visionmediabefore adoption6806f95

History of this file

Take it

The walk stopped after 200 commits: lines older than 22e338f point at it.

Add support to StaticFile so that it works with non-textual files.ciaranjbefore adoption22e338f

lines 1–13why, one step back
1
2describe '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 end

Closes #52visionmediabefore adoption161c9f9

line 14why, one step back
14

Merge branch 'integration'visionmediabefore adoption7d100da

lines 15–23why, one step back
15 describe 'set("partials")'
16 it 'should default to <views>/partials'17 set('root', 'spec')18 set('partials').should.eql 'spec/views/partials'19 set('views', 'magicland')20 set('partials').should.eql 'magicland/partials'21 end22 end23

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 24–26why, one step back
24 describe '#partial()'
25 before_each26 set('views', 'spec/fixtures')

Merge branch 'integration'visionmediabefore adoption7d100da

line 27why, one step back
27 set('partials', 'spec/fixtures/partials')

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 28–62why, one step back
28 end
29 30 describe 'given a valid view name'31 it 'should render a partial'32 get('/', function(){33 this.render('list.haml.html', { locals: { items: ['foo', 'bar'] }})34 })35 get('/').body.should.include '<ul>'36 get('/').body.should.include '<li>foo'37 get('/').body.should.include '<li>bar'38 end39 40 it 'should render collections'41 get('/', function(){42 return this.partial('item.haml.html', {43 collection: ['foo', 'bar']44 })45 })46 get('/').body.should.include '<li>foo'47 get('/').body.should.include '<li>bar'48 end49 50 it 'should render collections with a given object name'51 get('/', function(){52 return this.partial('video.haml.html', {53 collection: ['im a movie', 'im another movie'],54 as: 'vid'55 })56 })57 get('/').body.should.include '<li>im a movie'58 get('/').body.should.include '<li>im another movie'59 end60 end61 end62

Closes #52visionmediabefore adoption161c9f9

lines 63–178why, one step back
63 describe '#render()'
64 before_each65 set('views', 'spec/fixtures')66 end67 68 describe 'given a valid view name'69 describe 'and layout of the same type exists'70 it 'should render the layout and view'71 get('/', function(){72 this.render('hello.haml.html')73 })74 get('/').body.should.include '<html><body>'75 get('/').body.should.include '<h2>Hello'76 end77 78 it 'should default context to the current request'79 get('/', function(){80 this.title = 'Welcome'81 this.render('page.haml.html', { layout: false })82 })83 get('/').body.should.include '<title>Welcome'84 end85 86 it 'should set the content type based on the last path segment'87 get('/', function(){88 this.render('hello.haml.html')89 })90 get('/').headers['content-type'].should.eql 'text/html'91 end92 end93 94 describe 'and layout of the same type does not exist'95 it 'should throw an error'96 get('/', function(){97 this.render('hello.haml.html', { layout: 'front' })98 })99 -{ get('/') }.should.throw_error 'No such file or directory'100 end101 end102 103 describe 'given a custom layout name'104 it 'should render the layout and view'105 get('/', function(){106 this.title = 'Express'107 this.render('hello.haml.html', { layout: 'page' })108 })109 get('/').body.should.include '<title>Express'110 get('/').body.should.include '<h2>Hello'111 end112 end113 114 describe 'when layout: false'115 it 'should render the view only'116 get('/', function(){117 this.render('hello.haml.html', { layout: false })118 })119 get('/').body.should.not.include '<body>'120 get('/').body.should.include '<h2>Hello'121 end122 end123 124 describe 'when engine cannot be found'125 it 'should throw an error'126 get('/', function(){127 this.render('user.invalid.html')128 })129 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"130 end131 end132 133 describe 'when locals are passed'134 it 'should have direct access to locals'135 get('/user', function(){136 this.render('user.haml.html', {137 locals: {138 name: 'tj',139 email: 'tj@vision-media.ca'140 }141 })142 })143 get('/user').body.should.include '<h1>tj'144 get('/user').body.should.include '<p>tj@vision-media.ca'145 end146 147 it 'should have direct access to locals within the layout'148 get('/user', function(){149 this.render('user.haml.html', {150 layout: 'layout.user',151 locals: {152 name: 'tj',153 email: 'tj@vision-media.ca'154 }155 })156 })157 get('/user').body.should.include '<title>Viewing tj'158 get('/user').body.should.include '<h1>tj'159 get('/user').body.should.include '<p>tj@vision-media.ca'160 end161 end162 163 describe 'when context is passed'164 it 'should evaluate in context to that object'165 get('/article', function(){166 this.render('article.haml.html', {167 context: {168 name: 'Writing a Node.js Web Application'169 }170 })171 })172 get('/article').body.should.include '<h2>Writing a Node.js Web Application'173 end174 end175 176 end177 178 end

Add support to StaticFile so that it works with non-textual files.ciaranjbefore adoption22e338f

lines 179–180why, one step back
179 end
180end