From d113833e9a512e6349fc6ac8b23e2daf485affaa Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 9 Dec 2012 16:02:00 +0100 Subject: [PATCH] fix xml responder and result image specs --- Gemfile.lock | 2 +- lib/travis/api/app/responders/xml.rb | 25 ++++++++++++++++-------- spec/integration/v1/repositories_spec.rb | 6 +++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9c1d8f86..af4ce8e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,7 +42,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 2afee3dcfe6dfde30a797646e9772c397cd8d040 + revision: 714090635924650998b3a3d0f18b39d9cfd46839 specs: travis-core (0.0.1) actionmailer (~> 3.2.3) diff --git a/lib/travis/api/app/responders/xml.rb b/lib/travis/api/app/responders/xml.rb index b9191852..b6a075a6 100644 --- a/lib/travis/api/app/responders/xml.rb +++ b/lib/travis/api/app/responders/xml.rb @@ -3,15 +3,16 @@ module Travis::Api::App::Responders TEMPLATE = File.read(__FILE__).split("__END__").last.strip STATUS = { - nil => 'Unknown', - 0 => 'Success', - 1 => 'Failure' + default: 'Unknown', + passed: 'Success', + failed: 'Failure', + errored: 'Error', + canceld: 'Canceled', } ACTIVITY = { - nil => 'Sleeping', - 'started' => 'Building', - 'finished' => 'Sleeping' + default: 'Sleeping', + started: 'Building' } def apply? @@ -28,13 +29,21 @@ module Travis::Api::App::Responders { name: resource.slug, url: [Travis.config.domain, resource.slug].join('/'), - activity: ACTIVITY[last_build.try(:state)], + activity: activity, label: last_build.try(:number), - status: STATUS[resource.last_build_result_on(request.params)], + status: status, time: last_build.finished_at.try(:strftime, '%Y-%m-%dT%H:%M:%S.%L%z') } end + def status + STATUS[last_build.state.to_sym] || STATUS[:default] + end + + def activity + ACTIVITY[last_build.state.to_sym] || ACTIVITY[:default] + end + def last_build @last_build ||= resource.last_build end diff --git a/spec/integration/v1/repositories_spec.rb b/spec/integration/v1/repositories_spec.rb index 3e4311ae..9d4da90b 100644 --- a/spec/integration/v1/repositories_spec.rb +++ b/spec/integration/v1/repositories_spec.rb @@ -49,17 +49,17 @@ describe 'v1 repos' do it '"unknown" when it only has one build that is not finished' do Build.delete_all Factory(:build, repository: repo, state: :created, result: nil) - repo.update_attributes!(last_build_state: nil) + repo.builds.update_all(state: 'started') get('/svenfuchs/minimal.png').should deliver_result_image_for('unknown') end it '"failing" when the last build has failed' do - repo.update_attributes!(last_build_state: 'failed') + repo.builds.update_all(state: 'failed') get('/svenfuchs/minimal.png').should deliver_result_image_for('failing') end it '"passing" when the last build has passed' do - repo.update_attributes!(last_build_state: 'passed') + repo.builds.update_all(state: 'passed') get('/svenfuchs/minimal.png').should deliver_result_image_for('passing') end