jira-ruby 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8a9d8341a978cefa7838d24cb1ab04ed8b7b827
4
- data.tar.gz: 751b670eee108023f9c9f26c3a047990980d8460
3
+ metadata.gz: 73c4e19bc5c82d26d320a378266855abc8244997
4
+ data.tar.gz: 2fd1c376a41076726c10f28afd9e4c380b38b91f
5
5
  SHA512:
6
- metadata.gz: 2ad45e5cdc3d906be50dda804c90ce53a3bd82f9388357ad011186456bf51e2b98ce521709cbf95480f515e9e1dd0e37a54c908339ae9dad6db99713491410de
7
- data.tar.gz: 5e4bf3c7720a0a12e89a0de06a289a9da2bad66d54f93d4b889fb19c189d9e8481f829c716b5f2aa99ace0823e5605529072982949d59dcd1828bff0c99dbada
6
+ metadata.gz: 4b150a3fc57ba754238ae9851d2dd1c0b8f190203cd3e195d88c4778381c261f8f8a5196200f8ec13382eca8821fa2e24cf0008c37bf9582d91efda165d0e162
7
+ data.tar.gz: af41788a14386555867711bd12b40622f2b473f02362b6fec5268cd7a3a99a4b82de73cb873bc91954296140e001900fd5f561cb307baf6eb45926b25c1bb911
@@ -1,5 +1,6 @@
1
1
  require 'active_support/core_ext/string'
2
2
  require 'active_support/inflector'
3
+ require 'set'
3
4
 
4
5
  module JIRA
5
6
 
@@ -50,6 +51,8 @@ module JIRA
50
51
  # new_comment = issue.comments.build
51
52
  #
52
53
  class Base
54
+ QUERY_PARAMS_FOR_SINGLE_FETCH = Set.new [:expand, :fields]
55
+ QUERY_PARAMS_FOR_SEARCH = Set.new [:expand, :fields, :startAt, :maxResults]
53
56
 
54
57
  # A reference to the JIRA::Client used to initialize this resource.
55
58
  attr_reader :client
@@ -104,7 +107,7 @@ module JIRA
104
107
  def self.find(client, key, options = {})
105
108
  instance = self.new(client, options)
106
109
  instance.attrs[key_attribute.to_s] = key
107
- instance.fetch
110
+ instance.fetch(false, query_params_for_single_fetch(options))
108
111
  instance
109
112
  end
110
113
 
@@ -331,9 +334,9 @@ module JIRA
331
334
  # Fetches the attributes for the specified resource from JIRA unless
332
335
  # the resource is already expanded and the optional force reload flag
333
336
  # is not set
334
- def fetch(reload = false)
337
+ def fetch(reload = false, query_params = {})
335
338
  return if expanded? && !reload
336
- response = client.get(url)
339
+ response = client.get(url_with_query_params(url, query_params))
337
340
  set_attrs_from_response(response)
338
341
  @expanded = true
339
342
  end
@@ -465,5 +468,30 @@ module JIRA
465
468
  end
466
469
  end
467
470
 
471
+ def url_with_query_params(url, query_params)
472
+ if not query_params.empty?
473
+ "#{url}?#{hash_to_query_string query_params}"
474
+ else
475
+ url
476
+ end
477
+ end
478
+
479
+ def hash_to_query_string(query_params)
480
+ query_params.map do |k,v|
481
+ CGI.escape(k.to_s) + "=" + CGI.escape(v.to_s)
482
+ end.join('&')
483
+ end
484
+
485
+ def self.query_params_for_single_fetch(options)
486
+ Hash[options.select do |k,v|
487
+ QUERY_PARAMS_FOR_SINGLE_FETCH.include? k
488
+ end]
489
+ end
490
+
491
+ def self.query_params_for_search(options)
492
+ Hash[options.select do |k,v|
493
+ QUERY_PARAMS_FOR_SEARCH.include? k
494
+ end]
495
+ end
468
496
  end
469
497
  end
@@ -16,15 +16,16 @@ module JIRA
16
16
  end
17
17
 
18
18
  # Returns all the issues for this project
19
- def issues
20
- response = client.get(client.options[:rest_base_path] + "/search?jql=project%3D'#{key}'")
19
+ def issues(options={})
20
+ search_url = client.options[:rest_base_path] + '/search'
21
+ query_params = {:jql => "project=\"#{key}\""}
22
+ query_params.update Base.query_params_for_search(options)
23
+ response = client.get(url_with_query_params(search_url, query_params))
21
24
  json = self.class.parse_json(response.body)
22
25
  json['issues'].map do |issue|
23
26
  client.Issue.build(issue)
24
27
  end
25
28
  end
26
-
27
29
  end
28
-
29
30
  end
30
31
  end
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -26,7 +26,7 @@ describe JIRA::Resource::Project do
26
26
  describe "issues" do
27
27
 
28
28
  it "returns all the issues" do
