jira-ruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/README.rdoc +259 -0
  2. data/Rakefile +9 -0
  3. data/example.rb +47 -4
  4. data/jira-ruby.gemspec +5 -3
  5. data/lib/jira.rb +21 -7
  6. data/lib/jira/base.rb +466 -0
  7. data/lib/jira/base_factory.rb +49 -0
  8. data/lib/jira/client.rb +79 -8
  9. data/lib/jira/has_many_proxy.rb +43 -0
  10. data/lib/jira/http_error.rb +16 -0
  11. data/lib/jira/resource/attachment.rb +12 -0
  12. data/lib/jira/resource/comment.rb +14 -0
  13. data/lib/jira/resource/component.rb +4 -9
  14. data/lib/jira/resource/issue.rb +49 -5
  15. data/lib/jira/resource/issuetype.rb +10 -0
  16. data/lib/jira/resource/priority.rb +10 -0
  17. data/lib/jira/resource/project.rb +24 -3
  18. data/lib/jira/resource/status.rb +10 -0
  19. data/lib/jira/resource/user.rb +14 -0
  20. data/lib/jira/resource/version.rb +10 -0
  21. data/lib/jira/resource/worklog.rb +16 -0
  22. data/lib/jira/version.rb +2 -2
  23. data/spec/integration/attachment_spec.rb +26 -0
  24. data/spec/integration/comment_spec.rb +55 -0
  25. data/spec/integration/component_spec.rb +25 -52
  26. data/spec/integration/issue_spec.rb +50 -47
  27. data/spec/integration/issuetype_spec.rb +27 -0
  28. data/spec/integration/priority_spec.rb +27 -0
  29. data/spec/integration/project_spec.rb +32 -24
  30. data/spec/integration/status_spec.rb +27 -0
  31. data/spec/integration/user_spec.rb +25 -0
  32. data/spec/integration/version_spec.rb +43 -0
  33. data/spec/integration/worklog_spec.rb +55 -0
  34. data/spec/jira/base_factory_spec.rb +46 -0
  35. data/spec/jira/base_spec.rb +555 -0
  36. data/spec/jira/client_spec.rb +12 -12
  37. data/spec/jira/has_many_proxy_spec.rb +45 -0
  38. data/spec/jira/{resource/http_error_spec.rb → http_error_spec.rb} +1 -1
  39. data/spec/jira/resource/attachment_spec.rb +20 -0
  40. data/spec/jira/resource/issue_spec.rb +83 -0
  41. data/spec/jira/resource/project_factory_spec.rb +3 -3
  42. data/spec/jira/resource/project_spec.rb +28 -0
  43. data/spec/jira/resource/worklog_spec.rb +24 -0
  44. data/spec/mock_responses/attachment/10000.json +20 -0
  45. data/spec/mock_responses/component/10000.invalid.put.json +5 -0
  46. data/spec/mock_responses/issue.json +1108 -0
  47. data/spec/mock_responses/issue/10002.invalid.put.json +6 -0
  48. data/spec/mock_responses/issue/10002.json +13 -1
  49. data/spec/mock_responses/issue/10002.put.missing_field_update.json +6 -0
  50. data/spec/mock_responses/issue/10002/comment.json +65 -0
  51. data/spec/mock_responses/issue/10002/comment.post.json +29 -0
  52. data/spec/mock_responses/issue/10002/comment/10000.json +29 -0
  53. data/spec/mock_responses/issue/10002/comment/10000.put.json +29 -0
  54. data/spec/mock_responses/issue/10002/worklog.json +98 -0
  55. data/spec/mock_responses/issue/10002/worklog.post.json +30 -0
  56. data/spec/mock_responses/issue/10002/worklog/10000.json +31 -0
  57. data/spec/mock_responses/issue/10002/worklog/10000.put.json +30 -0
  58. data/spec/mock_responses/issuetype.json +42 -0
  59. data/spec/mock_responses/issuetype/5.json +8 -0
  60. data/spec/mock_responses/priority.json +42 -0
  61. data/spec/mock_responses/priority/1.json +8 -0
  62. data/spec/mock_responses/project/SAMPLEPROJECT.issues.json +1108 -0
  63. data/spec/mock_responses/project/SAMPLEPROJECT.json +15 -1
  64. data/spec/mock_responses/status.json +37 -0
  65. data/spec/mock_responses/status/1.json +7 -0
  66. data/spec/mock_responses/user?username=admin.json +17 -0
  67. data/spec/mock_responses/version.post.json +7 -0
  68. data/spec/mock_responses/version/10000.invalid.put.json +5 -0
  69. data/spec/mock_responses/version/10000.json +11 -0
  70. data/spec/mock_responses/version/10000.put.json +7 -0
  71. data/spec/spec_helper.rb +7 -12
  72. data/spec/support/matchers/have_attributes.rb +11 -0
  73. data/spec/support/matchers/have_many.rb +9 -0
  74. data/spec/support/matchers/have_one.rb +5 -0
  75. data/spec/support/shared_examples/integration.rb +174 -0
  76. metadata +139 -24
  77. data/README.markdown +0 -81
  78. data/lib/jira/resource/base.rb +0 -148
  79. data/lib/jira/resource/base_factory.rb +0 -44
  80. data/lib/jira/resource/http_error.rb +0 -17
  81. data/spec/jira/resource/base_factory_spec.rb +0 -36
  82. data/spec/jira/resource/base_spec.rb +0 -292
