diff --git a/assets/scripts/app/controllers.coffee b/assets/scripts/app/controllers.coffee index f1b4f520..c073461a 100644 --- a/assets/scripts/app/controllers.coffee +++ b/assets/scripts/app/controllers.coffee @@ -48,6 +48,8 @@ Travis.FirstSyncController = Em.Controller.extend isSyncing: Ember.computed.alias('user.isSyncing') +Travis.IndexErrorController = Em.Controller.extend() + require 'controllers/accounts' require 'controllers/build' require 'controllers/builds' diff --git a/assets/scripts/app/models/repo.coffee b/assets/scripts/app/models/repo.coffee index f582fb10..e1b835de 100644 --- a/assets/scripts/app/models/repo.coffee +++ b/assets/scripts/app/models/repo.coffee @@ -140,7 +140,10 @@ require 'travis/model' if repos.length > 0 repos[0] else - @fetch(slug: slug).then (repos) -> Ember.get(repos, 'firstObject') + @fetch(slug: slug).then (repos) -> + error = new Error('repo not found') + error.slug = slug + Ember.get(repos, 'firstObject') || throw(error) # buildURL: (slug) -> # if slug then slug else 'repos' diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 9b375015..8d913c1c 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -252,9 +252,15 @@ Travis.RepoRoute = Ember.Route.extend Travis.Repo.fetchBySlug(slug) actions: - error: -> - Ember.run.next this, -> - @render('repos/not_found', outlet: 'main') + error: (error) -> + # if error throwed has a slug (ie. it was probably repo not found) + # set the slug on index.error controller to allow to properly + # display the repo information + if error.slug + this.controllerFor('index.error').set('slug', error.slug) + + # bubble to the top + return true Travis.IndexRoute = Ember.Route.extend renderTemplate: -> diff --git a/assets/scripts/app/templates/repos/not_found.hbs b/assets/scripts/app/templates/index/error.hbs similarity index 100% rename from assets/scripts/app/templates/repos/not_found.hbs rename to assets/scripts/app/templates/index/error.hbs diff --git a/assets/scripts/spec/integration/routes_spec.coffee b/assets/scripts/spec/integration/routes_spec.coffee index b8130988..1cfe3fe8 100644 --- a/assets/scripts/spec/integration/routes_spec.coffee +++ b/assets/scripts/spec/integration/routes_spec.coffee @@ -6,4 +6,8 @@ module "Router", test 'renders notFound template when URL can\t be found', -> visit('/somehing/something/something/.../dark/side/..../something/something/something/.../complete').then -> - equal('The requested page was not found.', $('#main').text().trim()) + equal($('#main').text().trim(), 'The requested page was not found.') + +test 'renders repo not found information when repo can\'t be found', -> + visit('/what-is-this/i-dont-even').then -> + equal($('#main').text().trim(), 'The repository at what-is-this/i-dont-even was not found.') diff --git a/assets/scripts/spec/support/mocks.coffee b/assets/scripts/spec/support/mocks.coffee index e4786764..c1ce5a47 100644 --- a/assets/scripts/spec/support/mocks.coffee +++ b/assets/scripts/spec/support/mocks.coffee @@ -77,7 +77,9 @@ $.mockjax if !settings.data this.responseText = { repos: repos } else if slug = settings.data.slug - this.responseText = { repos: [$.detect(repos, (repository) -> repository.slug == slug)] } + repo = $.detect(repos, (repository) -> repository.slug == slug) + repos = if repo then [repo] else [] + this.responseText = { repos: repos } else if search = settings.data.search this.responseText = { repos: $.select(repos, (repository) -> repository.slug.indexOf(search) > -1).toArray() } else if settings.data.member