Skip to content

Commit

Permalink
Merge pull request #167 from Simwar/master
Browse files Browse the repository at this point in the history
If max_results set to 0, return count of issues instead of issues
  • Loading branch information
Robert Brodie authored Jul 19, 2016
2 parents 04ffd3f + 2436a55 commit 47f5ab8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/jira/resource/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def self.jql(client, jql, options = {fields: nil, start_at: nil, max_results: ni

response = client.get(url)
json = parse_json(response.body)
if options[:max_results] and options[:max_results] == 0
return json['total']
end
json['issues'].map do |issue|
client.Issue.build(issue)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/jira/resource/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
expect(JIRA::Resource::Issue.jql(client,'foo bar', start_at: 1, max_results: 3)).to eq([''])
end

it "should search an issue with a jql query string and maxResults equals zero and should return the count of tickets" do
response = double()
issue = double()

allow(response).to receive(:body).and_return('{"total": 1, "issues": []}')
expect(client).to receive(:get)
.with('/jira/rest/api/2/search?jql=foo+bar&maxResults=0')
.and_return(response)

expect(JIRA::Resource::Issue.jql(client,'foo bar', max_results: 0)).to eq(1)
end

it "should search an issue with a jql query string and string expand" do
response = double()
issue = double()
Expand Down

0 comments on commit 47f5ab8

Please sign in to comment.