         done()
 
     it 'should not start the same controller if params match', (done) ->
-      mediator.publish 'router:match', route1, params, options
+      publishMatch route1, params, options
 
       loadTest1Controller ->
         proto = Test1Controller.prototype
         initialize = sinon.spy proto, 'initialize'
         action     = sinon.spy proto, 'show'
 
-        mediator.publish 'router:match', route1, params, options
+        publishMatch route1, params, options
 
         loadTest1Controller ->
           expect(initialize).was.notCalled()

      spy = sinon.spy()
      mediator.subscribe '!router:changeURL', spy

      options =
        path: 'my-little-path', changeURL: false,
        controller: 'test1', action: 'show'
      mediator.publish 'router:match', route1, params, options

      loadTest1Controller ->
        expect(spy).was.notCalled()

      initialize = sinon.spy proto, 'initialize'
      action     = sinon.spy proto, 'show'

      paramsStore = []
      optionsStore = []

      for i in [0..1]
        refreshParams()
        paramsStore.push params
        optionsStore.push options
        options.forceStartup = true if i is 1
        publishMatch route1, params, options

      loadTest1Controller ->
        for i in [0..1]
          for spy in [initialize, action]
            [passedParams, passedRoute, passedOptions] = spy.args[i]
            expect(passedParams).to.eql paramsStore[i]
            expect(passedRoute.controller).to.be route1.controller
            expect(passedRoute.action).to.be route1.action
            expectedOptions = create optionsStore[i], {
              changeURL: true
              forceStartup: (if i is 0 then false else true)
            }
            expect(passedOptions).to.eql expectedOptions

        initialize.restore()
        action.restore()

        done()

    it 'should save the controller, action, params and path', (done) ->
      publishMatch route1, params, options
      publishMatch route2, params, options

      # Check that previous route is saved
      loadTest1Controller -> loadTest2Controller ->
        d = dispatcher
        expect(d.previousRoute.controller).to.be 'test1'
        expect(d.currentController).to.be.a Test2Controller
        expect(d.currentRoute).to.eql create(route2, previous: {})
        expect(d.currentParams).to.eql params

        done()

    it 'should add the previous controller name to the route', (done) ->
      action = sinon.spy Test2Controller.prototype, 'show'

      publishMatch route1, params, options

      loadTest1Controller ->
        publishMatch route2, params, options

        loadTest2Controller ->
          expect(action).was.calledOnce()
          route = action.firstCall.args[1]
          expect(route.controller).to.be route2.controller
          expect(route.action).to.be route2.action
          expect(route.previous).to.be.an 'object'
          expect(route.previous.controller).to.be route1.controller
          expect(route.previous.action).to.be route1.action

          action.restore()

          done()

    it 'should dispose inactive controllers', (done) ->
      dispose = sinon.spy Test1Controller.prototype, 'dispose'
      publishMatch route1, params, options
      publishMatch route2, params, options

      loadTest1Controller -> loadTest2Controller ->
        # It should pass the params and the new controller name
        expect(dispose).was.calledOnce()
        [passedParams, passedRoute] = dispose.firstCall.args
        expect(passedParams).to.eql params
        expect(passedRoute.controller).to.eql route2.controller
        expect(passedRoute.action).to.eql route2.action
        expect(passedRoute.path).to.eql route2.path

        dispose.restore()

        done()

    it 'should fire beforeControllerDispose events', (done) ->
      publishMatch route1, params, options

      beforeControllerDispose = sinon.spy()
      mediator.subscribe 'beforeControllerDispose', beforeControllerDispose

      # Now route to Test2Controller
      publishMatch route2, params, options

      loadTest1Controller -> loadTest2Controller ->
        expect(beforeControllerDispose).was.calledOnce()

        # Event payload should be the now disposed controller
        passedController = beforeControllerDispose.firstCall.args[0]
        expect(passedController).to.be.a Test1Controller
