fix xml responder and result image specs

This commit is contained in:
Sven Fuchs 2012-12-09 16:02:00 +01:00
parent a78e9d26cf
commit d113833e9a
3 changed files with 21 additions and 12 deletions

View File

@ -42,7 +42,7 @@ GIT
GIT GIT
remote: git://github.com/travis-ci/travis-core.git remote: git://github.com/travis-ci/travis-core.git
revision: 2afee3dcfe6dfde30a797646e9772c397cd8d040 revision: 714090635924650998b3a3d0f18b39d9cfd46839
specs: specs:
travis-core (0.0.1) travis-core (0.0.1)
actionmailer (~> 3.2.3) actionmailer (~> 3.2.3)

View File

@ -3,15 +3,16 @@ module Travis::Api::App::Responders
TEMPLATE = File.read(__FILE__).split("__END__").last.strip TEMPLATE = File.read(__FILE__).split("__END__").last.strip
STATUS = { STATUS = {
nil => 'Unknown', default: 'Unknown',
0 => 'Success', passed: 'Success',
1 => 'Failure' failed: 'Failure',
errored: 'Error',
canceld: 'Canceled',
} }
ACTIVITY = { ACTIVITY = {
nil => 'Sleeping', default: 'Sleeping',
'started' => 'Building', started: 'Building'
'finished' => 'Sleeping'
} }
def apply? def apply?
@ -28,13 +29,21 @@ module Travis::Api::App::Responders
{ {
name: resource.slug, name: resource.slug,
url: [Travis.config.domain, resource.slug].join('/'), url: [Travis.config.domain, resource.slug].join('/'),
activity: ACTIVITY[last_build.try(:state)], activity: activity,
label: last_build.try(:number), 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') time: last_build.finished_at.try(:strftime, '%Y-%m-%dT%H:%M:%S.%L%z')
} }
end 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 def last_build
@last_build ||= resource.last_build @last_build ||= resource.last_build
end end

View File

@ -49,17 +49,17 @@ describe 'v1 repos' do
it '"unknown" when it only has one build that is not finished' do it '"unknown" when it only has one build that is not finished' do
Build.delete_all Build.delete_all
Factory(:build, repository: repo, state: :created, result: nil) 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') get('/svenfuchs/minimal.png').should deliver_result_image_for('unknown')
end end
it '"failing" when the last build has failed' do 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') get('/svenfuchs/minimal.png').should deliver_result_image_for('failing')
end end
it '"passing" when the last build has passed' do 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') get('/svenfuchs/minimal.png').should deliver_result_image_for('passing')
end end