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"]