Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix job#build method when true/false values are passed as timeout parameter #161

Merged
merged 1 commit into from
Jan 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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