From 7eceeb284205fba5f45327489a5d47f895c0c599 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 2 Oct 2012 19:10:29 +0200 Subject: [PATCH] moar work on acceptance tests --- lib/travis/api/app/endpoint/artifacts.rb | 2 +- lib/travis/api/app/endpoint/branches.rb | 2 +- lib/travis/api/app/endpoint/hooks.rb | 4 +- lib/travis/api/app/endpoint/jobs.rb | 4 +- lib/travis/api/app/endpoint/repositories.rb | 6 +- lib/travis/api/app/endpoint/result_image.rb | 13 ++++ lib/travis/api/app/endpoint/stats.rb | 4 +- lib/travis/api/app/endpoint/workers.rb | 2 +- lib/travis/api/app/helpers/result_image.rb | 27 +++++++++ lib/travis/api/app/responder.rb | 2 +- public/images/result/failing.png | Bin 0 -> 1586 bytes public/images/result/passing.png | Bin 0 -> 1791 bytes public/images/result/unknown.png | Bin 0 -> 1678 bytes spec/integration/result_image_spec.rb | 62 ++++++++++++++++++++ spec/spec_helper.rb | 21 +++++++ 15 files changed, 134 insertions(+), 15 deletions(-) create mode 100644 lib/travis/api/app/endpoint/result_image.rb create mode 100644 lib/travis/api/app/helpers/result_image.rb create mode 100644 public/images/result/failing.png create mode 100644 public/images/result/passing.png create mode 100644 public/images/result/unknown.png create mode 100644 spec/integration/result_image_spec.rb diff --git a/lib/travis/api/app/endpoint/artifacts.rb b/lib/travis/api/app/endpoint/artifacts.rb index fa3d0743..72cd4a25 100644 --- a/lib/travis/api/app/endpoint/artifacts.rb +++ b/lib/travis/api/app/endpoint/artifacts.rb @@ -6,7 +6,7 @@ class Travis::Api::App # artifacts class Artifacts < Endpoint # Fetches an artifact by it's *id*. - get('/:id') do |id| + get '/:id' do |id| body one(params).run end end diff --git a/lib/travis/api/app/endpoint/branches.rb b/lib/travis/api/app/endpoint/branches.rb index 2f076482..bf898790 100644 --- a/lib/travis/api/app/endpoint/branches.rb +++ b/lib/travis/api/app/endpoint/branches.rb @@ -3,7 +3,7 @@ require 'travis/api/app' class Travis::Api::App class Endpoint class Branches < Endpoint - get('/') do + get '/' do body all(params).run, type: :branches end end diff --git a/lib/travis/api/app/endpoint/hooks.rb b/lib/travis/api/app/endpoint/hooks.rb index b3100bf7..02154e56 100644 --- a/lib/travis/api/app/endpoint/hooks.rb +++ b/lib/travis/api/app/endpoint/hooks.rb @@ -3,11 +3,11 @@ require 'travis/api/app' class Travis::Api::App class Endpoint class Hooks < Endpoint - get('/', scope: :private) do + get '/', scope: :private do body all(params).run, type: :hooks end - put('/:id?', scope: :private) do + put '/:id?', scope: :private do update(id: params[:id] || params[:hook][:id], active: params[:hook][:active]).run 204 end diff --git a/lib/travis/api/app/endpoint/jobs.rb b/lib/travis/api/app/endpoint/jobs.rb index bd2463ab..893fefb4 100644 --- a/lib/travis/api/app/endpoint/jobs.rb +++ b/lib/travis/api/app/endpoint/jobs.rb @@ -3,11 +3,11 @@ require 'travis/api/app' class Travis::Api::App class Endpoint class Jobs < Endpoint - get('/') do + get '/' do body all(params).run end - get('/:id') do + get '/:id' do body one(params).run end end diff --git a/lib/travis/api/app/endpoint/repositories.rb b/lib/travis/api/app/endpoint/repositories.rb index a26161a9..ade57472 100644 --- a/lib/travis/api/app/endpoint/repositories.rb +++ b/lib/travis/api/app/endpoint/repositories.rb @@ -7,13 +7,9 @@ class Travis::Api::App body all(params).run end - get('/:id') do + get '/:id' do body one(params).run end - - # TODO make sure status images and cc.xml work - # rescue ActiveRecord::RecordNotFound - # raise unless params[:format] == 'png' end end end diff --git a/lib/travis/api/app/endpoint/result_image.rb b/lib/travis/api/app/endpoint/result_image.rb new file mode 100644 index 00000000..ec45c890 --- /dev/null +++ b/lib/travis/api/app/endpoint/result_image.rb @@ -0,0 +1,13 @@ +require 'travis/api/app' + +class Travis::Api::App + class Endpoint + class ResultImage < Endpoint + set(:prefix) { '/' } + + get '/:owner_name/:name.png' do + result_image service(:repositories, :one, params).run(:raise => false) + end + end + end +end diff --git a/lib/travis/api/app/endpoint/stats.rb b/lib/travis/api/app/endpoint/stats.rb index ac46bc7e..7bd2a2ee 100644 --- a/lib/travis/api/app/endpoint/stats.rb +++ b/lib/travis/api/app/endpoint/stats.rb @@ -3,11 +3,11 @@ require 'travis/api/app' class Travis::Api::App class Endpoint class Stats < Endpoint - get('/repos') do + get '/repos' do { :stats => service(:daily_repos) } end - get('/tests') do + get '/tests' do { :stats => service(:daily_tests) } end end diff --git a/lib/travis/api/app/endpoint/workers.rb b/lib/travis/api/app/endpoint/workers.rb index ea4c7729..93d8796a 100644 --- a/lib/travis/api/app/endpoint/workers.rb +++ b/lib/travis/api/app/endpoint/workers.rb @@ -3,7 +3,7 @@ require 'travis/api/app' class Travis::Api::App class Endpoint class Workers < Endpoint - get('/') do + get '/' do body all(params).run end end diff --git a/lib/travis/api/app/helpers/result_image.rb b/lib/travis/api/app/helpers/result_image.rb new file mode 100644 index 00000000..3ddbef18 --- /dev/null +++ b/lib/travis/api/app/helpers/result_image.rb @@ -0,0 +1,27 @@ +require 'travis/api/app' +require 'cgi' + +module Travis::Api::App::Helpers + module ResultImage + RESULT_NAMES = { nil => 'unknown', 0 => 'passing', 1 => 'failing' } + + def result_image(resource) + headers['Expires'] = CGI.rfc1123_date(Time.now.utc) + filename = filename(resource) + env['travis.sending-file'] = filename + send_file filename, type: :png, disposition: :inline + end + + protected + + def filename(resource) + root = File.expand_path("#{settings.root}/../../../../../") # TODO wat. + "#{root}/public/images/result/#{result(resource)}.png" + end + + def result(resource) + RESULT_NAMES[resource.try(:last_build_result_on, branch: params[:branch])] + end + end +end + diff --git a/lib/travis/api/app/responder.rb b/lib/travis/api/app/responder.rb index 36e3a5c4..8b8f0785 100644 --- a/lib/travis/api/app/responder.rb +++ b/lib/travis/api/app/responder.rb @@ -23,7 +23,7 @@ class Travis::Api::App enable :raise_errors # disable :dump_errors register :subclass_tracker - helpers :json_renderer + helpers :json_renderer, :result_image end configure :development do diff --git a/public/images/result/failing.png b/public/images/result/failing.png new file mode 100644 index 0000000000000000000000000000000000000000..46eda84ee223c2e811e6300c6acff48bffbb7756 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s9KV{URbZ$Em5Q74~k@Z*Fc5$70FN zh~&^%@5z%W`Q}@U5}GFHjI>ZfqGCcPgIb$!nWPU>`HnGZC@bpC~7?mur;o$ih>N$k5KrX<{d3B!jxQxm;_hfv(XB@4>WMFj2a!dTc=XtEE+Q5qQXo(bmuH%W$VU-k=+>2>ovd;t zaaun`(_=)ZXov3=LgecwP6&9RL6T07*qoM6N<$g7^&t@c;k- literal 0 HcmV?d00001 diff --git a/public/images/result/passing.png b/public/images/result/passing.png new file mode 100644 index 0000000000000000000000000000000000000000..1d1bbe396fad82108a229a8c172a5ee4a0ea4a13 GIT binary patch literal 1791 zcmV^fz+s}2?H+u)1(-iv`sW|>cS7StrVKnw6TqWs4;3>1~C!& zp$;}FMWbXaNQ#vi2N$+s=Dpr?-+Qw$MbpF>Z#>@ZEcbo$-E$8rQ54fRZQA6Di;IK7 zV1P!Wfl8&q>)7Js<8jJ-3X|tde&uKJ2|hgbKSq0Adzz}Wv{WQeM@L67I5-Hu-wy`- zYYB2_1 zeXPCb`N%IQ7}tMFYU*=+#1fVGa%6>R1uo`Xd}003z$iRE4|;}rpeD{L5)cF~;cKzv z*6rJQ zzn_n5>*|o0kbt>!=i&!8Uc`W*@ulWw6y)c_(bUBCj4YSi7<*G0F!y_UFfcF>;d7nU z%5ABgIeQkFnVCppK-0R1-J(@1SMoi&RhKSZ!s5KVAY9S0$-aW!Hi}95v`0RIjiW8S zDYleyRHc6ov%$>g#m*AA2Jhj*`{#mdJMVr0hsS{nmh&*_OmGdkP<-PfZb$Ztj`N8V zRZFYT_)lYm&&rN1Xkcq(Z;8)gdTq?l6l7eyT z9xJ^d3UJ=M34_syJ9qDf2qnvjlP9tMnV4mbHiO&5^}J!bth``Yawh8pmxdO5NNVb@63L9wf)>aU6YPR z7xOV&g(i2Ctf!KM*{NA6!K(?Wq7X4FH4PKl$IhQO58VuKx4RFCEQOF>LSlmaHDXi` zSmx*O`CD&hh3!ewe7PBwTeo13-HyE6Mf|E$4BDfV(b3Vtn0b&_H?&6%4D3e5irw$^ z;+wsDxxc@xTf(5@VgrmC&COu0Lf(r{8 z7eZa5fwQ*_)+8(Ty7u!q>Df}tVbYpHzoa@yQa-=ee-G9SiM@r%g$nZ|VgIxeP7+sW zJTN$b-Me>Vh<$MVkM-z%@Bo7YgPb|{?|1VtloC(wFFGzFi{;sHo$xYn+tzK!Vig0m zD=k;h$F4iI3R?wkv^lZ)lg-?&&+X=KfVtUT`g|NyGr>9NQ4aj=z2T?6A$md6-ABAdU63Ty+=O}+t z&h(A=Sj7;4My=tBTCJArDgA^A6EHF|fowViFA!*n`f+_$>fR1$2&f#f_0h|3w~J$`*J(X@n)2^m&qWD z#AGq}UeI5ABx4He3Hq^XdVR1bAIdzKN5hyLy+@56tnr$Gr;XULmAx^sf=m`e$(-;` zN92o=9wXaF>&(E|S7?Sjo+Pt)k|cG%GbXQKO#UnY?}!)0r%QNM5q$a<<>iTVNMZv4 ztgzyBY*c=p$UP3xEPvcnNUVD!40D-KP=(TJ3^@59ShGawiiol$!2brXFzCjJ)8)K9 zOzDB$zP4NKYRlW%f{$H6KV9kIBl!9?9ZMx*CmRez0p>=`N+s5OyuGpW=oK0Er*hhv hDnhp-Uj45C0{~~rX3CZ%wSxcv002ovPDHLkV1m%6b(R1C literal 0 HcmV?d00001 diff --git a/public/images/result/unknown.png b/public/images/result/unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..cb7abbda12ba406a470bca8a210781fcfea7c100 GIT binary patch literal 1678 zcmV;9266d`P)VuaiBAAG_^%^yT z)o401+!s#MmXB1Ucb82d8UPeVlVcD`} zh=_=Qq9|C3B|bhLxw*MmwQAL(JYOIXfY0ZXx@prUi?Vz7Zk3HaIXMZh*NcgX36MjU zr14WyQt-*<&9K>Qi}HL1g8?R!Nm_Xxc=ZadfdLE+52K`{1huub03-hm)mBh|y1Keh zJJ;OX_Nc6?dgK0CR_j~$n5!~y=3A4KlJN1yjSE^kpX&GfF+M(yv9U1%`WOt1alQH} zEVzb`%~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