Skip to content
Myr

spec.plugins.view.js

This file

Path

spec/spec.plugins.view.js

152 lines · 4.7 KiB · JavaScript

Last changed by

Merge branch 'async-cache'visionmediabefore adoption7606f1b

History of this file

Take it

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

Added install section in readmevisionmediabefore adoptionbbb858e

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

lines 14–82why, one step back
14
15 describe '#render()'16 before_each17 set('views', 'spec/fixtures')18 end19 20 describe 'given a valid view name'21 describe 'and layout of the same type exists'22 it 'should render the layout and view'23 get('/', function(){24 this.render('hello.haml.html')25 })26 get('/').body.should.include '<html><body>'27 get('/').body.should.include '<h2>Hello'28 end29 30 it 'should default context to the current request'31 get('/', function(){32 this.title = 'Welcome'33 this.render('page.haml.html', { layout: false })34 })35 get('/').body.should.include '<title>Welcome'36 end37 38 it 'should set the content type based on the last path segment'39 get('/', function(){40 this.render('hello.haml.html')41 })42 get('/').headers['content-type'].should.eql 'text/html'43 end44 end45 46 describe 'and layout of the same type does not exist'47 it 'should throw an error'48 get('/', function(){49 this.render('hello.haml.html', { layout: 'front' })50 })51 -{ get('/') }.should.throw_error 'No such file or directory'52 end53 end54 55 describe 'given a custom layout name'56 it 'should render the layout and view'57 get('/', function(){58 this.title = 'Express'59 this.render('hello.haml.html', { layout: 'page' })60 })61 get('/').body.should.include '<title>Express'62 get('/').body.should.include '<h2>Hello'63 end64 end65 66 describe 'when layout: false'67 it 'should render the view only'68 get('/', function(){69 this.render('hello.haml.html', { layout: false })70 })71 get('/').body.should.not.include '<body>'72 get('/').body.should.include '<h2>Hello'73 end74 end75 76 describe 'when "cache view contents" is enabled'77 it 'should read the views into memory only once'78 enable('cache view contents')79 get('/', function(){80 this.render('hello.haml.html')81 })82 get('/cached', function(){

Merge branch 'async-cache'visionmediabefore adoption7606f1b

lines 83–86why, one step back
83 var self = this
84 this.cache.get('view:spec/fixtures/hello.haml.html', function(val){85 self.halt(200, val ? 'yes' : 'no')86 })

Closes #52visionmediabefore adoption161c9f9

lines 87–150why, one step back
87 })
88 get('/cached').body.should.eql 'no'89 get('/')90 get('/cached').body.should.eql 'yes'91 get('/')92 get('/cached').body.should.eql 'yes'93 end94 end95 96 describe 'when engine cannot be found'97 it 'should throw an error'98 get('/', function(){99 this.render('user.invalid.html')100 })101 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"102 end103 end104 105 describe 'when locals are passed'106 it 'should have direct access to locals'107 get('/user', function(){108 this.render('user.haml.html', {109 locals: {110 name: 'tj',111 email: 'tj@vision-media.ca'112 }113 })114 })115 get('/user').body.should.include '<h1>tj'116 get('/user').body.should.include '<p>tj@vision-media.ca'117 end118 119 it 'should have direct access to locals within the layout'120 get('/user', function(){121 this.render('user.haml.html', {122 layout: 'layout.user',123 locals: {124 name: 'tj',125 email: 'tj@vision-media.ca'126 }127 })128 })129 get('/user').body.should.include '<title>Viewing tj'130 get('/user').body.should.include '<h1>tj'131 get('/user').body.should.include '<p>tj@vision-media.ca'132 end133 end134 135 describe 'when context is passed'136 it 'should evaluate in context to that object'137 get('/article', function(){138 this.render('article.haml.html', {139 context: {140 name: 'Writing a Node.js Web Application'141 }142 })143 })144 get('/article').body.should.include '<h2>Writing a Node.js Web Application'145 end146 end147 148 end149 150 end

Added install section in readmevisionmediabefore adoptionbbb858e

lines 151–152why, one step back
151 end
152end