Skip to content

Commit

Permalink
route returns default host without tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosister committed Mar 4, 2014
1 parent 7b16c55 commit d81255f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module.exports = (grunt) ->
files:
'Resources/test/src/ng-router.js': ['Resources/coffee/ng-router.coffee']
'Resources/test/spec/ng-router.js': ['Resources/test/spec/ng-router.coffee']
dist:
options:
sourceMap: false
files:
'Resources/public/ng-router.js': ['Resources/coffee/ng-router.coffee']

jasmine:
ng_router:
Expand Down
6 changes: 6 additions & 0 deletions Resources/coffee/ng-router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class cypress.Route
setData: (data) ->
@data = data

setDefaultHost: (defaultHost) ->
@defaultHost = defaultHost

getResource: ->
out = ''
if @data.tokens?
Expand All @@ -20,6 +23,8 @@ class cypress.Route
getHost: ->
if @data.hosttokens.length > 0
@extractTokens(@data.hosttokens)
else
@defaultHost

extractTokens: (tokens = []) ->
out = ''
Expand Down Expand Up @@ -51,6 +56,7 @@ class cypress.NgRouter
route = new cypress.Route()
route.setName key
route.setData configs.routes[key]
route.setDefaultHost @host
@routes.push route

generateResourceUrl: (routeName) ->
Expand Down
36 changes: 22 additions & 14 deletions Resources/public/ng-router.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Resources/test/spec/ng-router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ describe 'cypress.Route', ->
route.setData {defaults: {}, tokens: [token, tokenText]}
expect(route.getResource()).not.toBe '/'

describe 'getHost', ->
it 'should respond a tokenized host', ->
route.setData {defaults: {}, hosttokens: [token]}
expect(route.getHost()).toBe '.:_format'

it 'should respond a default host without tokens', ->
route.setData {defaults: {}, hosttokens: []}
route.setDefaultHost 'test.dev'
expect(route.getHost()).toBe 'test.dev'
19 changes: 18 additions & 1 deletion Resources/test/spec/ng-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
return expect(route.extractTokens([token, tokenText])).toEqual('test.:_format');
});
});
return describe('getResource', function() {
describe('getResource', function() {
it('should respond / without tokens', function() {
route.setData({});
return expect(route.getResource()).toBe('/');
Expand All @@ -83,6 +83,23 @@
return expect(route.getResource()).not.toBe('/');
});
});
return describe('getHost', function() {
it('should respond a tokenized host', function() {
route.setData({
defaults: {},
hosttokens: [token]
});
return expect(route.getHost()).toBe('.:_format');
});
return it('should respond a default host without tokens', function() {
route.setData({
defaults: {},
hosttokens: []
});
route.setDefaultHost('test.dev');
return expect(route.getHost()).toBe('test.dev');
});
});
});

}).call(this);
7 changes: 7 additions & 0 deletions Resources/test/src/ng-router.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d81255f

Please sign in to comment.