jira-ruby-added-transitions 0.1.3

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.
Files changed (96) hide show
  1. data/.gitignore +10 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +46 -0
  4. data/README.rdoc +327 -0
  5. data/Rakefile +28 -0
  6. data/example.rb +119 -0
  7. data/http-basic-example.rb +112 -0
  8. data/jira-ruby.gemspec +30 -0
  9. data/lib/jira.rb +31 -0
  10. data/lib/jira/base.rb +469 -0
  11. data/lib/jira/base_factory.rb +49 -0
  12. data/lib/jira/client.rb +151 -0
  13. data/lib/jira/has_many_proxy.rb +43 -0
  14. data/lib/jira/http_client.rb +41 -0
  15. data/lib/jira/http_error.rb +16 -0
  16. data/lib/jira/oauth_client.rb +84 -0
  17. data/lib/jira/railtie.rb +10 -0
  18. data/lib/jira/request_client.rb +18 -0
  19. data/lib/jira/resource/attachment.rb +12 -0
  20. data/lib/jira/resource/comment.rb +14 -0
  21. data/lib/jira/resource/component.rb +10 -0
  22. data/lib/jira/resource/issue.rb +72 -0
  23. data/lib/jira/resource/issuetype.rb +10 -0
  24. data/lib/jira/resource/priority.rb +10 -0
  25. data/lib/jira/resource/project.rb +30 -0
  26. data/lib/jira/resource/status.rb +10 -0
  27. data/lib/jira/resource/transition.rb +16 -0
  28. data/lib/jira/resource/user.rb +14 -0
  29. data/lib/jira/resource/version.rb +10 -0
  30. data/lib/jira/resource/worklog.rb +16 -0
  31. data/lib/jira/tasks.rb +0 -0
  32. data/lib/jira/version.rb +3 -0
  33. data/lib/tasks/generate.rake +18 -0
  34. data/spec/integration/attachment_spec.rb +23 -0
  35. data/spec/integration/comment_spec.rb +54 -0
  36. data/spec/integration/component_spec.rb +42 -0
  37. data/spec/integration/issue_spec.rb +94 -0
  38. data/spec/integration/issuetype_spec.rb +26 -0
  39. data/spec/integration/priority_spec.rb +27 -0
  40. data/spec/integration/project_spec.rb +56 -0
  41. data/spec/integration/status_spec.rb +27 -0
  42. data/spec/integration/user_spec.rb +25 -0
  43. data/spec/integration/version_spec.rb +43 -0
  44. data/spec/integration/worklog_spec.rb +55 -0
  45. data/spec/jira/base_factory_spec.rb +46 -0
  46. data/spec/jira/base_spec.rb +556 -0
  47. data/spec/jira/client_spec.rb +188 -0
  48. data/spec/jira/has_many_proxy_spec.rb +45 -0
  49. data/spec/jira/http_client_spec.rb +77 -0
  50. data/spec/jira/http_error_spec.rb +25 -0
  51. data/spec/jira/oauth_client_spec.rb +111 -0
  52. data/spec/jira/request_client_spec.rb +14 -0
  53. data/spec/jira/resource/attachment_spec.rb +20 -0
  54. data/spec/jira/resource/issue_spec.rb +83 -0
  55. data/spec/jira/resource/project_factory_spec.rb +13 -0
  56. data/spec/jira/resource/project_spec.rb +28 -0
  57. data/spec/jira/resource/worklog_spec.rb +24 -0
  58. data/spec/mock_responses/attachment/10000.json +20 -0
  59. data/spec/mock_responses/component.post.json +28 -0
  60. data/spec/mock_responses/component/10000.invalid.put.json +5 -0
  61. data/spec/mock_responses/component/10000.json +39 -0
  62. data/spec/mock_responses/component/10000.put.json +39 -0
  63. data/spec/mock_responses/issue.json +1108 -0
  64. data/spec/mock_responses/issue.post.json +5 -0
  65. data/spec/mock_responses/issue/10002.invalid.put.json +6 -0
  66. data/spec/mock_responses/issue/10002.json +126 -0
  67. data/spec/mock_responses/issue/10002.put.missing_field_update.json +6 -0
  68. data/spec/mock_responses/issue/10002/comment.json +65 -0
  69. data/spec/mock_responses/issue/10002/comment.post.json +29 -0
  70. data/spec/mock_responses/issue/10002/comment/10000.json +29 -0
  71. data/spec/mock_responses/issue/10002/comment/10000.put.json +29 -0
  72. data/spec/mock_responses/issue/10002/worklog.json +98 -0
  73. data/spec/mock_responses/issue/10002/worklog.post.json +30 -0
  74. data/spec/mock_responses/issue/10002/worklog/10000.json +31 -0
  75. data/spec/mock_responses/issue/10002/worklog/10000.put.json +30 -0
  76. data/spec/mock_responses/issuetype.json +42 -0
  77. data/spec/mock_responses/issuetype/5.json +8 -0
  78. data/spec/mock_responses/priority.json +42 -0
  79. data/spec/mock_responses/priority/1.json +8 -0
  80. data/spec/mock_responses/project.json +12 -0
  81. data/spec/mock_responses/project/SAMPLEPROJECT.issues.json +1108 -0
  82. data/spec/mock_responses/project/SAMPLEPROJECT.json +84 -0
  83. data/spec/mock_responses/status.json +37 -0
  84. data/spec/mock_responses/status/1.json +7 -0
  85. data/spec/mock_responses/user_username=admin.json +17 -0
  86. data/spec/mock_responses/version.post.json +7 -0
  87. data/spec/mock_responses/version/10000.invalid.put.json +5 -0
  88. data/spec/mock_responses/version/10000.json +11 -0
  89. data/spec/mock_responses/version/10000.put.json +7 -0
  90. data/spec/spec_helper.rb +22 -0
  91. data/spec/support/clients_helper.rb +16 -0
  92. data/spec/support/matchers/have_attributes.rb +11 -0
  93. data/spec/support/matchers/have_many.rb +9 -0
  94. data/spec/support/matchers/have_one.rb +5 -0
  95. data/spec/support/shared_examples/integration.rb +190 -0
  96. metadata +315 -0
