Skip to content

Commit

Permalink
Merge pull request #163 from stjohnjohnson/CrumbyTree
Browse files Browse the repository at this point in the history
Passing tree= to View.list, use_crumbs?, use_security? to improve performance on large systems
  • Loading branch information
arangamani committed Jan 3, 2015
2 parents 6519547 + 0ec1774 commit 9c83cbd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/jenkins_api_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def init_update_center
# @return [Boolean] whether Jenkins uses crumbs or not
#
def use_crumbs?
response = api_get_request("")
response = api_get_request("", "tree=useCrumbs")
response["useCrumbs"]
end

Expand All @@ -498,7 +498,7 @@ def use_crumbs?
# @return [Boolean] whether Jenkins uses security or not
#
def use_security?
response = api_get_request("")
response = api_get_request("", "tree=useSecurity")
response["useSecurity"]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jenkins_api_client/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def delete_all!
def list(filter = "", ignorecase = true)
@logger.info "Obtaining views based on filter '#{filter}'"
view_names = []
response_json = @client.api_get_request("")
response_json = @client.api_get_request("", "tree=views[name]")
response_json["views"].each { |view|
if ignorecase
view_names << view["name"] if view["name"] =~ /#{filter}/i
Expand Down
40 changes: 40 additions & 0 deletions spec/unit_tests/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,46 @@
@client.compare_versions("1.0.10", "1.0.2").should eql(1)
end
end

describe "#use_crumbs?" do
it "returns true if the server has useCrumbs on" do
expect(@client).to receive(:api_get_request).with("", "tree=useCrumbs") {
{
"useCrumbs" => true
}
}
@client.use_crumbs?.should == true
end

it "returns false if the server has useCrumbs off" do
expect(@client).to receive(:api_get_request).with("", "tree=useCrumbs") {
{
"useCrumbs" => false
}
}
@client.use_crumbs?.should == false
end
end

describe "#use_security?" do
it "returns true if the server has useSecurity on" do
expect(@client).to receive(:api_get_request).with("", "tree=useSecurity") {
{
"useSecurity" => true
}
}
@client.use_security?.should == true
end

it "returns false if the server has useSecurity off" do
expect(@client).to receive(:api_get_request).with("", "tree=useSecurity") {
{
"useSecurity" => false
}
}
@client.use_security?.should == false
end
end
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/unit_tests/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

describe "InstanceMethods" do
describe "#initialize" do
it "initializes by receiving an instane of client object" do
it "initializes by receiving an instance of client object" do
mock_logger = Logger.new "/dev/null"
@client.should_receive(:logger).and_return(mock_logger)
expect(
Expand All @@ -48,21 +48,21 @@

describe "#list" do
it "lists all views" do
@client.should_receive(:api_get_request).with("").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
response = @view.list
response.class.should == Array
response.size.should == 2
end

it "lists views matching specific filter" do
@client.should_receive(:api_get_request).with("").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
response = @view.list("test_view2")
response.class.should == Array
response.size.should == 1
end

it "lists views matching specific filter and matches case" do
@client.should_receive(:api_get_request).with("").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
response = @view.list("TEST_VIEW", false)
response.class.should == Array
response.size.should == 0
Expand All @@ -71,27 +71,27 @@

describe "#exists?" do
it "returns true a view that exists" do
@client.should_receive(:api_get_request).with("").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
@view.exists?("test_view2").should == true
end

it "returns false for non-existent view" do
@client.should_receive(:api_get_request).with("").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
@view.exists?("i_am_not_there").should == false
end
end

describe "#list_jobs" do
it "lists all jobs in the given view" do
@client.should_receive(:api_get_request).with("").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("/view/test_view").and_return(@sample_view_json)
response = @view.list_jobs("test_view")
response.class.should == Array
response.size.should == 2
end

it "raises an error if called on a non-existent view" do
@client.should_receive(:api_get_request).with("").and_return(@sample_views_json)
@client.should_receive(:api_get_request).with("", "tree=views[name]").and_return(@sample_views_json)
expect(
lambda { @view.list_jobs("i_am_not_there") }
).to raise_error
Expand Down

0 comments on commit 9c83cbd

Please sign in to comment.