Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests showing usage of multiple parameters

  • Loading branch information...
commit d9bcc7d53627af122a08d67b0626966ed90bc45f 1 parent 13f7c02
@tarruda authored
Showing with 35 additions and 4 deletions.
  1. +3 −0  Makefile
  2. +3 −3 src/router.coffee
  3. +29 −1 test/router.coffee
View
3  Makefile
@@ -3,6 +3,9 @@ TESTS = ./test/support/http.js ./test/router.coffee
test:
@./node_modules/.bin/mocha --require should --compilers coffee:coffee-script $(TESTS)
+test-docs:
+ @./node_modules/.bin/mocha --reporter doc --require should --compilers coffee:coffee-script $(TESTS) > tests.html
+
compile:
@./node_modules/.bin/coffee -o lib src
View
6 src/router.coffee
@@ -7,11 +7,11 @@ escapeRegex = (s) -> s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
absoluteUrl = (req, pathname, search) ->
protocol = 'http'
- if req.protocol == 'https'
+ if req.headers['x-protocol'] == 'https'
protocol = 'https'
rv = [protocol, '://', req.headers.host]
- if req.port
- rv.push(":#{req.port}")
+ if port = req.headers['x-port']
+ rv.push(":#{port}")
rv.push(pathname)
if search
rv.push(search)
View
30 test/router.coffee
@@ -254,11 +254,39 @@ describe 'Accessing branch urls without trailing slash', ->
res.headers['location'].should.eql(l)
done()
+ it 'should use protocol/port info in the request', (done) ->
+ app.request()
+ .set('Host', 'www.google.com')
+ .set('X-Protocol', 'https')
+ .set('X-Port', 8080)
+ .get('/some/branch/url?var1=val1')
+ .end (res) ->
+ res.statusCode.should.eql(301)
+ l = 'https://www.google.com:8080/some/branch/url/?var1=val1'
+ res.headers['location'].should.eql(l)
+ done()
+
+
+describe 'Multiple parameters', ->
+ router = createRouter()
+ app = connect()
+ app.use(router.route)
+
+ router.get '/<id1>/branch/<int:id2>,<float:id3>/list', (req, res) ->
+ res.write(JSON.stringify(req.params))
+ res.end()
+
+ it 'should keep parameter order', (done) ->
+ app.request()
+ .get('/abc/branch/56,7.7756/list')
+ .end (res) ->
+ JSON.parse(res.body).should.eql(['abc', 56, 7.7756])
+ done()
+
describe 'Custom parser', ->
router = createRouter
options: (str) ->
- console.log str
rv = {}
options = str.split('/')
for option in options

0 comments on commit d9bcc7d

Please sign in to comment.
Something went wrong with that request. Please try again.