@@ -0,0 +1,10 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class ComponentFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Component < JIRA::Base ; end
8
+
9
+ end
10
+ end
@@ -0,0 +1,72 @@
1
+ require 'cgi'
2
+
3
+ module JIRA
4
+ module Resource
5
+
6
+ class IssueFactory < JIRA::BaseFactory # :nodoc:
7
+ end
8
+
9
+ class Issue < JIRA::Base
10
+
11
+ has_one :reporter, :class => JIRA::Resource::User,
12
+ :nested_under => 'fields'
13
+ has_one :assignee, :class => JIRA::Resource::User,
14
+ :nested_under => 'fields'
15
+ has_one :project, :nested_under => 'fields'
16
+
17
+ has_one :issuetype, :nested_under => 'fields'
18
+
19
+ has_one :priority, :nested_under => 'fields'
20
+
21
+ has_one :status, :nested_under => 'fields'
22
+
23
+ has_many :components, :nested_under => 'fields'
24
+
25
+ has_many :comments, :nested_under => ['fields','comment']
26
+
27
+ has_many :attachments, :nested_under => 'fields',
28
+ :attribute_key => 'attachment'
29
+
30
+ has_many :versions, :nested_under => 'fields'
31
+
32
+ has_many :worklogs, :nested_under => ['fields','worklog']
33
+
34
+ has_many :transitions
35
+
36
+ def self.all(client)
37
+ response = client.get(client.options[:rest_base_path] + "/search")
38
+ json = parse_json(response.body)
39
+ json['issues'].map do |issue|
40
+ client.Issue.build(issue)
41
+ end
42
+ end
43
+
44
+ def self.jql(client, jql)
45
+ url = client.options[:rest_base_path] + "/search?jql=" + CGI.escape(jql)
46
+ response = client.get(url)
47
+ json = parse_json(response.body)
48
+ json['issues'].map do |issue|
49
+ client.Issue.build(issue)
50
+ end
51
+ end
52
+
53
+ def respond_to?(method_name)
54
+ if attrs.keys.include?('fields') && attrs['fields'].keys.include?(method_name.to_s)
55
+ true
56
+ else
57
+ super(method_name)
58
+ end
59
+ end
60
+
61
+ def method_missing(method_name, *args, &block)
62
+ if attrs.keys.include?('fields') && attrs['fields'].keys.include?(method_name.to_s)
63
+ attrs['fields'][method_name.to_s]
64
+ else
65
+ super(method_name)
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,10 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class IssuetypeFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Issuetype < JIRA::Base ; end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class PriorityFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Priority < JIRA::Base ; end
8
+
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class ProjectFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Project < JIRA::Base
8
+
9
+ has_one :lead, :class => JIRA::Resource::User
10
+ has_many :components
11
+ has_many :issuetypes, :attribute_key => 'issueTypes'
12
+ has_many :versions
13
+
14
+ def self.key_attribute
15
+ :key
16
+ end
17
+
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}'")
21
+ json = self.class.parse_json(response.body)
22
+ json['issues'].map do |issue|
23
+ client.Issue.build(issue)
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class StatusFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Status < JIRA::Base ; end
8
+
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class TransitionFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class Transition < JIRA::Base
8
+ belongs_to :issue
9
+
10
+ def url
11
+ "#{@issue.self}/transitions"
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module JIRA
2
+ module Resource
3
+
4
+ class UserFactory < JIRA::BaseFactory # :nodoc:
5
+ end
6
+
7
+ class User < JIRA::Base
8
+ def self.singular_path(client, key, prefix = '/')
9
+ collection_path(client, prefix) + '?username=' + key
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -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
File without changes
@@ -0,0 +1,3 @@
1
+ module JIRA
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'securerandom'
2
+
3
+ namespace :jira do
4
+ desc "Generate a consumer key for your application"
5
+ task :generate_consumer_key do
6
+ key = SecureRandom.hex(16)
7
+ puts "You can use this as your consumer key: #{key}"
8
+ end
9
+
10
+ desc "Run the system call to generate a RSA public certificate"
11
+ task :generate_public_cert do
12
+ puts "Executing 'openssl req -x509 -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem'"
13
+ system("openssl req -x509 -nodes -newkey rsa:1024 -sha1 -keyout rsakey.pem -out rsacert.pem")
14
+ puts "Done. The RSA-SHA1 private keyfile is in the current directory: \'rsakey.pem\'."
15
+ puts "You will need to copy the following certificate into your application link configuration in Jira:"
16
+ system("cat rsacert.pem")
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Attachment do
4
+
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
8
+
9
+ let(:key) { "10000" }
10
+
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
18
+
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"
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Comment do
4
+
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
8
+
9
+ let(:key) { "10000" }
10
+
11
+ let(:target) { JIRA::Resource::Comment.new(client, :attrs => {'id' => '99999'}, :issue_id => '54321') }
12
+
13
+ let(:expected_collection_length) { 2 }
14
+
15
+ let(:belongs_to) {
16
+ JIRA::Resource::Issue.new(client, :attrs => {
17
+ 'id' => '10002', 'fields' => {
18
+ 'comment' => {'comments' => []}
19
+ }
20
+ })
21
+ }
22
+
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."
28
+ }
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"}
36
+ }
37
+
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
53
+
54
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Component do
4
+
5
+
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
+ }
26
+
27
+ let(:attributes_for_put) {
28
+ {"name" => "Jammy", "project" => "SAMPLEPROJECT" }
29
+ }
30
+ let(:expected_attributes_from_put) {
31
+ { "id" => "10000", "name" => "Jammy" }
32
+ }
33
+
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"
40
+
41
+ end
42
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Issue do
4
+
5
+ with_each_client do |site_url, client|
6
+ let(:client) { client }
7
+ let(:site_url) { site_url }
8
+
9
+
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
19
+
20
+ let(:attributes_for_post) {
21
+ { 'foo' => 'bar' }
22
+ }
23
+ let(:expected_attributes_from_post) {
24
+ { "id" => "10005", "key" => "SAMPLEPROJECT-4" }
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 }
34
+
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 }
40
+
41
+ let(:expected_attributes) {
42
+ {
43
+ "id"=>"10014",
44
+ "self"=>"http://localhost:2990/jira/rest/api/2/issue/10014",
45
+ "key"=>"SAMPLEPROJECT-13"
46
+ }
47
+ }
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"
53
+ end
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"
58
+
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
74
+
75
+ end
76
+
77
+ describe "GET jql issues" do # JIRA::Resource::Issue.jql uses the search endpoint
78
+ jql_query_string = "PROJECT = 'SAMPLEPROJECT'"
79
+ let(:client) { client }
80
+ let(:site_url) { site_url }
81
+ let(:jql_query_string) { jql_query_string }
82
+
83
+ let(:expected_attributes) {
84
+ {
85
+ "id"=>"10014",
86
+ "self"=>"http://localhost:2990/jira/rest/api/2/issue/10014",
87
+ "key"=>"SAMPLEPROJECT-13"
88
+ }
89
+ }
90
+ it_should_behave_like "a resource with JQL inputs and a collection GET endpoint"
91
+ end
92
+
93
+ end
94
+ end