jira-ruby 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +51 -7
- data/http-basic-example.rb +106 -0
- data/lib/jira.rb +3 -0
- data/lib/jira/client.rb +41 -74
- data/lib/jira/http_client.rb +41 -0
- data/lib/jira/oauth_client.rb +84 -0
- data/lib/jira/request_client.rb +18 -0
- data/lib/jira/version.rb +1 -1
- data/spec/integration/attachment_spec.rb +14 -17
- data/spec/integration/comment_spec.rb +40 -41
- data/spec/integration/component_spec.rb +32 -33
- data/spec/integration/issue_spec.rb +60 -57
- data/spec/integration/issuetype_spec.rb +16 -17
- data/spec/integration/priority_spec.rb +17 -17
- data/spec/integration/project_spec.rb +36 -36
- data/spec/integration/status_spec.rb +17 -17
- data/spec/integration/user_spec.rb +15 -15
- data/spec/integration/version_spec.rb +32 -32
- data/spec/integration/worklog_spec.rb +41 -41
- data/spec/jira/client_spec.rb +125 -95
- data/spec/jira/http_client_spec.rb +79 -0
- data/spec/jira/oauth_client_spec.rb +111 -0
- data/spec/jira/request_client_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/clients_helper.rb +16 -0
- data/spec/support/shared_examples/integration.rb +11 -11
- metadata +30 -18
@@ -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
@@ -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
|
-
|
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
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
-
|
11
|
+
let(:target) { JIRA::Resource::Comment.new(client, :attrs => {'id' => '99999'}, :issue_id => '54321') }
|
13
12
|
|
14
|
-
|
13
|
+
let(:expected_collection_length) { 2 }
|
15
14
|
|
16
|
-
|
15
|
+
let(:belongs_to) {
|
16
|
+
JIRA::Resource::Issue.new(client, :attrs => {
|
17
|
+
'id' => '10002', 'fields' => {
|
18
|
+
'comment' => {'comments' => []}
|
19
|
+
}
|
20
|
+
})
|
21
|
+
}
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
'
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
7
|
-
client
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
6
|
-
client
|
7
|
-
|
8
|
-
|
9
|
-
end
|
5
|
+
with_each_client do |site_url, client|
|
6
|
+
let(:client) { client }
|
7
|
+
let(:site_url) { site_url }
|
8
|
+
|
10
9
|
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
6
|
-
client
|
7
|
-
|
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
|
-
|
9
|
+
let(:key) { "5" }
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
19
|
+
let(:expected_collection_length) { 5 }
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
6
|
-
client
|
7
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|