sr (owner)

Revisions

  • e9905a sr Wed Jul 01 05:01:50 -0700 2009
gist: 138743 Download_button fork
public
Public Clone URL: git://gist.github.com/138743.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
commit a92bca10e6a015d981d886c82b46be244dfbf24d
Author: Simon Rozet <simon@rozet.name>
Date: Mon Jun 29 00:52:04 2009 +0200
 
    412 when buildable.from(payload) returns nil
 
diff --git a/lib/bobette.rb b/lib/bobette.rb
index a1ce407..b9e69c3 100644
--- a/lib/bobette.rb
+++ b/lib/bobette.rb
@@ -15,9 +15,13 @@ module Bobette
     def call(env)
       payload = env["bobette.payload"]
       commits = payload["commits"].collect { |c| c["id"] }
- @buildable.from(payload).build(commits)
 
- Rack::Response.new("OK", 200).finish
+ if buildable = @buildable.from(payload)
+ buildable.build(commits)
+ [200, {"Content-Type" => "text/plain"}, ["OK"]]
+ else
+ [412, {"Content-Type" => "text/plain"}, ["Precondition Failed"]]
+ end
     end
   end
 end
diff --git a/test/bobette_test.rb b/test/bobette_test.rb
index 7dcc3a9..774f10f 100644
--- a/test/bobette_test.rb
+++ b/test/bobette_test.rb
@@ -12,6 +12,8 @@ class BobetteTest < Bobette::TestCase
     Bob.logger = Logger.new("/dev/null")
     Bob.directory = "/tmp/bobette-builds"
 
+ TestHelper::BuildableStub.no_buildable = false
+
     @repo = GitRepo.new(:my_test_project)
     @repo.create
     3.times { |i|
@@ -52,4 +54,14 @@ class BobetteTest < Bobette::TestCase
     assert_raise(NoMethodError) { assert post("/") }
     assert_raise(NoMethodError) { post("/", {}, "bobette.payload" => "</3") }
   end
+
+ def test_no_buildable
+ TestHelper::BuildableStub.no_buildable = true
+
+ payload = payload(@repo).update("branch" => "unknown")
+
+ post("/", {}, "bobette.payload" => payload) { |response|
+ assert_equal 412, response.status
+ }
+ end
 end
diff --git a/test/helper/buildable_stub.rb b/test/helper/buildable_stub.rb
index 8517239..44a3e9b 100644
--- a/test/helper/buildable_stub.rb
+++ b/test/helper/buildable_stub.rb
@@ -1,6 +1,12 @@
 module TestHelper
   class BuildableStub < Bob::Test::BuildableStub
+ class << self
+ attr_accessor :no_buildable
+ end
+
     def self.from(payload)
+ return nil if no_buildable
+
       kind = payload["kind"]
       uri = payload["uri"]
       branch = payload["branch"]