From 2436a555a060f88e89778644ebd329379e9a049d Mon Sep 17 00:00:00 2001 From: Simon Guerrier Date: Mon, 18 Jul 2016 17:59:30 +0200 Subject: [PATCH] If max_results set to 0, return count of issues instead of issues --- lib/jira/resource/issue.rb | 3 +++ spec/jira/resource/issue_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/jira/resource/issue.rb b/lib/jira/resource/issue.rb index f8967254..a0c2f8d1 100644 --- a/lib/jira/resource/issue.rb +++ b/lib/jira/resource/issue.rb @@ -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 diff --git a/spec/jira/resource/issue_spec.rb b/spec/jira/resource/issue_spec.rb index 3f096aaf..b41e1a4a 100644 --- a/spec/jira/resource/issue_spec.rb +++ b/spec/jira/resource/issue_spec.rb @@ -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()