Skip to content
Myr

Closes #52

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fs.readFile becomes fs.readFileSync when testing Merge branch 'view-specs'

authored by visionmedia · committed by visionmedia · parents e1152f6, 2a099da · Browse files · 11 files+163 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+163 added−9 removed

  • tests:+158 added−1 removed
  • other:+5 added−8 removed

11 files+163 added−9 removed

modified:lib/express/plugins/cache.js+3 added-6 removed
207 unmodified lines
208 * @api private209 */210 211 startReaper: function() {212 var self = this,213 oneDay = 86400000,214 oneHour = 3600000215 setInterval(function(){216 self.store.reap(self.lifetime || oneDay)217 }, self.reapInterval || self.reapEvery || oneHour)212 setInterval(function(self){213 self.store.reap(self.lifetime || (1).day)214 }, this.reapInterval || this.reapEvery || (1).hour, this)215 }216 }217})
modified:lib/express/plugins/view.js+2 added-2 removed
modified:lib/express/spec/mocks.js+14 added-1 removed
3 unmodified lines
4/**5 * Module dependencies.6 */7 8var utils = require('express/utils')8var utils = require('express/utils'),9 fs = require('fs')1011/**12 * Mock fs.readFile()13 */14 15fs.readFile = function(path, fn) {16 try {17 fn(null, fs.readFileSync(path))18 } catch (e) {19 fn(e)20 }21}2223// --- MockRequest2425var MockRequest = new Class({26
122 unmodified lines
added:spec/fixtures/article.haml.html+1 added
added:spec/fixtures/hello.haml.html+1 added
added:spec/fixtures/layout.haml.html+2 added
added:spec/fixtures/layout.user.haml.html+2 added
added:spec/fixtures/page.haml.html+2 added
added:spec/fixtures/user.haml.html+2 added
1%h1= name2%p= email
added:spec/fixtures/user.invalid.html
modified:spec/spec.plugins.view.js+134 added
9 unmodified lines
10 set('root', 'spec')11 set('views').should.eql 'spec/views'12 end13 end14 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(){83 return this.cache.get('spec/fixtures/hello.haml.html') ? 'yes' : 'no'84 })85 get('/cached').body.should.eql 'no'86 get('/')87 get('/cached').body.should.eql 'yes'88 get('/')89 get('/cached').body.should.eql 'yes'90 end91 end92 93 describe 'when engine cannot be found'94 it 'should throw an error'95 get('/', function(){96 this.render('user.invalid.html')97 })98 -{ get('/') }.should.throw_error "Cannot find module 'invalid'"99 end100 end101 102 describe 'when locals are passed'103 it 'should have direct access to locals'104 get('/user', function(){105 this.render('user.haml.html', {106 locals: {107 name: 'tj',108 email: 'tj@vision-media.ca'109 }110 })111 })112 get('/user').body.should.include '<h1>tj'113 get('/user').body.should.include '<p>tj@vision-media.ca'114 end115 116 it 'should have direct access to locals within the layout'117 get('/user', function(){118 this.render('user.haml.html', {119 layout: 'layout.user',120 locals: {121 name: 'tj',122 email: 'tj@vision-media.ca'123 }124 })125 })126 get('/user').body.should.include '<title>Viewing tj'127 get('/user').body.should.include '<h1>tj'128 get('/user').body.should.include '<p>tj@vision-media.ca'129 end130 end131 132 describe 'when context is passed'133 it 'should evaluate in context to that object'134 get('/article', function(){135 this.render('article.haml.html', {136 context: {137 name: 'Writing a Node.js Web Application'138 }139 })140 })141 get('/article').body.should.include '<h2>Writing a Node.js Web Application'142 end143 end144 145 end146 147 end148 end149end