jira-ruby 1.2.0 → 2.3.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.
Files changed (109) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.travis.yml +5 -3
  4. data/Gemfile +7 -1
  5. data/Guardfile +1 -1
  6. data/README.md +452 -0
  7. data/Rakefile +6 -7
  8. data/example.rb +23 -1
  9. data/http-basic-example.rb +13 -12
  10. data/jira-ruby.gemspec +13 -13
  11. data/lib/jira/base.rb +53 -52
  12. data/lib/jira/base_factory.rb +3 -6
  13. data/lib/jira/client.rb +127 -30
  14. data/lib/jira/has_many_proxy.rb +0 -1
  15. data/lib/jira/http_client.rb +54 -16
  16. data/lib/jira/http_error.rb +3 -5
  17. data/lib/jira/jwt_client.rb +67 -0
  18. data/lib/jira/oauth_client.rb +47 -17
  19. data/lib/jira/request_client.rb +16 -5
  20. data/lib/jira/resource/agile.rb +34 -9
  21. data/lib/jira/resource/applinks.rb +5 -8
  22. data/lib/jira/resource/attachment.rb +41 -3
  23. data/lib/jira/resource/board.rb +91 -0
  24. data/lib/jira/resource/board_configuration.rb +9 -0
  25. data/lib/jira/resource/comment.rb +0 -2
  26. data/lib/jira/resource/component.rb +1 -3
  27. data/lib/jira/resource/createmeta.rb +12 -14
  28. data/lib/jira/resource/field.rb +22 -22
  29. data/lib/jira/resource/filter.rb +2 -2
  30. data/lib/jira/resource/issue.rb +69 -38
  31. data/lib/jira/resource/issue_picker_suggestions.rb +24 -0
  32. data/lib/jira/resource/issue_picker_suggestions_issue.rb +10 -0
  33. data/lib/jira/resource/issuelink.rb +3 -5
  34. data/lib/jira/resource/issuelinktype.rb +0 -1
  35. data/lib/jira/resource/issuetype.rb +1 -3
  36. data/lib/jira/resource/priority.rb +1 -3
  37. data/lib/jira/resource/project.rb +5 -7
  38. data/lib/jira/resource/rapidview.rb +28 -7
  39. data/lib/jira/resource/remotelink.rb +1 -4
  40. data/lib/jira/resource/resolution.rb +2 -4
  41. data/lib/jira/resource/serverinfo.rb +1 -2
  42. data/lib/jira/resource/sprint.rb +86 -17
  43. data/lib/jira/resource/sprint_report.rb +8 -0
  44. data/lib/jira/resource/status.rb +1 -3
  45. data/lib/jira/resource/suggested_issue.rb +9 -0
  46. data/lib/jira/resource/transition.rb +2 -6
  47. data/lib/jira/resource/user.rb +12 -2
  48. data/lib/jira/resource/version.rb +1 -3
  49. data/lib/jira/resource/watcher.rb +35 -0
  50. data/lib/jira/resource/webhook.rb +3 -6
  51. data/lib/jira/resource/worklog.rb +3 -5
  52. data/lib/jira/version.rb +1 -1
  53. data/lib/jira-ruby.rb +12 -2
  54. data/lib/tasks/generate.rake +4 -4
  55. data/spec/integration/attachment_spec.rb +17 -8
  56. data/spec/integration/comment_spec.rb +31 -34
  57. data/spec/integration/component_spec.rb +21 -24
  58. data/spec/integration/field_spec.rb +15 -18
  59. data/spec/integration/issue_spec.rb +45 -46
  60. data/spec/integration/issuelinktype_spec.rb +8 -11
  61. data/spec/integration/issuetype_spec.rb +5 -7
  62. data/spec/integration/priority_spec.rb +5 -8
  63. data/spec/integration/project_spec.rb +13 -20
  64. data/spec/integration/rapidview_spec.rb +17 -10
  65. data/spec/integration/resolution_spec.rb +7 -10
  66. data/spec/integration/status_spec.rb +5 -8
  67. data/spec/integration/transition_spec.rb +17 -20
  68. data/spec/integration/user_spec.rb +24 -8
  69. data/spec/integration/version_spec.rb +21 -25
  70. data/spec/integration/watcher_spec.rb +62 -0
  71. data/spec/integration/webhook.rb +8 -17
  72. data/spec/integration/worklog_spec.rb +30 -34
  73. data/spec/jira/base_factory_spec.rb +11 -12
  74. data/spec/jira/base_spec.rb +216 -229
  75. data/spec/jira/client_spec.rb +227 -159
  76. data/spec/jira/has_many_proxy_spec.rb +11 -12
  77. data/spec/jira/http_client_spec.rb +254 -31
  78. data/spec/jira/http_error_spec.rb +7 -9
  79. data/spec/jira/jwt_uri_builder_spec.rb +59 -0
  80. data/spec/jira/oauth_client_spec.rb +110 -39
  81. data/spec/jira/request_client_spec.rb +36 -9
  82. data/spec/jira/resource/agile_spec.rb +135 -0
  83. data/spec/jira/resource/attachment_spec.rb +127 -9
  84. data/spec/jira/resource/board_spec.rb +224 -0
  85. data/spec/jira/resource/createmeta_spec.rb +29 -32
  86. data/spec/jira/resource/field_spec.rb +42 -48
  87. data/spec/jira/resource/filter_spec.rb +40 -40
  88. data/spec/jira/resource/issue_picker_suggestions_spec.rb +79 -0
  89. data/spec/jira/resource/issue_spec.rb +88 -85
  90. data/spec/jira/resource/issuelink_spec.rb +1 -1
  91. data/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +18 -0
  92. data/spec/jira/resource/project_factory_spec.rb +2 -4
  93. data/spec/jira/resource/project_spec.rb +33 -33
  94. data/spec/jira/resource/sprint_spec.rb +90 -0
  95. data/spec/jira/resource/user_factory_spec.rb +6 -8
  96. data/spec/jira/resource/worklog_spec.rb +9 -11
  97. data/spec/mock_responses/board/1.json +33 -0
  98. data/spec/mock_responses/board/1_issues.json +62 -0
  99. data/spec/mock_responses/empty_issues.json +8 -0
  100. data/spec/mock_responses/issue/10002/watchers.json +13 -0
  101. data/spec/mock_responses/issue.json +1 -1
  102. data/spec/mock_responses/sprint/1_issues.json +125 -0
  103. data/spec/spec_helper.rb +8 -9
  104. data/spec/support/clients_helper.rb +4 -4
  105. data/spec/support/shared_examples/integration.rb +60 -77
  106. metadata +115 -55
  107. data/.ruby-version +0 -1
  108. data/README.rdoc +0 -333
  109. /data/spec/mock_responses/{attachment → issue/10002/attachments}/10000.json +0 -0
