Skip to content

Commit

Permalink
added the ability to generate non-absolute url
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Giachino committed Jun 13, 2014
1 parent e66c490 commit 15b327c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 237 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
Resources/test/src/ng-router.js
Resources/test/spec/ng-router.js
5 changes: 3 additions & 2 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = (grunt) ->

jasmine:
ng_router:
src: 'Resources/test/src/*.js'
src: ['node_modules/underscore/underscore.js', 'Resources/test/src/*.js']
options:
specs: 'Resources/test/spec/*.js'

Expand All @@ -37,4 +37,5 @@ module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-notify'

grunt.registerTask 'default', ['test']
grunt.registerTask 'test', ['coffee', 'jasmine']
grunt.registerTask 'test', ['coffee', 'jasmine']
grunt.registerTask 'release', ['coffee:dist']
9 changes: 6 additions & 3 deletions Resources/coffee/ng-router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ class cypress.NgRouter
route.setDefaultHost @host
@routes.push route

generateResourceUrl: (routeName) ->
generateResourceUrl: (routeName, absolute = true) ->
path = @findRoute(routeName)?.getResource()
host = @findRoute(routeName)?.getHost()
"#{cypress.NgRouter.scheme}://#{host}#{cypress.NgRouter.baseUrl}#{path}"
if absolute
host = @findRoute(routeName)?.getHost()
return "#{cypress.NgRouter.scheme}://#{host}#{cypress.NgRouter.baseUrl}#{path}"
else
return path

findRoute: (routeName) ->
matchedRoute = null
Expand Down
13 changes: 10 additions & 3 deletions Resources/public/ng-router.js

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

53 changes: 52 additions & 1 deletion Resources/test/spec/ng-router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,55 @@ describe 'cypress.Route', ->
it 'should respond a default host without tokens', ->
route.setData {defaults: {}, hosttokens: []}
route.setDefaultHost 'test.dev'
expect(route.getHost()).toBe 'test.dev'
expect(route.getHost()).toBe 'test.dev'

describe 'cypress.NgRouter', ->
ngRouter = null
baseData = {}
aRoute =
test: {
tokens: [
[
"variable",
"/",
"[^/\.]++",
"id"
],
[
"text",
"/test"
]
],
defaults: {},
requirements: {
_method: "GET",
_format: "json|jsonp|xml|html"
},
hosttokens: [ ]
},
beforeEach ->
ngRouter = new cypress.NgRouter()
baseData =
base_url: '/base_url'
prefix: 'prefix'
host: 'host'
scheme: 'scheme'
routes: aRoute
cypress.NgRouter.setData baseData

it 'should have a findRoute method', ->
expect(ngRouter.findRoute).toBeDefined()

it 'should match routes by name', ->
expect(ngRouter.findRoute('non_existent')).toBeNull()
expect(ngRouter.findRoute('test')).not.toBeNull()

it 'should generate a route by its name', ->
expect(ngRouter.generateResourceUrl('test')).toBe('scheme://host/base_url/test/:id')

it 'should generate a route by its name, without the absolute path', ->
expect(ngRouter.generateResourceUrl('test', false)).toBe('/test/:id')

it 'should have a generateResourceUrl method', ->
expect(ngRouter.generateResourceUrl).toBeDefined()

105 changes: 0 additions & 105 deletions Resources/test/spec/ng-router.js

This file was deleted.

120 changes: 0 additions & 120 deletions Resources/test/src/ng-router.js

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
},
"homepage": "https://github.com/matteosister/CypressAngularNgRoutingBundle",
"devDependencies": {
"grunt-contrib-watch": "~0.5.3",
"grunt": "^0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-coffee": "~0.10.0",
"grunt-contrib-jasmine": "~0.6.1",
"grunt": "~0.4.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-notify": "~0.2.17",
"grunt-cli": "~0.1.13"
"underscore": "^1.6.0"
},
"scripts": {
"test": "./node_modules/.bin/grunt"
Expand Down

0 comments on commit 15b327c

Please sign in to comment.