29
- stub_request(:get, site_url + "/jira/rest/api/2/search?jql=project='SAMPLEPROJECT'").
29
+ stub_request(:get, site_url + "/jira/rest/api/2/search?jql=project=\"SAMPLEPROJECT\"").
30
30
  to_return(:status => 200, :body => get_mock_response('project/SAMPLEPROJECT.issues.json'))
31
31
  subject = client.Project.build('key' => key)
32
32
  issues = subject.issues
@@ -67,6 +67,21 @@ describe JIRA::Base do
67
67
  deadbeef.expanded?.should be_true
68
68
  end
69
69
 
70
+ it "finds a deadbeef containing changelog by id" do
71
+ response = double()
72
+ response.stub(:body).and_return('{"self":"http://deadbeef/","id":"98765","changelog":{"histories":[]}}')
73
+ client.should_receive(:get).with('/jira/rest/api/2/deadbeef/98765?expand=changelog').and_return(response)
74
+
75
+ JIRA::Resource::Deadbeef.should_receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
76
+
77
+ deadbeef = JIRA::Resource::Deadbeef.find(client, '98765', {expand:'changelog'})
78
+ deadbeef.client.should == client
79
+ deadbeef.attrs['self'].should == 'http://deadbeef/'
80
+ deadbeef.attrs['id'].should == '98765'
81
+ deadbeef.expanded?.should be_true
82
+ deadbeef.attrs['changelog']['histories'].should == []
83
+ end
84
+
70
85
  it "builds a deadbeef" do
71
86
  deadbeef = JIRA::Resource::Deadbeef.build(client, 'id' => "98765" )
72
87
  deadbeef.expanded?.should be_false
@@ -176,6 +191,21 @@ describe JIRA::Base do
176
191
  end
177
192
  end
178
193
 
194
+ context "with expand parameter 'changelog'" do
195
+ it "fetchs changelogs '" do
196
+ response = double()
197
+ response.stub(:body).and_return('{"self":"http://deadbeef/","id":"98765","changelog":{"histories":[]}}')
198
+ client.should_receive(:get).with('/jira/rest/api/2/deadbeef/98765?expand=changelog').and_return(response)
199
+
200
+ JIRA::Resource::Deadbeef.should_receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
201
+
202
+ subject.fetch(false, {expand:'changelog'})
203
+
204
+ subject.self.should == "http://deadbeef/"
205
+ subject.id.should == "98765"
206
+ subject.changelog['histories'].should == []
207
+ end
208
+ end
179
209
  end
180
210
 
181
211
  describe "save" do
@@ -2,14 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Project do
4
4
 
5
- let(:client) { double() }
5
+ let(:client) { double("client", :options => {
6
+ :rest_base_path => '/jira/rest/api/2'
7
+ })
8
+ }
6
9
 
7
10
  describe "relationships" do
8
11
  subject {
9
12
  JIRA::Resource::Project.new(client, :attrs => {
10
- 'lead' => {'foo' => 'bar'},
11
- 'issueTypes' => [{'foo' =>'bar'},{'baz' => 'flum'}],
12
- 'versions' => [{'foo' =>'bar'},{'baz' => 'flum'}]
13
+ 'lead' => {'foo' => 'bar'},
14
+ 'issueTypes' => [{'foo' =>'bar'},{'baz' => 'flum'}],
15
+ 'versions' => [{'foo' =>'bar'},{'baz' => 'flum'}],
13
16
  })
14
17
  }
15
18
 
@@ -25,4 +28,43 @@ describe JIRA::Resource::Project do
25
28
  end
26
29
  end
27
30
 
31
+ describe "issues" do
32
+ subject {
33
+ JIRA::Resource::Project.new(client, :attrs => {
34
+ 'key' => 'test'
35
+ })
36
+ }
37
+
38
+ it "returns issues" do
39
+ response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"}}]}'
40
+ response = double("response",
41
+ :body => response_body)
42
+ issue_factory = double("issue factory")
43
+
44
+ client.should_receive(:get)
45
+ .with('/jira/rest/api/2/search?jql=project%3D%22test%22')
46
+ .and_return(response)
47
+ client.should_receive(:Issue).and_return(issue_factory)
48
+ issue_factory.should_receive(:build)
49
+ .with(JSON.parse(response_body)["issues"][0])
50
+ subject.issues
51
+ end
52
+
53
+ context "with changelog" do
54
+ it "returns issues" do
55
+ response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"},"changelog":{}}]}'
56
+ response = double("response",
57
+ :body => response_body)
58
+ issue_factory = double("issue factory")
59
+
60
+ client.should_receive(:get)
61
+ .with('/jira/rest/api/2/search?jql=project%3D%22test%22&expand=changelog&startAt=1&maxResults=100')
62
+ .and_return(response)
63
+ client.should_receive(:Issue).and_return(issue_factory)
64
+ issue_factory.should_receive(:build)
65
+ .with(JSON.parse(response_body)["issues"][0])
66
+ subject.issues({expand:'changelog', startAt:1, maxResults:100})
67
+ end
68
+ end
69
+ end
28
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUMO Heavy Industries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth