Skip to content

Commit

Permalink
Merge pull request #1 from luchenghan/is_offline_bug
Browse files Browse the repository at this point in the history
Restoring node property methods to its original logic, but handles both bool and string case
  • Loading branch information
bsnape committed Mar 31, 2015
2 parents 1aed610 + c233856 commit e0f99c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/jenkins_api_client/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def index(node_name)
define_method("is_#{meth_suffix}?") do |node_name|
@logger.info "Obtaining '#{meth_suffix}' property of '#{node_name}'"
response_json = @client.api_get_request("/computer")
response_json["computer"][index(node_name)]["#{meth_suffix}"]
resp = response_json["computer"][index(node_name)]["#{meth_suffix}"].to_s
resp =~ /False/i ? false : true
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/unit_tests/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
"offline" => false,
]
}
@offline_slave_in_string = {
"computer" => [
"displayName" => "slave",
"offline" => "true",
]
}
@online_slave_in_string = {
"computer" => [
"displayName" => "slave",
"offline" => "false",
]
}
computer_sample_xml_filename = '../fixtures/files/computer_sample.xml'
@sample_computer_xml = File.read(
File.expand_path(computer_sample_xml_filename , __FILE__)
Expand Down Expand Up @@ -190,6 +202,24 @@
)
@node.method("is_offline?").call("slave").should be_false
end

it "returns false if the node is online and have a string value on its attr" do
@client.should_receive(
:api_get_request
).twice.and_return(
@offline_slave_in_string
)
@node.method("is_offline?").call("slave").should be_true
end

it "returns false if the node is online and have a string value on its attr" do
@client.should_receive(
:api_get_request
).twice.and_return(
@online_slave_in_string
)
@node.method("is_offline?").call("slave").should be_false
end
end

describe "NodeAttributes" do
Expand Down

0 comments on commit e0f99c2

Please sign in to comment.