@@ -0,0 +1,62 @@
1
+ {
2
+ "expand": "schema,names",
3
+ "startAt": 0,
4
+ "maxResults": 1000,
5
+ "total": 9,
6
+ "issues": [
7
+ {
8
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
9
+ "id": "10546",
10
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10546",
11
+ "key": "SBT-1"
12
+ },
13
+ {
14
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
15
+ "id": "10547",
16
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10547",
17
+ "key": "SBT-2"
18
+ },
19
+ {
20
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
21
+ "id": "10556",
22
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10556",
23
+ "key": "SBT-11"
24
+ },
25
+ {
26
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
27
+ "id": "10557",
28
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10557",
29
+ "key": "SBT-12"
30
+ },
31
+ {
32
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
33
+ "id": "10558",
34
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10558",
35
+ "key": "SBT-13"
36
+ },
37
+ {
38
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
39
+ "id": "10559",
40
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10559",
41
+ "key": "SBT-14"
42
+ },
43
+ {
44
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
45
+ "id": "10600",
46
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10600",
47
+ "key": "SBT-16"
48
+ },
49
+ {
50
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
51
+ "id": "10601",
52
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10601",
53
+ "key": "SBT-17"
54
+ },
55
+ {
56
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
57
+ "id": "10604",
58
+ "self": "https://jira.example.com/rest/agile/1.0/issue/10604",
59
+ "key": "SBT-19"
60
+ }
61
+ ]
62
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "expand": "schema,names",
3
+ "startAt": 11,
4
+ "maxResults": 1000,
5
+ "total": 0,
6
+ "issues": [
7
+ ]
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "self": "http://localhost:2990/jira/rest/api/2/issue/10002/watchers",
3
+ "isWatching": false,
4
+ "watchCount": 1,
5
+ "watchers": [
6
+ {
7
+ "self": "http://www.example.com/jira/rest/api/2/user?username=admin",
8
+ "name": "admin",
9
+ "displayName": "admin",
10
+ "active": false
11
+ }
12
+ ]
13
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "expand": "schema,names",
3
3
  "startAt": 0,
4
- "maxResults": 50,
4
+ "maxResults": 1000,
5
5
  "total": 11,
6
6
  "issues": [
7
7
  {
@@ -0,0 +1,125 @@
1
+ {
2
+ "expand": "schema,names",
3
+ "startAt": 0,
4
+ "maxResults": 50,
5
+ "total": 1,
6
+ "issues": [
7
+ {
8
+ "expand": "",
9
+ "id": "10001",
10
+ "self": "http://www.example.com/jira/rest/agile/1.0/board/92/issue/10001",
11
+ "key": "HSP-1",
12
+ "fields": {
13
+ "flagged": true,
14
+ "sprint": {
15
+ "id": 37,
16
+ "self": "http://www.example.com/jira/rest/agile/1.0/sprint/13",
17
+ "state": "future",
18
+ "name": "sprint 2"
19
+ },
20
+ "closedSprints": [
21
+ {
22
+ "id": 37,
23
+ "self": "http://www.example.com/jira/rest/agile/1.0/sprint/23",
24
+ "state": "closed",
25
+ "name": "sprint 1",
26
+ "startDate": "2015-04-11T15:22:00.000+10:00",
27
+ "endDate": "2015-04-20T01:22:00.000+10:00",
28
+ "completeDate": "2015-04-20T11:04:00.000+10:00"
29
+ }
30
+ ],
31
+ "description": "example bug report",
32
+ "project": {
33
+ "self": "http://www.example.com/jira/rest/api/2/project/EX",
34
+ "id": "10000",
35
+ "key": "EX",
36
+ "name": "Example",
37
+ "avatarUrls": {
38
+ "48x48": "http://www.example.com/jira/secure/projectavatar?size=large&pid=10000",
39
+ "24x24": "http://www.example.com/jira/secure/projectavatar?size=small&pid=10000",
40
+ "16x16": "http://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10000",
41
+ "32x32": "http://www.example.com/jira/secure/projectavatar?size=medium&pid=10000"
42
+ },
43
+ "projectCategory": {
44
+ "self": "http://www.example.com/jira/rest/api/2/projectCategory/10000",
45
+ "id": "10000",
46
+ "name": "FIRST",
47
+ "description": "First Project Category"
48
+ }
49
+ },
50
+ "comment": [
51
+ {
52
+ "self": "http://www.example.com/jira/rest/api/2/issue/10010/comment/10000",
53
+ "id": "10000",
54
+ "author": {
55
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
56
+ "name": "fred",
57
+ "displayName": "Fred F. User",
58
+ "active": false
59
+ },
60
+ "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
61
+ "updateAuthor": {
62
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
63
+ "name": "fred",
64
+ "displayName": "Fred F. User",
65
+ "active": false
66
+ },
67
+ "created": "2016-06-22T11:49:57.797+0200",
68
+ "updated": "2016-06-22T11:49:57.800+0200",
69
+ "visibility": {
70
+ "type": "role",
71
+ "value": "Administrators"
72
+ }
73
+ }
74
+ ],
75
+ "epic": {
76
+ "id": 37,
77
+ "self": "http://www.example.com/jira/rest/agile/1.0/epic/23",
78
+ "name": "epic 1",
79
+ "summary": "epic 1 summary",
80
+ "color": {
81
+ "key": "color_4"
82
+ },
83
+ "done": true
84
+ },
85
+ "worklog": [
86
+ {
87
+ "self": "http://www.example.com/jira/rest/api/2/issue/10010/worklog/10000",
88
+ "author": {
89
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
90
+ "name": "fred",
91
+ "displayName": "Fred F. User",
92
+ "active": false
93
+ },
94
+ "updateAuthor": {
95
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
96
+ "name": "fred",
97
+ "displayName": "Fred F. User",
98
+ "active": false
99
+ },
100
+ "comment": "I did some work here.",
101
+ "updated": "2016-06-22T11:49:57.804+0200",
102
+ "visibility": {
103
+ "type": "group",
104
+ "value": "jira-developers"
105
+ },
106
+ "started": "2016-06-22T11:49:57.804+0200",
107
+ "timeSpent": "3h 20m",
108
+ "timeSpentSeconds": 12000,
109
+ "id": "100028",
110
+ "issueId": "10002"
111
+ }
112
+ ],
113
+ "updated": 1,
114
+ "timetracking": {
115
+ "originalEstimate": "10m",
116
+ "remainingEstimate": "3m",
117
+ "timeSpent": "6m",
118
+ "originalEstimateSeconds": 600,
119
+ "remainingEstimateSeconds": 200,
120
+ "timeSpentSeconds": 400
121
+ }
122
+ }
123
+ }
124
+ ]
125
+ }
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,9 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require 'rubygems'
3
3
  require 'bundler/setup'
4
4
  require 'webmock/rspec'
5
- Dir["./spec/support/**/*.rb"].each {|f| require f}
5
+ require 'pry'
6
+
7
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
6
8
 
7
9
  require 'jira-ruby'
8
10
 
@@ -10,13 +12,10 @@ RSpec.configure do |config|
10
12
  config.extend ClientsHelper
11
13
  end
12
14
 
13
-
14
15
  def get_mock_response(file, value_if_file_not_found = false)
15
- begin
16
- file.sub!('?', '_') # we have to replace this character on Windows machine
17
- File.read(File.join(File.dirname(__FILE__), 'mock_responses/', file))
18
- rescue Errno::ENOENT => e
19
- raise e if value_if_file_not_found == false
20
- value_if_file_not_found
21
- end
16
+ file.sub!('?', '_') # we have to replace this character on Windows machine
17
+ File.read(File.join(File.dirname(__FILE__), 'mock_responses/', file))
18
+ rescue Errno::ENOENT => e
19
+ raise e if value_if_file_not_found == false
20
+ value_if_file_not_found
22
21
  end
@@ -2,12 +2,12 @@ module ClientsHelper
2
2
  def with_each_client
3
3
  clients = {}
4
4
 
5
- oauth_client = JIRA::Client.new({ :consumer_key => 'foo', :consumer_secret => 'bar' })
5
+ oauth_client = JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar')
6
6
  oauth_client.set_access_token('abc', '123')
7
- clients["http://localhost:2990"] = oauth_client
7
+ clients['http://localhost:2990'] = oauth_client
8
8
 
9
- basic_client = JIRA::Client.new({ :username => 'foo', :password => 'bar', :auth_type => :basic, :use_ssl => false })
10
- clients["http://foo:bar@localhost:2990"] = basic_client
9
+ basic_client = JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :basic, use_ssl: false)
10
+ clients['http://foo:bar@localhost:2990'] = basic_client
11
11
 
12
12
  clients.each do |site_url, client|
13
13
  yield site_url, client
@@ -1,43 +1,39 @@
1
1
  require 'cgi'
2
2
 
3
3
  def get_mock_from_path(method, options = {})
4
- if defined? belongs_to
5
- prefix = belongs_to.path_component + '/'
6
- else
7
- prefix = ''
8
- end
9
-
10
- if options[:url]
11
- url = options[:url]
12
- elsif options[:key]
13
- url = described_class.singular_path(client, options[:key], prefix)
14
- else
15
- url = described_class.collection_path(client, prefix)
16
- end
4
+ prefix = if defined? belongs_to
5
+ belongs_to.path_component + '/'
6
+ else
7
+ ''
8
+ end
9
+
10
+ url = if options[:url]
11
+ options[:url]
12
+ elsif options[:key]
13
+ described_class.singular_path(client, options[:key], prefix)
14
+ else
15
+ described_class.collection_path(client, prefix)
16
+ end
17
17
  file_path = url.sub(client.options[:rest_base_path], '')
18
18
  file_path = file_path + '.' + options[:suffix] if options[:suffix]
19
19
  file_path = file_path + '.' + method.to_s unless method == :get
20
- value_if_not_found = options.keys.include?(:value_if_not_found) ? options[:value_if_not_found] : false
20
+ value_if_not_found = options.key?(:value_if_not_found) ? options[:value_if_not_found] : false
21
21
  get_mock_response("#{file_path}.json", value_if_not_found)
22
22
  end
23
23
 
24
24
  def class_basename
25
- described_class.name.split('::').last
25
+ described_class.name.split('::').last
26
26
  end
27
27
 
28
28
  def options
29
29
  options = {}
30
- if defined? belongs_to
31
- options[belongs_to.to_sym] = belongs_to
32
- end
30
+ options[belongs_to.to_sym] = belongs_to if defined? belongs_to
33
31
  options
34
32
  end
35
33
 
36
34
  def prefix
37
35
  prefix = '/'
38
- if defined? belongs_to
39
- prefix = belongs_to.path_component + '/'
40
- end
36
+ prefix = belongs_to.path_component + '/' if defined? belongs_to
41
37
  prefix
42
38
  end
43
39
 
@@ -49,73 +45,66 @@ def build_receiver
49
45
  end
50
46
  end
51
47
 
52
- shared_examples "a resource" do
53
-
54
- it "gracefully handles non-json responses" do
48
+ shared_examples 'a resource' do
49
+ it 'gracefully handles non-json responses' do
55
50
  if defined? target
56
51
  subject = target
57
52
  else
58
53
  subject = client.send(class_basename).build(described_class.key_attribute.to_s => '99999')
59
54
  end
60
- stub_request(:put, site_url + subject.url).
61
- to_return(:status => 405, :body => "<html><body>Some HTML</body></html>")
55
+ stub_request(:put, site_url + subject.url)
56
+ .to_return(status: 405, body: '<html><body>Some HTML</body></html>')
62
57
  expect(subject.save('foo' => 'bar')).to be_falsey
63
58
  expect(lambda do
64
59
  expect(subject.save!('foo' => 'bar')).to be_falsey
65
60
  end).to raise_error(JIRA::HTTPError)
66
61
  end
67
-
68
62
  end
69
63
 
70
- shared_examples "a resource with a collection GET endpoint" do
71
-
72
- it "should get the collection" do
73
- stub_request(:get, site_url + described_class.collection_path(client)).
74
- to_return(:status => 200, :body => get_mock_from_path(:get))
64
+ shared_examples 'a resource with a collection GET endpoint' do
65
+ it 'should get the collection' do
66
+ stub_request(:get, site_url + described_class.collection_path(client))
67
+ .to_return(status: 200, body: get_mock_from_path(:get))
75
68
  collection = build_receiver.all
76
69
 
77
70
  expect(collection.length).to eq(expected_collection_length)
78
71
  expect(collection.first).to have_attributes(expected_attributes)
79
72
  end
80
-
81
73
  end
82
74
 
83
- shared_examples "a resource with JQL inputs and a collection GET endpoint" do
84
-
85
- it "should get the collection" do
75
+ shared_examples 'a resource with JQL inputs and a collection GET endpoint' do
76
+ it 'should get the collection' do
86
77
  stub_request(
87
78
  :get,
88
79
  site_url +
89
80
  client.options[:rest_base_path] +
90
81
  '/search?jql=' +
91
82
  CGI.escape(jql_query_string)
92
- ).to_return(:status => 200, :body => get_mock_response('issue.json'))
83
+ ).to_return(status: 200, body: get_mock_response('issue.json'))
93
84
 
94
85
  collection = build_receiver.jql(jql_query_string)
95
86
 
96
87
  expect(collection.length).to eq(expected_collection_length)
97
88
  expect(collection.first).to have_attributes(expected_attributes)
98
89
  end
99
-
100
90
  end
101
91
 
102
- shared_examples "a resource with a singular GET endpoint" do
103
-
104
- it "GETs a single resource" do
92
+ shared_examples 'a resource with a singular GET endpoint' do
93
+ it 'GETs a single resource' do
105
94
  # E.g., for JIRA::Resource::Project, we need to call
106
95
  # client.Project.find()
107
- stub_request(:get, site_url + described_class.singular_path(client, key, prefix)).
108
- to_return(:status => 200, :body => get_mock_from_path(:get, :key => key))
96
+ stub_request(:get, site_url + described_class.singular_path(client, key, prefix))
97
+ .to_return(status: 200, body: get_mock_from_path(:get, key: key))
109
98
  subject = client.send(class_basename).find(key, options)
110
99
 
111
100
  expect(subject).to have_attributes(expected_attributes)
112
101
  end
113
102
 
114
- it "builds and fetches a single resource" do
103
+ it 'builds and fetches a single resource' do
115
104
  # E.g., for JIRA::Resource::Project, we need to call
116
105
  # client.Project.build('key' => 'ABC123')
117
- stub_request(:get, site_url + described_class.singular_path(client, key, prefix)).
118
- to_return(:status => 200, :body => get_mock_from_path(:get, :key => key))
106
+ stub_request(:get, site_url + described_class.singular_path(client, key, prefix))
107
+ .to_return(status: 200, body: get_mock_from_path(:get, key: key))
119
108
 
120
109
  subject = build_receiver.build(described_class.key_attribute.to_s => key)
121
110
  subject.fetch
@@ -123,48 +112,45 @@ shared_examples "a resource with a singular GET endpoint" do
123
112
  expect(subject).to have_attributes(expected_attributes)
124
113
  end
125
114
 
126
- it "handles a 404" do
127
- stub_request(:get, site_url + described_class.singular_path(client, '99999', prefix)).
128
- to_return(:status => 404, :body => '{"errorMessages":["'+class_basename+' Does Not Exist"],"errors": {}}')
129
- expect( lambda do
115
+ it 'handles a 404' do
116
+ stub_request(:get, site_url + described_class.singular_path(client, '99999', prefix))
117
+ .to_return(status: 404, body: '{"errorMessages":["' + class_basename + ' Does Not Exist"],"errors": {}}')
118
+ expect(lambda do
130
119
  client.send(class_basename).find('99999', options)
131
120
  end).to raise_exception(JIRA::HTTPError)
132
121
  end
133
122
  end
134
123
 
135
- shared_examples "a resource with a DELETE endpoint" do
136
- it "deletes a resource" do
124
+ shared_examples 'a resource with a DELETE endpoint' do
125
+ it 'deletes a resource' do
137
126
  # E.g., for JIRA::Resource::Project, we need to call
138
127
  # client.Project.delete()
139
- stub_request(:delete, site_url + described_class.singular_path(client, key, prefix)).
140
- to_return(:status => 204, :body => nil)
128
+ stub_request(:delete, site_url + described_class.singular_path(client, key, prefix))
129
+ .to_return(status: 204, body: nil)
141
130
 
142
131
  subject = build_receiver.build(described_class.key_attribute.to_s => key)
143
132
  expect(subject.delete).to be_truthy
144
133
  end
145
134
  end
146
135
 
147
- shared_examples "a resource with a POST endpoint" do
148
-
149
- it "saves a new resource" do
150
- stub_request(:post, site_url + described_class.collection_path(client, prefix)).
151
- to_return(:status => 201, :body => get_mock_from_path(:post))
136
+ shared_examples 'a resource with a POST endpoint' do
137
+ it 'saves a new resource' do
138
+ stub_request(:post, site_url + described_class.collection_path(client, prefix))
139
+ .to_return(status: 201, body: get_mock_from_path(:post))
152
140
  subject = build_receiver.build
153
141
  expect(subject.save(attributes_for_post)).to be_truthy
154
142
  expected_attributes_from_post.each do |method_name, value|
155
143
  expect(subject.send(method_name)).to eq(value)
156
144
  end
157
145
  end
158
-
159
146
  end
160
147
 
161
- shared_examples "a resource with a PUT endpoint" do
162
-
163
- it "saves an existing component" do
164
- stub_request(:get, site_url + described_class.singular_path(client, key, prefix)).
165
- to_return(:status => 200, :body => get_mock_from_path(:get, :key =>key))
166
- stub_request(:put, site_url + described_class.singular_path(client, key, prefix)).
167
- to_return(:status => 200, :body => get_mock_from_path(:put, :key => key, :value_if_not_found => nil))
148
+ shared_examples 'a resource with a PUT endpoint' do
149
+ it 'saves an existing component' do
150
+ stub_request(:get, site_url + described_class.singular_path(client, key, prefix))
151
+ .to_return(status: 200, body: get_mock_from_path(:get, key: key))
152
+ stub_request(:put, site_url + described_class.singular_path(client, key, prefix))
153
+ .to_return(status: 200, body: get_mock_from_path(:put, key: key, value_if_not_found: nil))
168
154
  subject = build_receiver.build(described_class.key_attribute.to_s => key)
169
155
  subject.fetch
170
156
  expect(subject.save(attributes_for_put)).to be_truthy
@@ -172,23 +158,20 @@ shared_examples "a resource with a PUT endpoint" do
172
158
  expect(subject.send(method_name)).to eq(value)
173
159
  end
174
160
  end
175
-
176
161
  end
177
162
 
178
163
  shared_examples 'a resource with a PUT endpoint that rejects invalid fields' do
179
-
180
- it "fails to save with an invalid field" do
181
- stub_request(:get, site_url + described_class.singular_path(client, key)).
182
- to_return(:status => 200, :body => get_mock_from_path(:get, :key => key))
183
- stub_request(:put, site_url + described_class.singular_path(client, key)).
184
- to_return(:status => 400, :body => get_mock_from_path(:put, :key => key, :suffix => "invalid"))
164
+ it 'fails to save with an invalid field' do
165
+ stub_request(:get, site_url + described_class.singular_path(client, key))
166
+ .to_return(status: 200, body: get_mock_from_path(:get, key: key))
167
+ stub_request(:put, site_url + described_class.singular_path(client, key))
168
+ .to_return(status: 400, body: get_mock_from_path(:put, key: key, suffix: 'invalid'))
185
169
  subject = client.send(class_basename).build(described_class.key_attribute.to_s => key)
186
170
  subject.fetch
187
171
 
188
- expect(subject.save('fields'=> {'invalid' => 'field'})).to be_falsey
172
+ expect(subject.save('fields' => { 'invalid' => 'field' })).to be_falsey
189
173
  expect(lambda do
190
- subject.save!('fields'=> {'invalid' => 'field'})
174
+ subject.save!('fields' => { 'invalid' => 'field' })
191
175
  end).to raise_error(JIRA::HTTPError)
192
176
  end
193
-
194
177
  end