Skip to content
Myr

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 file

Take it

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

Release 0.7.2visionmediabefore adoptiond0a8bb5

line 1why, one step back
1

Merge branch 'ejs'visionmediabefore adoption2d132cd

lines 2–3why, one step back
2ejs = require('ejs')
3

Release 0.7.2visionmediabefore adoptiond0a8bb5

lines 4–15why, one step back
4describe '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 end

Closes #52visionmediabefore adoption161c9f9

line 16why, one step back
16

Merge branch 'integration'visionmediabefore adoption7d100da

lines 17–22why, one step back
17 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 back
23 end
24 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 back
35 end
36 end37

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 38–40why, one step back
38 describe '#partial()'
39 before_each40 set('views', 'spec/fixtures')

Merge branch 'integration'visionmediabefore adoption7d100da

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

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 42–44why, one step back
42 end
43 44 describe 'given a valid view name'

Merge branch 'integration'visionmediabefore adoption8d4ef6e

lines 45–48why, one step back
45 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 back
49 })

Merge branch 'integration'visionmediabefore adoption8d4ef6e

lines 50–59why, one step back
50 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 back
60 })

Merge branch 'integration'visionmediabefore adoption8d4ef6e

lines 61–85why, one step back
61 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 end

Merge branch 'partials'visionmediabefore adoption28f2ad0

line 86why, one step back
86 end

Merge branch 'integration'visionmediabefore adoption8d4ef6e

lines 87–90why, one step back
87 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 back
91 })

Merge branch 'integration'visionmediabefore adoption8d4ef6e

lines 92–127why, one step back
92 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 end

Merge branch 'partial-index-and-length'visionmediabefore adoptionb2093d6

line 128why, one step back
128 end

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 129–131why, one step back
129 end
130 end131

Closes #52visionmediabefore adoption161c9f9

lines 132–136why, one step back
132 describe '#render()'
133 before_each134 set('views', 'spec/fixtures')135 end136

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

lines 137–139why, one step back
137 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 back
140 this.render('hello.html.haml', {}, function(err, content){

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

line 141why, one step back
141 if (err) this.error(err)

Merge branch 'rename-halt'visionmediabefore adoption531990b

line 142why, one step back
142 else this.respond(203, content)

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

lines 143–144why, one step back
143 })
144 })

Merge branch 'better-haml'visionmediabefore adoptionbdf9f88

line 145why, one step back
145 get('/').body.should.include '<html>\n<body>'

Added Request#render() callback function. Closes #258visionmediabefore adoption7b9f18b

lines 146–149why, one step back
146 get('/').status.should.eql 203
147 end148 end149

Closes #52visionmediabefore adoption161c9f9

lines 150–153why, one step back
150 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 back
154 this.render('hello.html.haml')

Closes #52visionmediabefore adoption161c9f9

line 155why, one step back
155 })

Merge branch 'better-haml'visionmediabefore adoptionbdf9f88

line 156why, one step back
156 get('/').body.should.include '<html>\n<body>'

Closes #52visionmediabefore adoption161c9f9

lines 157–162why, one step back
157 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 back
163 this.render('page.html.haml', { layout: false })

Closes #52visionmediabefore adoption161c9f9

lines 164–169why, one step back
164 })
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 back
170 this.render('hello.html.haml')

Closes #52visionmediabefore adoption161c9f9

line 171why, one step back
171 })

Merge branch 'etag'visionmediabefore adoptionb5d6f1a

line 172why, one step back
172 get('/').headers['Content-Type'].should.eql 'text/html'

Closes #52visionmediabefore adoption161c9f9

lines 173–178why, one step back
173 end
174 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 back
179 this.render('hello.html.haml', { layout: 'front' })

Closes #52visionmediabefore adoption161c9f9

line 180why, one step back
180 })

Updated ext submodulevisionmediabefore adoption8108876

line 181why, one step back
181 -{ get('/') }.should.throw_error 'ENOENT, No such file or directory'

Closes #52visionmediabefore adoption161c9f9

lines 182–188why, one step back
182 end
183 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 back
189 this.render('hello.html.haml', { layout: 'page' })

Closes #52visionmediabefore adoption161c9f9

lines 190–195why, one step back
190 })
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 back
196 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 back
206 describe 'when layout: false'
207 it 'should render the view only'208 get('/', function(){

Merge branch 'flip-views'visionmediabefore adoption6b13fc9

line 209why, one step back
209 this.render('hello.html.haml', { layout: false })

Closes #52visionmediabefore adoption161c9f9

lines 210–218why, one step back
210 })
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 back
219 this.render('user.html.invalid')

Closes #52visionmediabefore adoption161c9f9

lines 220–227why, one step back
220 })
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 back
228 this.render('user.html.haml', {

Closes #52visionmediabefore adoption161c9f9

lines 229–240why, one step back
229 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 back
241 this.render('user.html.haml', {

Merge branch 'integration'visionmediabefore adoption289487c

line 242why, one step back
242 layout: 'layout-user',

Closes #52visionmediabefore adoption161c9f9

lines 243–257why, one step back
243 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 back
258 this.render('article.html.haml', {

Closes #52visionmediabefore adoption161c9f9

lines 259–270why, one step back
259 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 end

Release 0.7.2visionmediabefore adoptiond0a8bb5

lines 271–272why, one step back
271 end
272end