jira-ruby 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ require 'oauth'
2
+ require 'json'
3
+ require 'net/https'
4
+
5
+ module JIRA
6
+ class RequestClient
7
+
8
+ # Returns the response if the request was successful (HTTP::2xx) and
9
+ # raises a JIRA::HTTPError if it was not successful, with the response
10
+ # attached.
11
+
12
+ def request(*args)
13
+ response = make_request(*args)
14
+ raise HTTPError.new(response) unless response.kind_of?(Net::HTTPSuccess)
15
+ response
16
+ end
17
+ end
18
+ end
data/lib/jira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,25 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Attachment do
4
4
 
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
5
8
 
6
- let(:client) do
7
- client = JIRA::Client.new('foo', 'bar')
8
- client.set_access_token('abc', '123')
9
- client
10
- end
9
+ let(:key) { "10000" }
11
10
 
12
- let(:key) { "10000" }
11
+ let(:expected_attributes) do
12
+ {
13
+ 'self' => "http://localhost:2990/jira/rest/api/2/attachment/10000",
14
+ 'size' => 15360,
15
+ 'filename' => "ballmer.png"
16
+ }
17
+ end
13
18
 
14
- let(:expected_attributes) do
15
- {
16
- 'self' => "http://localhost:2990/jira/rest/api/2/attachment/10000",
17
- 'size' => 15360,
18
- 'filename' => "ballmer.png"
19
- }
19
+ it_should_behave_like "a resource"
20
+ it_should_behave_like "a resource with a singular GET endpoint"
21
+ it_should_behave_like "a resource with a DELETE endpoint"
20
22
  end
21
-
22
- it_should_behave_like "a resource"
23
- it_should_behave_like "a resource with a singular GET endpoint"
24
- it_should_behave_like "a resource with a DELETE endpoint"
25
-
26
23
  end
@@ -2,54 +2,53 @@ require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Comment do
4
4
 
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
5
8
 
6
- let(:client) do
7
- client = JIRA::Client.new('foo', 'bar')
8
- client.set_access_token('abc', '123')
9
- client
10
- end
9
+ let(:key) { "10000" }
11
10
 
12
- let(:key) { "10000" }
11
+ let(:target) { JIRA::Resource::Comment.new(client, :attrs => {'id' => '99999'}, :issue_id => '54321') }
13
12
 
14
- let(:target) { JIRA::Resource::Comment.new(client, :attrs => {'id' => '99999'}, :issue_id => '54321') }
13
+ let(:expected_collection_length) { 2 }
15
14
 
16
- let(:expected_collection_length) { 2 }
15
+ let(:belongs_to) {
16
+ JIRA::Resource::Issue.new(client, :attrs => {
17
+ 'id' => '10002', 'fields' => {
18
+ 'comment' => {'comments' => []}
19
+ }
20
+ })
21
+ }
17
22
 