@@ -0,0 +1,10 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class VersionFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Version < JIRA::Base ; end
8
+
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class WorklogFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Worklog < JIRA::Base
8
+ has_one :author, :class => JIRA::Resource::User
9
+ has_one :update_author, :class => JIRA::Resource::User,
10
+ :attribute_key => "updateAuthor"
11
+ belongs_to :issue
12
+ nested_collections true
13
+ end
14
+
15
+ end
16
+ end
data/lib/jira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Jira
2
- VERSION = "0.0.2"
1
+ module JIRA
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Attachment do
4
+
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" }
13
+
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
+ }
20
+ 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
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Comment do
4
+
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" }
13
+
14
+ let(:target) { JIRA::Resource::Comment.new(client, :attrs => {'id' => '99999'}, :issue_id => '54321') }
15
+
16
+ let(:expected_collection_length) { 2 }
17
+
18
+ let(:belongs_to) {
19
+ JIRA::Resource::Issue.new(client, :attrs => {
20
+ 'id' => '10002', 'fields' => {
21
+ 'comment' => {'comments' => []}
22
+ }
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."
31
+ }
32
+ end
33
+
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"
54
+
55
+ end
@@ -1,70 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Jira::Resource::Component do
3
+ describe JIRA::Resource::Component do
4
4
 
5
5
 
6
6
  let(:client) do
7
- client = Jira::Client.new('foo', 'bar')
7
+ client = JIRA::Client.new('foo', 'bar')
8
8
  client.set_access_token('abc', '123')
9
9
  client
10
10
  end
11
11
 
12
+ let(:key) { "10000" }
13
+
12
14
  let(:expected_attributes) do
13
15
  {
14
16
  'self' => "http://localhost:2990/jira/rest/api/2/component/10000",
15
- 'id' => "10000",
17
+ 'id' => key,
16
18
  'name' => "Cheesecake"
17
19
  }
18
20
  end
19
21
 
20
- before(:each) do
21
- stub_request(:get,
22
- "http://localhost:2990/jira/rest/api/2/component/10000").
23
- to_return(:body => get_mock_response('component/10000.json'))
24
- stub_request(:delete,
25
- "http://localhost:2990/jira/rest/api/2/component/10000").
26
- to_return(:body => nil)
27
- stub_request(:post,
28
- "http://localhost:2990/jira/rest/api/2/component").
29
- with(:body => '{"name":"Test component","project":"SAMPLEPROJECT"}').
30
- to_return(:status => 201, :body => get_mock_response('component.post.json'))
31
- stub_request(:put,
32
- "http://localhost:2990/jira/rest/api/2/component/10000").
33
- with(:body => '{"name":"Jammy"}').
34
- to_return(:status => 200, :body => get_mock_response('component/10000.put.json'))
35
- end
36
-
37
- it "should get a single component by id" do
38
- component = client.Component.find(10000)
39
-
40
- component.should have_attributes(expected_attributes)
41
- end
42
-
43
- it "builds and fetches single component" do
44
- component = client.Component.build('id' => 10000)
45
- component.fetch
46
-
47
- component.should have_attributes(expected_attributes)
48
- end
49
-
50
- it "deletes a component" do
51
- component = client.Component.build('id' => "10000")
52
- component.delete.should be_true
53
- end
54
-
55
- it "saves a new component" do
56
- component = client.Component.build
57
- component.save({"name" => "Test component", "project" => "SAMPLEPROJECT"}).should be_true
58
- component.id.should == "10001"
59
- component.name.should == "Test component"
60
- end
61
-
62
- it "saves an existing component" do
63
- component = client.Component.build('id' => '10000')
64
- component.fetch
65
- component.save('name' => 'Jammy').should be_true
66
- component.id.should == "10000"
67
- component.name.should == "Jammy"
68
- end
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"
69
42
 
70
43
  end
@@ -1,13 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Jira::Resource::Issue do
3
+ describe JIRA::Resource::Issue do
4
4
 
5
5
  let(:client) do
6
- client = Jira::Client.new('foo', 'bar')
6
+ client = JIRA::Client.new('foo', 'bar')
7
7
  client.set_access_token('abc', '123')
8
8
  client
9
9
  end
10
10
 
11
+ let(:key) { "10002" }
12
+
11
13
  let(:expected_attributes) do
12
14
  {
13
15
  'self' => "http://localhost:2990/jira/rest/api/2/issue/10002",
@@ -16,57 +18,58 @@ describe Jira::Resource::Issue do
16
18
  }
17
19
  end
18
20
 
19
- before(:each) do
20
- stub_request(:get,
21
- "http://localhost:2990/jira/rest/api/2/issue/10002").
22
- to_return(:body => get_mock_response('issue/10002.json'))
23
- stub_request(:delete,
24
- "http://localhost:2990/jira/rest/api/2/issue/10002").
25
- to_return(:body => nil)
26
- stub_request(:post, "http://localhost:2990/jira/rest/api/2/issue").
27
- with(:body => '{"foo":"bar"}').
28
- to_return(:body => get_mock_response('issue.post.json'))
29
- stub_request(:put, "http://localhost:2990/jira/rest/api/2/issue/10002").
30
- with(:body => '{"foo":"bar"}').
31
- to_return(:body => nil)
32
- stub_request(:get,
33
- "http://localhost:2990/jira/rest/api/2/issue/99999").
34
- to_return(:status => 404, :body => '{"errorMessages":["Issue Does Not Exist"],"errors": {}}')
35
- end
36
-
37
- it "should get a single issue by key" do
38
- issue = client.Issue.find('10002')
39
-
40
- issue.should have_attributes(expected_attributes)
41
- end
42
-
43
- it "should handle issue not found" do
44
- lambda do
45
- issue = client.Issue.find('99999')
46
- end.should raise_exception(Jira::Resource::HTTPError)
47
- end
21
+ let(:attributes_for_post) {
22
+ { 'foo' => 'bar' }
23
+ }
24
+ let(:expected_attributes_from_post) {
25
+ { "id" => "10005", "key" => "SAMPLEPROJECT-4" }
26
+ }
48
27
 
49
- it "builds and fetches single issue" do
50
- issue = client.Issue.build('id' => '10002')
51
- issue.fetch
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 }
52
35
 
53
- issue.should have_attributes(expected_attributes)
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"
44
+ }
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'))
49
+ end
50
+ it_should_behave_like "a resource with a collection GET endpoint"
54
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"
55
56
 
56
- it "deletes an issue" do
57
- issue = client.Issue.build('id' => "10002")
58
- issue.delete.should be_true
59
- end
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
60
66
 
61
- it "should save a new record" do
62
- subject = described_class.new(client)
63
- subject.save('foo' => 'bar').should be_true
64
- end
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
+ end
65
72
 
66
- it "should save an existing record" do
67
- subject = client.Issue.build('id' => '10002')
68
- subject.fetch
69
- subject.save('foo' => 'bar').should be_true
70
73
  end
71
74
 
72
75
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Issuetype do
4
+
5
+ let(:client) do
6
+ client = JIRA::Client.new('foo', 'bar')
7
+ client.set_access_token('abc', '123')
8
+ client
9
+ end
10
+
11
+ let(:key) { "5" }
12
+
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
20
+
21
+ let(:expected_collection_length) { 5 }
22
+
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"
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Priority do
4
+
5
+ let(:client) do
6
+ client = JIRA::Client.new('foo', 'bar')
7
+ client.set_access_token('abc', '123')
8
+ client
9
+ end
10
+
11
+ let(:key) { "1" }
12
+
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
20
+
21
+ let(:expected_collection_length) { 5 }
22
+
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"
26
+
27
+ end
@@ -1,48 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Jira::Resource::Project do
3
+ describe JIRA::Resource::Project do
4
4
 
