From 6bda358786a4d63ecc2310b007d551d67b0c1b97 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 3 Oct 2012 13:14:01 +0200 Subject: [PATCH] cleanup and some notes --- lib/travis/api/app/endpoint/branches.rb | 5 ++ lib/travis/api/app/endpoint/builds.rb | 5 ++ lib/travis/api/app/endpoint/repositories.rb | 8 +-- lib/travis/api/app/endpoint/users.rb | 1 + spec/integration/result_image_spec.rb | 62 ----------------- spec/integration/v1/repositories_spec.rb | 74 ++++++++++----------- 6 files changed, 52 insertions(+), 103 deletions(-) delete mode 100644 spec/integration/result_image_spec.rb diff --git a/lib/travis/api/app/endpoint/branches.rb b/lib/travis/api/app/endpoint/branches.rb index b77e4ae2..f5931bfd 100644 --- a/lib/travis/api/app/endpoint/branches.rb +++ b/lib/travis/api/app/endpoint/branches.rb @@ -6,6 +6,11 @@ class Travis::Api::App get '/' do respond_with all(params).run, type: :branches end + + # get '/:owner_name/:name/branches' do # v1 + # get '/repos/:owner_name/:name/branches' do # v2 + # respond_with all(params).run, type: :branches + # end end end end diff --git a/lib/travis/api/app/endpoint/builds.rb b/lib/travis/api/app/endpoint/builds.rb index c4b5021a..c1085a4e 100644 --- a/lib/travis/api/app/endpoint/builds.rb +++ b/lib/travis/api/app/endpoint/builds.rb @@ -7,6 +7,11 @@ class Travis::Api::App respond_with all(params).run end + # get '/:owner_name/:name/builds' do # v1 + # get '/repos/:owner_name/:name/builds' do # v2 + # respond_with all(params).run + # end + get '/:id' do respond_with one(params).run end diff --git a/lib/travis/api/app/endpoint/repositories.rb b/lib/travis/api/app/endpoint/repositories.rb index 2329e424..62391a5d 100644 --- a/lib/travis/api/app/endpoint/repositories.rb +++ b/lib/travis/api/app/endpoint/repositories.rb @@ -12,13 +12,13 @@ class Travis::Api::App end # TODO the format constraint neither seems to work nor fail? - get '/:id/cc.:format', format: 'xml' do + get '/:id/cc.:format', format: 'xml' do # v1 respond_with one(params).run end - # get '/:owner_name/:name.:format', format: 'png' do - # pass unless params.key?('owner_name') && params.key?('name') - # result_image service(:repositories, :one, params).run(:raise => false) + # get '/:owner_name/:name.?:format?' do # v1 + # get '/repos/:owner_name/:name.?:format?' do # v2 + # respond_with service(:repositories, :one, params).run(:raise => params[:format] != 'png') # end end end diff --git a/lib/travis/api/app/endpoint/users.rb b/lib/travis/api/app/endpoint/users.rb index 8712e230..7d0f268e 100644 --- a/lib/travis/api/app/endpoint/users.rb +++ b/lib/travis/api/app/endpoint/users.rb @@ -2,6 +2,7 @@ require 'travis/api/app' class Travis::Api::App class Endpoint + # TODO should this be /profile? class Users < Endpoint # Gives information about the currently logged in user. # diff --git a/spec/integration/result_image_spec.rb b/spec/integration/result_image_spec.rb deleted file mode 100644 index 8cfc26c1..00000000 --- a/spec/integration/result_image_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -# require 'spec_helper' -# -# describe 'Result images' do -# let!(:repo) { Factory(:repository, owner_name: 'svenfuchs', name: 'minimal') } -# -# describe 'GET /svenfuchs/minimal.png' do -# it '"unknown" when the repository does not exist' do -# get('/svenfuchs/does-not-exist.png').should deliver_result_image_for('unknown') -# end -# -# it '"unknown" when it only has one build that is not finished' do -# repo.update_attributes!(last_build_result: nil) -# 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_result: 1) -# 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_result: 0) -# get('/svenfuchs/minimal.png').should deliver_result_image_for('passing') -# end -# -# it '"passing" when there is a running build but the previous one has passed' do -# Factory(:build, repository: repo, state: :finished, result: nil, previous_result: 0) -# repo.update_attributes!(last_build_result: nil) -# get('/svenfuchs/minimal.png').should deliver_result_image_for('passing') -# end -# end -# -# describe 'GET /svenfuchs/minimal.png' do -# let(:commit) { Factory(:commit, branch: 'dev') } -# -# it '"unknown" when the repository does not exist' do -# get('/svenfuchs/does-not-exist.png?branch=dev').should deliver_result_image_for('unknown') -# end -# -# it '"unknown" when it only has a build that is not finished' do -# Factory(:build, repository: repo, state: :started, result: nil, commit: commit) -# get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('unknown') -# end -# -# it '"failing" when the last build has failed' do -# Factory(:build, repository: repo, state: :finished, result: 1, commit: commit) -# get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('failing') -# end -# -# it '"passing" when the last build has passed' do -# Factory(:build, repository: repo, state: :finished, result: 0, commit: commit) -# get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('passing') -# end -# -# it '"passing" when there is a running build but the previous one has passed' do -# Factory(:build, repository: repo, state: :finished, result: 0, commit: commit) -# Factory(:build, repository: repo, state: :started, result: nil, commit: commit) -# repo.update_attributes!(last_build_result: nil) -# get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('passing') -# end -# end -# end diff --git a/spec/integration/v1/repositories_spec.rb b/spec/integration/v1/repositories_spec.rb index 4e2c4010..22d39518 100644 --- a/spec/integration/v1/repositories_spec.rb +++ b/spec/integration/v1/repositories_spec.rb @@ -46,55 +46,55 @@ describe 'Repos' do get('/svenfuchs/does-not-exist.png').should deliver_result_image_for('unknown') end - xit '"unknown" when it only has a build that is not finished' do - repo.builds.delete_all - Factory(:running_build, repository: repo) + xit '"unknown" when it only has one build that is not finished' do + repo.update_attributes!(last_build_result: nil) get('/svenfuchs/minimal.png').should deliver_result_image_for('unknown') end xit '"failing" when the last build has failed' do - repo.last_build.update_attributes!(:result => 1) + repo.update_attributes!(last_build_result: 1) get('/svenfuchs/minimal.png').should deliver_result_image_for('failing') end xit '"passing" when the last build has passed' do - repo.last_build.update_attributes!(:result => 0) - get('/svenfuchs/minimal.png').should deliver_result_image_for('failing') - end - - # TODO what? there's not even an image for this - xit '"stable" when there is a running build but the previous one has passed' do - Factory(:running_build, repository: repo) - repo.last_build.update_attributes!(:result => 0) - get('/svenfuchs/minimal.png').should deliver_result_image_for('stable') - end - end - - describe 'GET /svenfuchs/minimal.png' do - xit '"unknown" when the repository does not exist' do - get('/svenfuchs/minimal.png').should deliver_result_image_for('unknown') - end - - xit '"unknown" when it only has a build that is not finished' do - repo.builds.delete_all - Factory(:running_build, repository: repo) - get('/svenfuchs/minimal.png').should deliver_result_image_for('unknown') - end - - xit '"failing" when the last build has failed' do - repo.last_build.update_attributes!(:result => 1) - get('/svenfuchs/minimal.png').should deliver_result_image_for('failing') - end - - xit '"passing" when the last build has passed' do - repo.last_build.update_attributes!(:result => 0) + repo.update_attributes!(last_build_result: 0) get('/svenfuchs/minimal.png').should deliver_result_image_for('passing') end xit '"passing" when there is a running build but the previous one has passed' do - repo.last_build.update_attributes!(:result => 0) - Factory(:running_build, :repository => repo) - get_png(repository, :branch => 'master').should serve_result_image('passing') + Factory(:build, repository: repo, state: :finished, result: nil, previous_result: 0) + repo.update_attributes!(last_build_result: nil) + get('/svenfuchs/minimal.png').should deliver_result_image_for('passing') + end + end + + describe 'GET /svenfuchs/minimal.png' do + let(:commit) { Factory(:commit, branch: 'dev') } + + xit '"unknown" when the repository does not exist' do + get('/svenfuchs/does-not-exist.png?branch=dev').should deliver_result_image_for('unknown') + end + + xit '"unknown" when it only has a build that is not finished' do + Factory(:build, repository: repo, state: :started, result: nil, commit: commit) + get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('unknown') + end + + xit '"failing" when the last build has failed' do + Factory(:build, repository: repo, state: :finished, result: 1, commit: commit) + get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('failing') + end + + xit '"passing" when the last build has passed' do + Factory(:build, repository: repo, state: :finished, result: 0, commit: commit) + get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('passing') + end + + xit '"passing" when there is a running build but the previous one has passed' do + Factory(:build, repository: repo, state: :finished, result: 0, commit: commit) + Factory(:build, repository: repo, state: :started, result: nil, commit: commit) + repo.update_attributes!(last_build_result: nil) + get('/svenfuchs/minimal.png?branch=dev').should deliver_result_image_for('passing') end end end