Skip to content

Commit

Permalink
Merge pull request #161 from jlucasps/master
Browse files Browse the repository at this point in the history
Fix job#build method when true/false values are passed as timeout parameter
  • Loading branch information
arangamani committed Jan 30, 2015
2 parents 128ffbe + 7b407fd commit fb6a5b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/jenkins_api_client/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,9 @@ def get_current_build_number(job_name)
# @return [String] HTTP response code (per prev. behavior) (NO TIMEOUT SPECIFIED)
#
def build(job_name, params={}, opts = {})
if opts.nil? || opts.class.is_a?(FalseClass)
if opts.nil? || opts.is_a?(FalseClass)
opts = {}
elsif opts.class.is_a?(TrueClass)
elsif opts.is_a?(TrueClass)
opts = { 'build_start_timeout' => @client_timeout }
end

Expand Down
30 changes: 23 additions & 7 deletions spec/unit_tests/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,31 @@
### OLD NON-QUEUE RESPONSE JENKINS ###
# Next tests confirm it deals with different jenkins versions and waits
# for build to start (or not)
it "accepts the job name and builds the job (w/timeout)" do
@client.should_receive(:api_get_request).with(
"/job/test_job").and_return({})
context "accepts the job name and builds the job (w/timeout)" do
before do
@client.should_receive(:api_get_request).with(
"/job/test_job").and_return({})
@client.should_receive(:api_post_request).with(
"/job/test_job/build", {}, true).and_return(FakeResponse.new(302))
@client.should_receive(:api_get_request).with(
"/job/test_job/1/").and_return({})
@client.should_receive(:get_jenkins_version).and_return("1.1")
end

it "passes a number of seconds for timeout in opts={} parameter" do
@job.build("test_job", {}, {'build_start_timeout' => 10}).should == 1
end

it "passes a true value for timeout in opts={} parameter" do
@job.instance_variable_set :@client_timeout, 10
@job.build("test_job", {}, true).should == 1
end
end

it "accepts the job name and builds the job (with a false timeout value)" do
@client.should_receive(:api_post_request).with(
"/job/test_job/build", {}, true).and_return(FakeResponse.new(302))
@client.should_receive(:api_get_request).with(
"/job/test_job/1/").and_return({})
@client.should_receive(:get_jenkins_version).and_return("1.1")
@job.build("test_job", {}, {'build_start_timeout' => 10}).should == 1
@job.build("test_job", {}, false).should == "302"
end

# wait for build to start (or not) (initial response will fail)
Expand Down

0 comments on commit fb6a5b1

Please sign in to comment.