5
5
  let(:client) do
6
- client = Jira::Client.new('foo', 'bar')
6
+ client = JIRA::Client.new('foo', 'bar')
7
7
  client.set_access_token('abc', '123')
8
8
  client
9
9
  end
10
10
 
11
+ let(:key) { "SAMPLEPROJECT" }
12
+
11
13
  let(:expected_attributes) do
12
14
  {
13
15
  'self' => "http://localhost:2990/jira/rest/api/2/project/SAMPLEPROJECT",
14
- 'key' => "SAMPLEPROJECT",
16
+ 'key' => key,
15
17
  'name' => "Sample Project for Developing RoR RESTful API"
16
18
  }
17
19
  end
18
20
 
19
- before(:each) do
20
- stub_request(:get,
21
- "http://localhost:2990/jira/rest/api/2/project").
22
- to_return(:body => get_mock_response('project.json'))
23
- stub_request(:get,
24
- "http://localhost:2990/jira/rest/api/2/project/SAMPLEPROJECT").
25
- to_return(:body => get_mock_response('project/SAMPLEPROJECT.json'))
26
- end
21
+ let(:expected_collection_length) { 1 }
27
22
 
28
- it "should get all the projects" do
29
- projects = client.Project.all
30
- projects.length.should == 1
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"
31
26
 
32
- first = projects.first
33
- first.should have_attributes(expected_attributes)
34
- end
27
+ describe "issues" do
35
28
 
36
- it "should get a single project by key" do
37
- project = client.Project.find('SAMPLEPROJECT')
29
+ it "returns all the issues" do
30
+ stub_request(:get, "http://localhost:2990/jira/rest/api/2/search?jql=project='SAMPLEPROJECT'").
31
+ to_return(:status => 200, :body => get_mock_response('project/SAMPLEPROJECT.issues.json'))
32
+ subject = client.Project.build('key' => key)
33
+ issues = subject.issues
34
+ issues.length.should == 11
35
+ issues.each do |issue|
36
+ issue.class.should == JIRA::Resource::Issue
37
+ issue.expanded?.should be_false
38
+ end
39
+
40
+ end
38
41
 
39
- project.should have_attributes(expected_attributes)
40
42
  end
41
43
 
42
- it "builds and fetches single project" do
43
- project = client.Project.build('key' => 'SAMPLEPROJECT')
44
- project.fetch
44
+ it "returns a collection of components" do
45
+
46
+ stub_request(:get, 'http://localhost:2990' + described_class.singular_path(client, key)).
47
+ to_return(:status => 200, :body => get_mock_response('project/SAMPLEPROJECT.json'))
48
+
49
+ subject = client.Project.find(key)
50
+ subject.components.length.should == 2
51
+ subject.components.each do |component|
52
+ component.class.should == JIRA::Resource::Component
53
+ end
45
54
 
46
- project.should have_attributes(expected_attributes)
47
55
  end
48
56
  end