Skip to content
Myr

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 file

Take 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 back
1

Merge branch 'ejs'visionmediabefore adoption2d132cd

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

Updated --version of node tested against in readmevisionmediabefore adoptionc429e88

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–46why, one step back
42 end
43 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 back
47 this.render('list.html.haml', { locals: { items: ['foo', 'bar'] }})

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 48–55why, one step back
48 })
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 back
56 return this.partial('item.html.haml', {

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 57–65why, one step back
57 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 back
66 return this.partial('video.html.haml', {

Merge branch 'partials'visionmediabefore adoption28f2ad0

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

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

lines 74–76why, one step back
74
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 back
77 return this.partial('article.html.haml', {

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

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

Merge branch 'partials'visionmediabefore adoption28f2ad0

lines 85–87why, one step back
85 end
86 end87

Closes #52visionmediabefore adoption161c9f9

lines 88–92why, one step back
88 describe '#render()'
89 before_each90 set('views', 'spec/fixtures')91 end92

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

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

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

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

Merge branch 'rename-halt'visionmediabefore adoption531990b

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

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

lines 99–100why, one step back
99 })
100 })

Merge branch 'better-haml'visionmediabefore adoptionbdf9f88

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

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

lines 102–105why, one step back
102 get('/').status.should.eql 203
103 end104 end105

Closes #52visionmediabefore adoption161c9f9

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

Closes #52visionmediabefore adoption161c9f9

line 111why, one step back
111 })

Merge branch 'better-haml'visionmediabefore adoptionbdf9f88

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

Closes #52visionmediabefore adoption161c9f9

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

Closes #52visionmediabefore adoption161c9f9

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

Closes #52visionmediabefore adoption161c9f9

line 127why, one step back
127 })

Merge branch 'etag'visionmediabefore adoptionb5d6f1a

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

Closes #52visionmediabefore adoption161c9f9

lines 129–134why, one step back
129 end
130 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 back
135 this.render('hello.html.haml', { layout: 'front' })

Closes #52visionmediabefore adoption161c9f9

line 136why, one step back
136 })

Updated ext submodulevisionmediabefore adoption8108876

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

Closes #52visionmediabefore adoption161c9f9

lines 138–144why, one step back
138 end
139 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 back
145 this.render('hello.html.haml', { layout: 'page' })

Closes #52visionmediabefore adoption161c9f9

lines 146–154why, one step back
146 })
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 back
155 this.render('hello.html.haml', { layout: false })

Closes #52visionmediabefore adoption161c9f9

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

Closes #52visionmediabefore adoption161c9f9

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

Closes #52visionmediabefore adoption161c9f9

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

Closes #52visionmediabefore adoption161c9f9

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

Closes #52visionmediabefore adoption161c9f9

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

Updated --version of node tested against in readmevisionmediabefore adoptionc429e88

lines 217–218why, one step back
217 end
218end