sclemmer-jira-ruby 0.1.12

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 (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +46 -0
  6. data/README.rdoc +309 -0
  7. data/Rakefile +28 -0
  8. data/example.rb +119 -0
  9. data/http-basic-example.rb +112 -0
  10. data/lib/jira.rb +33 -0
  11. data/lib/jira/base.rb +497 -0
  12. data/lib/jira/base_factory.rb +49 -0
  13. data/lib/jira/client.rb +165 -0
  14. data/lib/jira/has_many_proxy.rb +43 -0
  15. data/lib/jira/http_client.rb +69 -0
  16. data/lib/jira/http_error.rb +16 -0
  17. data/lib/jira/oauth_client.rb +84 -0
  18. data/lib/jira/railtie.rb +10 -0
  19. data/lib/jira/request_client.rb +18 -0
  20. data/lib/jira/resource/attachment.rb +12 -0
  21. data/lib/jira/resource/comment.rb +14 -0
  22. data/lib/jira/resource/component.rb +10 -0
  23. data/lib/jira/resource/field.rb +10 -0
  24. data/lib/jira/resource/filter.rb +15 -0
  25. data/lib/jira/resource/issue.rb +80 -0
  26. data/lib/jira/resource/issuetype.rb +10 -0
  27. data/lib/jira/resource/priority.rb +10 -0
  28. data/lib/jira/resource/project.rb +31 -0
  29. data/lib/jira/resource/status.rb +10 -0
  30. data/lib/jira/resource/transition.rb +33 -0
  31. data/lib/jira/resource/user.rb +14 -0
  32. data/lib/jira/resource/version.rb +10 -0
  33. data/lib/jira/resource/worklog.rb +16 -0
  34. data/lib/jira/tasks.rb +0 -0
  35. data/lib/jira/version.rb +3 -0
  36. data/lib/tasks/generate.rake +18 -0
  37. data/sclemmer-jira-ruby.gemspec +28 -0
  38. data/spec/integration/attachment_spec.rb +23 -0
  39. data/spec/integration/comment_spec.rb +55 -0
  40. data/spec/integration/component_spec.rb +42 -0
  41. data/spec/integration/field_spec.rb +35 -0
  42. data/spec/integration/issue_spec.rb +94 -0
  43. data/spec/integration/issuetype_spec.rb +26 -0
  44. data/spec/integration/priority_spec.rb +27 -0
  45. data/spec/integration/project_spec.rb +56 -0
  46. data/spec/integration/status_spec.rb +27 -0
  47. data/spec/integration/transition_spec.rb +52 -0
  48. data/spec/integration/user_spec.rb +25 -0
  49. data/spec/integration/version_spec.rb +43 -0
  50. data/spec/integration/worklog_spec.rb +55 -0
  51. data/spec/jira/base_factory_spec.rb +46 -0
  52. data/spec/jira/base_spec.rb +583 -0
  53. data/spec/jira/client_spec.rb +188 -0
  54. data/spec/jira/has_many_proxy_spec.rb +47 -0
  55. data/spec/jira/http_client_spec.rb +109 -0
  56. data/spec/jira/http_error_spec.rb +26 -0
  57. data/spec/jira/oauth_client_spec.rb +111 -0
  58. data/spec/jira/request_client_spec.rb +14 -0
  59. data/spec/jira/resource/attachment_spec.rb +20 -0
  60. data/spec/jira/resource/filter_spec.rb +97 -0
  61. data/spec/jira/resource/issue_spec.rb +123 -0
  62. data/spec/jira/resource/project_factory_spec.rb +13 -0
  63. data/spec/jira/resource/project_spec.rb +70 -0
  64. data/spec/jira/resource/worklog_spec.rb +24 -0
  65. data/spec/mock_responses/attachment/10000.json +20 -0
  66. data/spec/mock_responses/component.post.json +28 -0
  67. data/spec/mock_responses/component/10000.invalid.put.json +5 -0
  68. data/spec/mock_responses/component/10000.json +39 -0
  69. data/spec/mock_responses/component/10000.put.json +39 -0
  70. data/spec/mock_responses/field.json +32 -0
  71. data/spec/mock_responses/field/1.json +15 -0
  72. data/spec/mock_responses/issue.json +1108 -0
  73. data/spec/mock_responses/issue.post.json +5 -0
  74. data/spec/mock_responses/issue/10002.invalid.put.json +6 -0
  75. data/spec/mock_responses/issue/10002.json +126 -0
  76. data/spec/mock_responses/issue/10002.put.missing_field_update.json +6 -0
  77. data/spec/mock_responses/issue/10002/comment.json +65 -0
  78. data/spec/mock_responses/issue/10002/comment.post.json +29 -0
  79. data/spec/mock_responses/issue/10002/comment/10000.json +29 -0
  80. data/spec/mock_responses/issue/10002/comment/10000.put.json +29 -0
  81. data/spec/mock_responses/issue/10002/transitions.json +49 -0
  82. data/spec/mock_responses/issue/10002/transitions.post.json +1 -0
  83. data/spec/mock_responses/issue/10002/worklog.json +98 -0
  84. data/spec/mock_responses/issue/10002/worklog.post.json +30 -0
  85. data/spec/mock_responses/issue/10002/worklog/10000.json +31 -0
  86. data/spec/mock_responses/issue/10002/worklog/10000.put.json +30 -0
  87. data/spec/mock_responses/issuetype.json +42 -0
  88. data/spec/mock_responses/issuetype/5.json +8 -0
  89. data/spec/mock_responses/priority.json +42 -0
  90. data/spec/mock_responses/priority/1.json +8 -0
  91. data/spec/mock_responses/project.json +12 -0
  92. data/spec/mock_responses/project/SAMPLEPROJECT.issues.json +1108 -0
  93. data/spec/mock_responses/project/SAMPLEPROJECT.json +84 -0
  94. data/spec/mock_responses/status.json +37 -0
  95. data/spec/mock_responses/status/1.json +7 -0
  96. data/spec/mock_responses/user_username=admin.json +17 -0
  97. data/spec/mock_responses/version.post.json +7 -0
  98. data/spec/mock_responses/version/10000.invalid.put.json +5 -0
  99. data/spec/mock_responses/version/10000.json +11 -0
  100. data/spec/mock_responses/version/10000.put.json +7 -0
  101. data/spec/spec_helper.rb +22 -0
  102. data/spec/support/clients_helper.rb +16 -0
  103. data/spec/support/matchers/have_attributes.rb +11 -0
  104. data/spec/support/matchers/have_many.rb +9 -0
  105. data/spec/support/matchers/have_one.rb +5 -0
  106. data/spec/support/shared_examples/integration.rb +194 -0
  107. metadata +302 -0
@@ -0,0 +1,188 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Client do
4
+
5
+ let(:oauth_client) do
6
+ JIRA::Client.new({ :consumer_key => 'foo', :consumer_secret => 'bar' })
7
+ end
8
+
9
+ let(:basic_client) do
10
+ JIRA::Client.new({ :username => 'foo', :password => 'bar', :auth_type => :basic })
11
+ end
12
+
13
+ let(:clients) { [oauth_client, basic_client] }
14
+
15
+ let(:response) do
16
+ response = double("response")
17
+ allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
18
+ response
19
+ end
20
+
21
+ let(:headers) { {'Accept' => 'application/json'} }
22
+ let(:content_type_header) { {'Content-Type' => 'application/json'} }
23
+ let(:merged_headers) { headers.merge(content_type_header) }
24
+
25
+ it "creates an instance" do
26
+ clients.each {|client| expect(client.class).to eq(JIRA::Client) }
27
+ end
28
+
29
+ it "allows the overriding of some options" do
30
+ client = JIRA::Client.new({:consumer_key => 'foo', :consumer_secret => 'bar', :site => 'http://foo.com/'})
31
+ expect(client.options[:site]).to eq('http://foo.com/')
32
+ expect(JIRA::Client::DEFAULT_OPTIONS[:site]).not_to eq('http://foo.com/')
33
+ end
34
+
35
+ it "prepends the context path to the rest base path" do
36
+ options = [:rest_base_path]
37
+ defaults = JIRA::Client::DEFAULT_OPTIONS
38
+ options.each do |key|
39
+ clients.each { |client| expect(client.options[key]).to eq(defaults[:context_path] + defaults[key]) }
40
+ end
41
+ end
42
+
43
+ # To avoid having to validate options after initialisation, e.g. setting
44
+ # client.options[:invalid] = 'foo'
45
+ it "freezes the options" do
46
+ clients.each { |client| expect(client.options).to be_frozen }
47
+ end
48
+
49
+ it "merges headers" do
50
+ clients.each { |client| expect(client.send(:merge_default_headers, {})).to eq({'Accept' => 'application/json'}) }
51
+ end
52
+
53
+ describe "creates instances of request clients" do
54
+ specify "that are of the correct class" do
55
+ expect(oauth_client.request_client.class).to eq(JIRA::OauthClient)
56
+ expect(basic_client.request_client.class).to eq(JIRA::HttpClient)
57
+ end
58
+
59
+ specify "which have a corresponding auth type option" do
60
+ expect(oauth_client.options[:auth_type]).to eq(:oauth)
61
+ expect(basic_client.options[:auth_type]).to eq(:basic)
62
+ end
63
+
64
+ describe "like oauth" do
65
+
66
+ it "allows setting an access token" do
67
+ token = double()
68
+ expect(OAuth::AccessToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
69
+ access_token = oauth_client.set_access_token('foo', 'bar')
70
+
71
+ expect(access_token).to eq(token)
72
+ expect(oauth_client.access_token).to eq(token)
73
+ end
74
+
75
+ it "allows initializing the access token" do
76
+ request_token = OAuth::RequestToken.new(oauth_client.consumer)
77
+ allow(oauth_client.consumer).to receive(:get_request_token).and_return(request_token)
78
+ mock_access_token = double()
79
+ expect(request_token).to receive(:get_access_token).with(:oauth_verifier => 'abc123').and_return(mock_access_token)
80
+ oauth_client.init_access_token(:oauth_verifier => 'abc123')
81
+ expect(oauth_client.access_token).to eq(mock_access_token)
82
+ end
83
+
84
+ specify "that has specific default options" do
85
+ options = [:signature_method, :private_key_file]
86
+ options.each do |key|
87
+ expect(oauth_client.options[key]).to eq(JIRA::Client::DEFAULT_OPTIONS[key])
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "like basic http" do
93
+ it "sets the username and password" do
94
+ expect(basic_client.options[:username]).to eq('foo')
95
+ expect(basic_client.options[:password]).to eq('bar')
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "has http methods" do
101
+ before do
102
+ oauth_client.set_access_token("foo", "bar")
103
+ end
104
+
105
+ specify "that merge default headers" do
106
+ # stubbed response for generic client request method
107
+ expect(oauth_client).to receive(:request).exactly(5).times.and_return(response)
108
+ expect(basic_client).to receive(:request).exactly(5).times.and_return(response)
109
+
110
+ # response for merging headers for http methods with no body
111
+ expect(oauth_client).to receive(:merge_default_headers).exactly(3).times.with({})
112
+ expect(basic_client).to receive(:merge_default_headers).exactly(3).times.with({})
113
+
114
+ # response for merging headers for http methods with body
115
+ expect(oauth_client).to receive(:merge_default_headers).exactly(2).times.with(content_type_header)
116
+ expect(basic_client).to receive(:merge_default_headers).exactly(2).times.with(content_type_header)
117
+
118
+ [:delete, :get, :head].each do |method|
119
+ oauth_client.send(method, '/path', {})
120
+ basic_client.send(method, '/path', {})
121
+ end
122
+
123
+ [:post, :put].each do |method|
124
+ oauth_client.send(method, '/path', '', content_type_header)
125
+ basic_client.send(method, '/path', '', content_type_header)
126
+ end
127
+ end
128
+
129
+ specify "that call the generic request method" do
130
+ [:delete, :get, :head].each do |method|
131
+ expect(oauth_client).to receive(:request).with(method, '/path', nil, headers).and_return(response)
132
+ expect(basic_client).to receive(:request).with(method, '/path', nil, headers).and_return(response)
133
+ oauth_client.send(method, '/path', {})
134
+ basic_client.send(method, '/path', {})
135
+ end
136
+
137
+ [:post, :put].each do |method|
138
+ expect(oauth_client).to receive(:request).with(method, '/path', '', merged_headers)
139
+ expect(basic_client).to receive(:request).with(method, '/path', '', merged_headers)
140
+ oauth_client.send(method, '/path', '', {})
141
+ basic_client.send(method, '/path', '', {})
142
+ end
143
+ end
144
+
145
+ describe "that call a oauth client" do
146
+ specify "which makes a request" do
147
+ [:delete, :get, :head].each do |method|
148
+ expect(oauth_client.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(response)
149
+ oauth_client.send(method, '/path', {})
150
+ end
151
+ [:post, :put].each do |method|
152
+ expect(oauth_client.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(response)
153
+ oauth_client.send(method, '/path', '', {})
154
+ end
155
+ end
156
+ end
157
+
158
+ describe "that call a http client" do
159
+ it "which makes a request" do
160
+ [:delete, :get, :head].each do |method|
161
+ expect(basic_client.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(response)
162
+ basic_client.send(method, '/path', headers)
163
+ end
164
+ [:post, :put].each do |method|
165
+ expect(basic_client.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(response)
166
+ basic_client.send(method, '/path', '', headers)
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ describe "Resource Factories" do
173
+ it "gets all projects" do
174
+ expect(JIRA::Resource::Project).to receive(:all).with(oauth_client).and_return([])
175
+ expect(JIRA::Resource::Project).to receive(:all).with(basic_client).and_return([])
176
+ expect(oauth_client.Project.all).to eq([])
177
+ expect(basic_client.Project.all).to eq([])
178
+ end
179
+
180
+ it "finds a single project" do
181
+ find_result = double()
182
+ expect(JIRA::Resource::Project).to receive(:find).with(oauth_client, '123').and_return(find_result)
183
+ expect(JIRA::Resource::Project).to receive(:find).with(basic_client, '123').and_return(find_result)
184
+ expect(oauth_client.Project.find('123')).to eq(find_result)
185
+ expect(basic_client.Project.find('123')).to eq(find_result)
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::HasManyProxy do
4
+
5
+ class Foo ; end
6
+
7
+ subject { JIRA::HasManyProxy.new(parent, Foo, collection) }
8
+
9
+ let(:parent) { double("parent") }
10
+ let(:collection) { double("collection") }
11
+
12
+ it "has a target class" do
13
+ expect(subject.target_class).to eq(Foo)
14
+ end
15
+
16
+ it "has a parent" do
17
+ expect(subject.parent).to eq(parent)
18
+ end
19
+
20
+ it "has a collection" do
21
+ expect(subject.collection).to eq(collection)
22
+ end
23
+
24
+ it "can build a new instance" do
25
+ client = double('client')
26
+ foo = double('foo')
27
+ allow(parent).to receive(:client).and_return(client)
28
+ allow(parent).to receive(:to_sym).and_return(:parent)
29
+ expect(Foo).to receive(:new).with(client, :attrs => {'foo' => 'bar'}, :parent => parent).and_return(foo)
30
+ expect(collection).to receive(:<<).with(foo)
31
+ expect(subject.build('foo' => 'bar')).to eq(foo)
32
+ end
33
+
34
+ it "can get all the instances" do
35
+ foo = double('foo')
36
+ client = double('client')
37
+ allow(parent).to receive(:client).and_return(client)
38
+ allow(parent).to receive(:to_sym).and_return(:parent)
39
+ expect(Foo).to receive(:all).with(client, :parent => parent).and_return(foo)
40
+ expect(subject.all).to eq(foo)
41
+ end
42
+
43
+ it "delegates missing methods to the collection" do
44
+ expect(collection).to receive(:missing_method)
45
+ subject.missing_method
46
+ end
47
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::HttpClient do
4
+
5
+ let(:basic_client) do
6
+ options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS)
7
+ JIRA::HttpClient.new(options)
8
+ end
9
+
10
+ let(:basic_cookie_client) do
11
+ options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(:use_cookies => true)
12
+ JIRA::HttpClient.new(options)
13
+ end
14
+
15
+ let(:response) do
16
+ response = double("response")
17
+ allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
18
+ response
19
+ end
20
+
21
+ let(:cookie_response) do
22
+ response = double("response")
23
+ allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
24
+ response
25
+ end
26
+
27
+ it "creates an instance of Net:HTTP for a basic auth client" do
28
+ expect(basic_client.basic_auth_http_conn.class).to eq(Net::HTTP)
29
+ end
30
+
31
+ it "responds to the http methods" do
32
+ body = ''
33
+ headers = double()
34
+ basic_auth_http_conn = double()
35
+ request = double()
36
+ allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
37
+ expect(request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).exactly(5).times.and_return(request)
38
+ expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(response)
39
+ [:delete, :get, :head].each do |method|
40
+ expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
41
+ expect(basic_client.make_request(method, '/path', nil, headers)).to eq(response)
42
+ end
43
+ [:post, :put].each do |method|
44
+ expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
45
+ expect(request).to receive(:body=).with(body).and_return(request)
46
+ expect(basic_client.make_request(method, '/path', body, headers)).to eq(response)
47
+ end
48
+ end
49
+
50
+ it "gets and sets cookies" do
51
+ body = ''
52
+ headers = double()
53
+ basic_auth_http_conn = double()
54
+ request = double()
55
+ allow(basic_cookie_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
56
+ expect(request).to receive(:basic_auth).with(basic_cookie_client.options[:username], basic_cookie_client.options[:password]).exactly(5).times.and_return(request)
57
+ expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times
58
+ expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response)
59
+ [:delete, :get, :head].each do |method|
60
+ expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
61
+ expect(basic_cookie_client.make_request(method, '/path', nil, headers)).to eq(cookie_response)
62
+ end
63
+ [:post, :put].each do |method|
64
+ expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
65
+ expect(request).to receive(:body=).with(body).and_return(request)
66
+ expect(basic_cookie_client.make_request(method, '/path', body, headers)).to eq(cookie_response)
67
+ end
68
+ end
69
+
70
+
71
+ it "performs a basic http client request" do
72
+ body = nil
73
+ headers = double()
74
+ basic_auth_http_conn = double()
75
+ http_request = double()
76
+ expect(Net::HTTP::Get).to receive(:new).with('/foo', headers).and_return(http_request)
77
+
78
+ expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response)
79
+ expect(http_request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).and_return(http_request)
80
+ allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
81
+ basic_client.make_request(:get, '/foo', body, headers)
82
+ end
83
+
84
+ it "returns a URI" do
85
+ uri = URI.parse(basic_client.options[:site])
86
+ expect(basic_client.uri).to eq(uri)
87
+ end
88
+
89
+ it "sets up a http connection with options" do
90
+ http_conn = double()
91
+ uri = double()
92
+ host = double()
93
+ port = double()
94
+ expect(uri).to receive(:host).and_return(host)
95
+ expect(uri).to receive(:port).and_return(port)
96
+ expect(Net::HTTP).to receive(:new).with(host, port).and_return(http_conn)
97
+ expect(http_conn).to receive(:use_ssl=).with(basic_client.options[:use_ssl]).and_return(http_conn)
98
+ expect(http_conn).to receive(:verify_mode=).with(basic_client.options[:ssl_verify_mode]).and_return(http_conn)
99
+ expect(basic_client.http_conn(uri)).to eq(http_conn)
100
+ end
101
+
102
+ it "returns a http connection" do
103
+ http_conn = double()
104
+ uri = double()
105
+ expect(basic_client).to receive(:uri).and_return(uri)
106
+ expect(basic_client).to receive(:http_conn).and_return(http_conn)
107
+ expect(basic_client.basic_auth_http_conn).to eq(http_conn)
108
+ end
109
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::HTTPError do
4
+
5
+ let(:response) {
6
+ response = double("response")
7
+ allow(response).to receive(:code).and_return(401)
8
+ allow(response).to receive(:message).and_return("A MESSAGE WOO")
9
+ response
10
+ }
11
+
12
+ subject { described_class.new(response) }
13
+
14
+ it "takes the response object as an argument" do
15
+ expect(subject.response).to eq(response)
16
+ end
17
+
18
+ it "has a code method" do
19
+ expect(subject.code).to eq(response.code)
20
+ end
21
+
22
+ it "returns code and class from message" do
23
+ expect(subject.message).to eq(response.message)
24
+ end
25
+
26
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::OauthClient do
4
+
5
+ let(:oauth_client) do
6
+ options = { :consumer_key => 'foo', :consumer_secret => 'bar' }
7
+ options = JIRA::Client::DEFAULT_OPTIONS.merge(options)
8
+ JIRA::OauthClient.new(options)
9
+ end
10
+
11
+ let(:response) do
12
+ response = double("response")
13
+ allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
14
+ response
15
+ end
16
+
17
+ describe "authenticating with oauth" do
18
+ it "prepends the context path to all authorization and rest paths" do
19
+ options = [:request_token_path, :authorize_path, :access_token_path]
20
+ defaults = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::OauthClient::DEFAULT_OPTIONS)
21
+ options.each do |key|
22
+ expect(oauth_client.options[key]).to eq(defaults[:context_path] + defaults[key])
23
+ end
24
+ end
25
+
26
+ it "creates a Oauth::Consumer on initialize" do
27
+ expect(oauth_client.consumer.class).to eq(OAuth::Consumer)
28
+ expect(oauth_client.consumer.key).to eq(oauth_client.key)
29
+ expect(oauth_client.consumer.secret).to eq(oauth_client.secret)
30
+ end
31
+
32
+ it "returns an OAuth request_token" do
33
+ # Cannot just check for method delegation as http connection will be attempted
34
+ request_token = OAuth::RequestToken.new(oauth_client.consumer)
35
+ allow(oauth_client).to receive(:get_request_token).and_return(request_token)
36
+ expect(oauth_client.get_request_token).to eq(request_token)
37
+ end
38
+
39
+ it "allows setting the request token" do
40
+ token = double()
41
+ expect(OAuth::RequestToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
42
+
43
+ request_token = oauth_client.set_request_token('foo', 'bar')
44
+
45
+ expect(request_token).to eq(token)
46
+ expect(oauth_client.request_token).to eq(token)
47
+ end
48
+
49
+ it "allows setting the consumer key" do
50
+ expect(oauth_client.key).to eq('foo')
51
+ end
52
+
53
+ it "allows setting the consumer secret" do
54
+ expect(oauth_client.secret).to eq('bar')
55
+ end
56
+
57
+ describe "the access token" do
58
+
59
+ it "initializes" do
60
+ request_token = OAuth::RequestToken.new(oauth_client.consumer)
61
+ allow(oauth_client).to receive(:get_request_token).and_return(request_token)
62
+ mock_access_token = double()
63
+ expect(request_token).to receive(:get_access_token).with(:oauth_verifier => 'abc123').and_return(mock_access_token)
64
+ oauth_client.init_access_token(:oauth_verifier => 'abc123')
65
+ expect(oauth_client.access_token).to eq(mock_access_token)
66
+ end
67
+
68
+ it "raises an exception when accessing without initialisation" do
69
+ expect {
70
+ oauth_client.access_token
71
+ }.to raise_exception(JIRA::OauthClient::UninitializedAccessTokenError,
72
+ "init_access_token must be called before using the client")
73
+ end
74
+
75
+ it "allows setting the access token" do
76
+ token = double()
77
+ expect(OAuth::AccessToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
78
+
79
+ access_token = oauth_client.set_access_token('foo', 'bar')
80
+
81
+ expect(access_token).to eq(token)
82
+ expect(oauth_client.access_token).to eq(token)
83
+ end
84
+ end
85
+
86
+ describe "http" do
87
+ it "responds to the http methods" do
88
+ headers = double()
89
+ mock_access_token = double()
90
+ allow(oauth_client).to receive(:access_token).and_return(mock_access_token)
91
+ [:delete, :get, :head].each do |method|
92
+ expect(mock_access_token).to receive(method).with('/path', headers).and_return(response)
93
+ oauth_client.make_request(method, '/path', '', headers)
94
+ end
95
+ [:post, :put].each do |method|
96
+ expect(mock_access_token).to receive(method).with('/path', '', headers).and_return(response)
97
+ oauth_client.make_request(method, '/path', '', headers)
98
+ end
99
+ end
100
+
101
+ it "performs a request" do
102
+ body = nil
103
+ headers = double()
104
+ access_token = double()
105
+ expect(access_token).to receive(:send).with(:get, '/foo', headers).and_return(response)
106
+ allow(oauth_client).to receive(:access_token).and_return(access_token)
107
+ oauth_client.request(:get, '/foo', body, headers)
108
+ end
109
+ end
110
+ end
111
+ end