From 7b407fdcfc4eea789d674a4c24fe1d9ecc60adbe Mon Sep 17 00:00:00 2001 From: Joao Lucas Santana Date: Thu, 4 Dec 2014 01:36:00 -0200 Subject: [PATCH] Fix job#build method when true/false values are passed as timeout parameter --- lib/jenkins_api_client/job.rb | 4 ++-- spec/unit_tests/job_spec.rb | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/jenkins_api_client/job.rb b/lib/jenkins_api_client/job.rb index 8b78329f..0ea95f28 100644 --- a/lib/jenkins_api_client/job.rb +++ b/lib/jenkins_api_client/job.rb @@ -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 diff --git a/spec/unit_tests/job_spec.rb b/spec/unit_tests/job_spec.rb index 51dfba30..49d88ad1 100644 --- a/spec/unit_tests/job_spec.rb +++ b/spec/unit_tests/job_spec.rb @@ -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)