Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

412 when result of buildable#call doesn't respond to :build

  • Loading branch information...
commit 9f0581d0359defdf00e27c908b833432bd7b2b61 1 parent 0a3b315
@sr authored
View
13 lib/bobette.rb
@@ -13,11 +13,16 @@ def initialize(buildable)
end
def call(env)
- payload = env["bobette.payload"]
- commits = payload["commits"].collect { |c| c["id"] }
- @buildable.call(payload).build(commits)
+ payload = env["bobette.payload"]
+ commits = payload["commits"].collect { |c| c["id"] }
+ buildable = @buildable.call(payload)
- Rack::Response.new("OK", 200).finish
+ if buildable.respond_to?(:build)
+ buildable.build(commits)
+ [200, {"Content-Type" => "text/plain"}, ["OK"]]
+ else
+ [412, {"Content-Type" => "text/plain"}, ["Precondition Failed"]]
+ end
end
end
end
View
12 test/bobette_test.rb
@@ -12,6 +12,8 @@ def setup
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 @@ def test_invalid_payload
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
View
6 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.call(payload)
+ return nil if no_buildable
+
kind = payload["kind"]
uri = payload["uri"]
branch = payload["branch"]
Please sign in to comment.
Something went wrong with that request. Please try again.