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

If max_results set to 0, return count of issues instead of issues #167

Merged
merged 1 commit into from
Jul 19, 2016
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
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