 require 'travis/location'
 require 'travis/line_number_parser'
+
+Travis.DontSetupModelForControllerMixin = Ember.Mixin.create
+  # I've override setup to *not* set controller's model
+  # this can be remove when this patch will be merged https://github.com/emberjs/ember.js/pull/2044
+  # this will allow us to override setting up model for a controller
+  setup: (context) ->
+    @redirected = false
+    @_checkingRedirect = true
+
+    @redirect(context)
+
+    @_checkingRedirect = false
+    if @redirected
+      return false
+
+    controller = @controllerFor(@routeName, context)
+
+    @setupController(controller, context)
+    @renderTemplate(controller, context);
 
 Ember.Router.reopen
   location: (if testMode? then Ember.NoneLocation.create() else Travis.Location.create())

Travis.PullRequestsRoute = Travis.AbstractBuildsRoute.extend(contentType: 'pull_requests')
Travis.BranchesRoute = Travis.AbstractBuildsRoute.extend(contentType: 'branches')

Travis.BuildRoute = Ember.Route.extend
  renderTemplate: ->
    @render 'build', outlet: 'pane', into: 'repo'


    repo.set('job', model)
    repo.activate('job')

Travis.RepoIndexRoute = Ember.Route.extend Travis.DontSetupModelForControllerMixin,
  setupController: (controller, model) ->
    @container.lookup('controller:repo').activate('current')

  renderTemplate: ->
    @render 'build', outlet: 'pane', into: 'repo'

Travis.RepoRoute = Ember.Route.extend Travis.DontSetupModelForControllerMixin,
  renderTemplate: ->
    @render 'repo'

