Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Composer redesign #779

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
WIP
molily committed Mar 16, 2014
commit 78a4520c1c56be4f03b92e1c3501934076ac3ff8
1 change: 0 additions & 1 deletion Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -401,7 +401,6 @@ module.exports = (grunt) ->
# Test
# ----
grunt.registerTask 'prepareTest', [
'clean'
'coffee:test'
'coffee:src'
'urequire'
9 changes: 6 additions & 3 deletions src/chaplin/lib/utils.coffee
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

_ = require 'underscore'
support = require 'chaplin/lib/support'
mediator = require 'chaplin/mediator'

# Utilities
# ---------
@@ -98,11 +97,15 @@ utils =

# Returns the url for a named route and any params.
reverse: (criteria, params, query) ->
mediator.execute 'router:reverse', criteria, params, query
# Require mediator here to avoid a circular dependency
# between utils and mediator.
require('chaplin/mediator').execute 'router:reverse', criteria, params, query

# Redirects to URL, route name or controller and action pair.
redirectTo: (pathDesc, params, options) ->
mediator.execute 'router:route', pathDesc, params, options
# Require mediator here to avoid a circular dependency
# between utils and mediator.
require('chaplin/mediator').execute 'router:route', pathDesc, params, options

# Query parameters Helpers
# --------------
40 changes: 20 additions & 20 deletions test/spec/layout_spec.coffee
Original file line number Diff line number Diff line change
@@ -47,21 +47,21 @@ define [
document.body.removeChild element

expectWasRouted = (linkAttributes) ->
stub = sinon.spy()
mediator.setHandler 'router:route', stub
spy = sinon.spy()
mediator.setHandler 'router:route', spy
appendClickRemove createLink linkAttributes
expect(stub).was.calledOnce()
[passedPath] = stub.firstCall.args
expect(spy).was.calledOnce()
[passedPath] = spy.firstCall.args
expect(passedPath).to.eql url: linkAttributes.href
mediator.unsubscribe '!router:route', stub
stub
mediator.removeHandlers ['router:route']
spy

expectWasNotRouted = (linkAttributes) ->
spy = sinon.spy()
mediator.setHandler 'router:route', spy
appendClickRemove createLink linkAttributes
expect(spy).was.notCalled()
mediator.unsubscribe '!router:route', spy
mediator.removeHandlers ['router:route']
spy

beforeEach ->
@@ -105,14 +105,14 @@ define [
path = '/internal/link'
query = 'foo=bar&baz=qux'

stub = sinon.spy()
mediator.setHandler 'router:route', stub
spy = sinon.spy()
mediator.setHandler 'router:route', spy
linkAttributes = href: "#{path}?#{query}"
appendClickRemove createLink linkAttributes
expect(stub).was.calledOnce()
[passedPath] = stub.firstCall.args
expect(spy).was.calledOnce()
[passedPath] = spy.firstCall.args
expect(passedPath).to.eql url: linkAttributes.href
mediator.unsubscribe '!router:route', stub
mediator.removeHandlers ['router:route']

it 'should not route links without href attributes', ->
expectWasNotRouted name: 'foo'
@@ -139,24 +139,24 @@ define [

it 'should not route clicks on external links', ->
old = window.open
window.open = sinon.stub()
window.open = sinon.spy()
expectWasNotRouted href: 'http://example.com/'
expectWasNotRouted href: 'https://example.com/'
expect(window.open).was.notCalled()
window.open = old

it 'should route clicks on elements with the “go-to” class', ->
stub = sinon.stub()
mediator.setHandler 'router:route', stub
spy = sinon.spy()
mediator.setHandler 'router:route', spy
path = '/internal/link'
span = document.createElement 'span'
span.className = 'go-to'
span.setAttribute 'data-href', path
appendClickRemove span
expect(stub).was.calledOnce()
passedPath = stub.firstCall.args[0]
expect(spy).was.calledOnce()
passedPath = spy.firstCall.args[0]
expect(passedPath).to.eql url: path
mediator.unsubscribe '!router:route', stub
mediator.removeHandlers ['router:route']

# With custom external checks
# ---------------------------
@@ -193,13 +193,13 @@ define [
it 'openExternalToBlank=true should open external links in a new tab', ->
old = window.open

window.open = sinon.stub()
window.open = sinon.spy()
layout.dispose()
layout = new Layout title: '', openExternalToBlank: true
expectWasNotRouted href: 'http://www.example.org/'
expect(window.open).was.called()

window.open = sinon.stub()
window.open = sinon.spy()
layout.dispose()
layout = new Layout title: '', openExternalToBlank: true
expectWasNotRouted href: '/foo', rel: "external"
2 changes: 2 additions & 0 deletions test/spec/mediator_spec.coffee
Original file line number Diff line number Diff line change
@@ -62,6 +62,8 @@ define [
mediator.setHandler name, spy
expect(mediator.execute name).to.be resp

# TODO: Test removeHandlers

it 'should support sealing itself', ->
strict = do (-> 'use strict'; !this)
return unless strict