18
- let(:belongs_to) {
19
- JIRA::Resource::Issue.new(client, :attrs => {
20
- 'id' => '10002', 'fields' => {
21
- 'comment' => {'comments' => []}
23
+ let(:expected_attributes) do
24
+ {
25
+ 'self' => "http://localhost:2990/jira/rest/api/2/issue/10002/comment/10000",
26
+ 'id' => key,
27
+ 'body' => "This is a comment. Creative."
22
28
  }
23
- })
24
- }
25
-
26
- let(:expected_attributes) do
27
- {
28
- 'self' => "http://localhost:2990/jira/rest/api/2/issue/10002/comment/10000",
29
- 'id' => key,
30
- 'body' => "This is a comment. Creative."
29
+ end
30
+
31
+ let(:attributes_for_post) {
32
+ {"body" => "new comment"}
33
+ }
34
+ let(:expected_attributes_from_post) {
35
+ { "id" => "10001", "body" => "new comment"}
31
36
  }
32
- end
33
37
 
34
- let(:attributes_for_post) {
35
- {"body" => "new comment"}
36
- }
37
- let(:expected_attributes_from_post) {
38
- { "id" => "10001", "body" => "new comment"}
39
- }
40
-
41
- let(:attributes_for_put) {
42
- {"body" => "new body"}
43
- }
44
- let(:expected_attributes_from_put) {
45
- { "id" => "10000", "body" => "new body" }
46
- }
47
-
48
- it_should_behave_like "a resource"
49
- it_should_behave_like "a resource with a collection GET endpoint"
50
- it_should_behave_like "a resource with a singular GET endpoint"
51
- it_should_behave_like "a resource with a DELETE endpoint"
52
- it_should_behave_like "a resource with a POST endpoint"
53
- it_should_behave_like "a resource with a PUT endpoint"
38
+ let(:attributes_for_put) {
39
+ {"body" => "new body"}
40
+ }
41
+ let(:expected_attributes_from_put) {
42
+ { "id" => "10000", "body" => "new body" }
43
+ }
44
+
45
+ it_should_behave_like "a resource"
46
+ it_should_behave_like "a resource with a collection GET endpoint"
47
+ it_should_behave_like "a resource with a singular GET endpoint"
48
+ it_should_behave_like "a resource with a DELETE endpoint"
49
+ it_should_behave_like "a resource with a POST endpoint"
50
+ it_should_behave_like "a resource with a PUT endpoint"
51
+
52
+ end
54
53
 
55
54
  end
@@ -3,41 +3,40 @@ require 'spec_helper'
3
3
  describe JIRA::Resource::Component do
4
4
 
5
5
 
6
- let(:client) do
7
- client = JIRA::Client.new('foo', 'bar')
8
- client.set_access_token('abc', '123')
9
- client
10
- end
11
-
12
- let(:key) { "10000" }
6
+ with_each_client do |site_url, client|
7
+ let(:client) { client }
8
+ let(:site_url) { site_url }
9
+
10
+ let(:key) { "10000" }
11
+
12
+ let(:expected_attributes) do
13
+ {
14
+ 'self' => "http://localhost:2990/jira/rest/api/2/component/10000",
15
+ 'id' => key,
16
+ 'name' => "Cheesecake"
17
+ }
18
+ end
19
+
20
+ let(:attributes_for_post) {
21
+ {"name" => "Test component", "project" => "SAMPLEPROJECT" }
22
+ }
23
+ let(:expected_attributes_from_post) {
24
+ { "id" => "10001", "name" => "Test component" }
25
+ }
13
26
 
14
- let(:expected_attributes) do
15
- {
16
- 'self' => "http://localhost:2990/jira/rest/api/2/component/10000",
17
- 'id' => key,
18
- 'name' => "Cheesecake"
27
+ let(:attributes_for_put) {
28
+ {"name" => "Jammy", "project" => "SAMPLEPROJECT" }
29
+ }
30
+ let(:expected_attributes_from_put) {
31
+ { "id" => "10000", "name" => "Jammy" }
19
32
  }
20
- end
21
33
 
22
- let(:attributes_for_post) {
23
- {"name" => "Test component", "project" => "SAMPLEPROJECT" }
24
- }
25
- let(:expected_attributes_from_post) {
26
- { "id" => "10001", "name" => "Test component" }
27
- }
28
-
29
- let(:attributes_for_put) {
30
- {"name" => "Jammy", "project" => "SAMPLEPROJECT" }
31
- }
32
- let(:expected_attributes_from_put) {
33
- { "id" => "10000", "name" => "Jammy" }
34
- }
35
-
36
- it_should_behave_like "a resource"
37
- it_should_behave_like "a resource with a singular GET endpoint"
38
- it_should_behave_like "a resource with a DELETE endpoint"
39
- it_should_behave_like "a resource with a POST endpoint"
40
- it_should_behave_like "a resource with a PUT endpoint"
41
- it_should_behave_like "a resource with a PUT endpoint that rejects invalid fields"
34
+ it_should_behave_like "a resource"
35
+ it_should_behave_like "a resource with a singular GET endpoint"
36
+ it_should_behave_like "a resource with a DELETE endpoint"
37
+ it_should_behave_like "a resource with a POST endpoint"
38
+ it_should_behave_like "a resource with a PUT endpoint"
39
+ it_should_behave_like "a resource with a PUT endpoint that rejects invalid fields"
42
40
 
41
+ end
43
42
  end
@@ -2,74 +2,77 @@ require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Issue do
4
4
 
5
- let(:client) do
6
- client = JIRA::Client.new('foo', 'bar')
7
- client.set_access_token('abc', '123')
8
- client
9
- end
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
8
+
10
9
 
11
- let(:key) { "10002" }
10
+ let(:key) { "10002" }
11
+
12
+ let(:expected_attributes) do
13
+ {
14
+ 'self' => "http://localhost:2990/jira/rest/api/2/issue/10002",
15
+ 'key' => "SAMPLEPROJECT-1",
16
+ 'expand' => "renderedFields,names,schema,transitions,editmeta,changelog"
17
+ }
18
+ end
12
19
 
13
- let(:expected_attributes) do
14
- {
15
- 'self' => "http://localhost:2990/jira/rest/api/2/issue/10002",
16
- 'key' => "SAMPLEPROJECT-1",
17
- 'expand' => "renderedFields,names,schema,transitions,editmeta,changelog"
20
+ let(:attributes_for_post) {
21
+ { 'foo' => 'bar' }
22
+ }
23
+ let(:expected_attributes_from_post) {
24
+ { "id" => "10005", "key" => "SAMPLEPROJECT-4" }
18
25
  }
19
- end
20
26
 
21
- let(:attributes_for_post) {
22
- { 'foo' => 'bar' }
23
- }
24
- let(:expected_attributes_from_post) {
25
- { "id" => "10005", "key" => "SAMPLEPROJECT-4" }
26
- }
27
+ let(:attributes_for_put) {
28
+ { 'foo' => 'bar' }
29
+ }
30
+ let(:expected_attributes_from_put) {
31
+ { 'foo' => 'bar' }
32
+ }
33
+ let(:expected_collection_length) { 11 }
27
34
 
28
- let(:attributes_for_put) {
29
- { 'foo' => 'bar' }
30
- }
31
- let(:expected_attributes_from_put) {
32
- { 'foo' => 'bar' }
33
- }
34
- let(:expected_collection_length) { 11 }
35
+ it_should_behave_like "a resource"
36
+ it_should_behave_like "a resource with a singular GET endpoint"
37
+ describe "GET all issues" do # JIRA::Resource::Issue.all uses the search endpoint
38
+ let(:client) { client }
39
+ let(:site_url) { site_url }
35
40
 
36
- it_should_behave_like "a resource"
37
- it_should_behave_like "a resource with a singular GET endpoint"
38
- describe "GET all issues" do # JIRA::Resource::Issue.all uses the search endpoint
39
- let(:expected_attributes) {
40
- {
41
- "id"=>"10014",
42
- "self"=>"http://localhost:2990/jira/rest/api/2/issue/10014",
43
- "key"=>"SAMPLEPROJECT-13"
41
+ let(:expected_attributes) {
42
+ {
43
+ "id"=>"10014",
44
+ "self"=>"http://localhost:2990/jira/rest/api/2/issue/10014",
45
+ "key"=>"SAMPLEPROJECT-13"
46
+ }
44
47
  }
45
- }
46
- before(:each) do
47
- stub_request(:get, "http://localhost:2990/jira/rest/api/2/search").
48
- to_return(:status => 200, :body => get_mock_response('issue.json'))
48
+ before(:each) do
49
+ stub_request(:get, site_url + "/jira/rest/api/2/search").
50
+ to_return(:status => 200, :body => get_mock_response('issue.json'))
51
+ end
52
+ it_should_behave_like "a resource with a collection GET endpoint"
49
53
  end
50
- it_should_behave_like "a resource with a collection GET endpoint"
51
- end
52
- it_should_behave_like "a resource with a DELETE endpoint"
53
- it_should_behave_like "a resource with a POST endpoint"
54
- it_should_behave_like "a resource with a PUT endpoint"
55
- it_should_behave_like "a resource with a PUT endpoint that rejects invalid fields"
54
+ it_should_behave_like "a resource with a DELETE endpoint"
55
+ it_should_behave_like "a resource with a POST endpoint"
56
+ it_should_behave_like "a resource with a PUT endpoint"
57
+ it_should_behave_like "a resource with a PUT endpoint that rejects invalid fields"
56
58
 
57
- describe "errors" do
58
- before(:each) do
59
- stub_request(:get,
60
- "http://localhost:2990/jira/rest/api/2/issue/10002").
61
- to_return(:status => 200, :body => get_mock_response('issue/10002.json'))
62
- stub_request(:put, "http://localhost:2990/jira/rest/api/2/issue/10002").
63
- with(:body => '{"missing":"fields and update"}').
64
- to_return(:status => 400, :body => get_mock_response('issue/10002.put.missing_field_update.json'))
65
- end
59
+ describe "errors" do
60
+ before(:each) do
61
+ stub_request(:get,
62
+ site_url + "/jira/rest/api/2/issue/10002").
63
+ to_return(:status => 200, :body => get_mock_response('issue/10002.json'))
64
+ stub_request(:put, site_url + "/jira/rest/api/2/issue/10002").
65
+ with(:body => '{"missing":"fields and update"}').
66
+ to_return(:status => 400, :body => get_mock_response('issue/10002.put.missing_field_update.json'))
67
+ end
68
+
69
+ it "fails to save when fields and update are missing" do
70
+ subject = client.Issue.build('id' => '10002')
71
+ subject.fetch
72
+ subject.save('missing' => 'fields and update').should be_false
73
+ end
66
74
 
67
- it "fails to save when fields and update are missing" do
68
- subject = client.Issue.build('id' => '10002')
69
- subject.fetch
70
- subject.save('missing' => 'fields and update').should be_false
71
75
  end
72
76
 
73
77
  end
74
-
75
78
  end
@@ -2,26 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Issuetype do
4
4
 
5
- let(:client) do
6
- client = JIRA::Client.new('foo', 'bar')
7
- client.set_access_token('abc', '123')
8
- client
9
- end
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
10
8
 
11
- let(:key) { "5" }
9
+ let(:key) { "5" }
12
10
 
13
- let(:expected_attributes) do
14
- {
15
- 'self' => "http://localhost:2990/jira/rest/api/2/issuetype/5",
16
- 'id' => key,
17
- 'name' => 'Sub-task'
18
- }
19
- end
11
+ let(:expected_attributes) do
12
+ {
13
+ 'self' => "http://localhost:2990/jira/rest/api/2/issuetype/5",
14
+ 'id' => key,
15
+ 'name' => 'Sub-task'
16
+ }
17
+ end
20
18
 
21
- let(:expected_collection_length) { 5 }
19
+ let(:expected_collection_length) { 5 }
22
20
 
23
- it_should_behave_like "a resource"
24
- it_should_behave_like "a resource with a collection GET endpoint"
25
- it_should_behave_like "a resource with a singular GET endpoint"
21
+ it_should_behave_like "a resource"
22
+ it_should_behave_like "a resource with a collection GET endpoint"
23
+ it_should_behave_like "a resource with a singular GET endpoint"
26
24
 
25
+ end
27
26
  end
@@ -2,26 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Priority do
4
4
 
5
- let(:client) do
6
- client = JIRA::Client.new('foo', 'bar')
7
- client.set_access_token('abc', '123')
8
- client
9
- end
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
10
8
 
11
- let(:key) { "1" }
12
9
 
13
- let(:expected_attributes) do
14
- {
15
- 'self' => "http://localhost:2990/jira/rest/api/2/priority/1",
16
- 'id' => key,
17
- 'name' => 'Blocker'
18
- }
19
- end
10
+ let(:key) { "1" }
20
11
 
21
- let(:expected_collection_length) { 5 }
12
+ let(:expected_attributes) do
13
+ {
14
+ 'self' => "http://localhost:2990/jira/rest/api/2/priority/1",
15
+ 'id' => key,
16
+ 'name' => 'Blocker'
17
+ }
18
+ end
22
19
 
23
- it_should_behave_like "a resource"
24
- it_should_behave_like "a resource with a collection GET endpoint"
25
- it_should_behave_like "a resource with a singular GET endpoint"
20
+ let(:expected_collection_length) { 5 }
26
21
 
22
+ it_should_behave_like "a resource"
23
+ it_should_behave_like "a resource with a collection GET endpoint"
24
+ it_should_behave_like "a resource with a singular GET endpoint"
25
+
26
+ end
27
27
  end