ashikawa-core 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +1 -3
- data/README.md +7 -3
- data/Rakefile +1 -0
- data/ashikawa-core.gemspec +9 -11
- data/config/reek.yml +5 -5
- data/lib/ashikawa-core/collection.rb +4 -0
- data/lib/ashikawa-core/configuration.rb +13 -1
- data/lib/ashikawa-core/connection.rb +34 -52
- data/lib/ashikawa-core/database.rb +9 -5
- data/lib/ashikawa-core/document.rb +6 -6
- data/lib/ashikawa-core/faraday_factory.rb +89 -0
- data/lib/ashikawa-core/minimal_logger.rb +64 -0
- data/lib/ashikawa-core/version.rb +1 -1
- data/log/.gitkeep +0 -0
- data/spec/acceptance/basic_spec.rb +2 -2
- data/spec/acceptance/index_spec.rb +5 -0
- data/spec/acceptance/spec_helper.rb +37 -22
- data/spec/unit/collection_spec.rb +34 -33
- data/spec/unit/configuration_spec.rb +8 -8
- data/spec/unit/connection_spec.rb +28 -48
- data/spec/unit/cursor_spec.rb +5 -4
- data/spec/unit/database_spec.rb +8 -16
- data/spec/unit/document_spec.rb +11 -10
- data/spec/unit/edge_spec.rb +12 -11
- data/spec/unit/exception_spec.rb +2 -2
- data/spec/unit/faraday_factory_spec.rb +51 -0
- data/spec/unit/figure_spec.rb +11 -11
- data/spec/unit/index_spec.rb +7 -6
- data/spec/unit/key_options_spec.rb +12 -15
- data/spec/unit/minimal_logger_spec.rb +55 -0
- data/spec/unit/query_spec.rb +53 -53
- data/spec/unit/spec_helper.rb +1 -0
- data/spec/unit/transaction_spec.rb +12 -14
- metadata +44 -53
- data/spec/fixtures/collections/60768679-figures.json +0 -35
@@ -3,12 +3,12 @@ require 'unit/spec_helper'
|
|
3
3
|
require 'ashikawa-core/configuration'
|
4
4
|
|
5
5
|
describe Ashikawa::Core::Configuration do
|
6
|
-
let(:url) {
|
7
|
-
let(:logger) {
|
8
|
-
let(:adapter) { double }
|
9
|
-
let(:connection) {
|
10
|
-
let(:username) {
|
11
|
-
let(:password) {
|
6
|
+
let(:url) { 'http://localhost:8530' }
|
7
|
+
let(:logger) { instance_double('Logger') }
|
8
|
+
let(:adapter) { double('Adapter') }
|
9
|
+
let(:connection) { instance_double('Ashikawa::Core::Connection') }
|
10
|
+
let(:username) { 'jeff' }
|
11
|
+
let(:password) { 'bowling!' }
|
12
12
|
|
13
13
|
its(:url) { should be_nil }
|
14
14
|
its(:logger) { should be_nil }
|
@@ -38,7 +38,7 @@ describe Ashikawa::Core::Configuration do
|
|
38
38
|
|
39
39
|
it 'should construct a connection' do
|
40
40
|
expect(Ashikawa::Core::Connection).to receive(:new)
|
41
|
-
.with(url, { logger: logger, adapter: adapter })
|
41
|
+
.with(url, '_system', { logger: logger, adapter: adapter })
|
42
42
|
.and_return(connection)
|
43
43
|
expect(subject.connection).to be connection
|
44
44
|
end
|
@@ -55,7 +55,7 @@ describe Ashikawa::Core::Configuration do
|
|
55
55
|
|
56
56
|
it 'should construct a connection' do
|
57
57
|
expect(Ashikawa::Core::Connection).to receive(:new)
|
58
|
-
.with(url, {})
|
58
|
+
.with(url, '_system', {})
|
59
59
|
.and_return(connection)
|
60
60
|
expect(subject.connection).to be connection
|
61
61
|
end
|
@@ -5,14 +5,24 @@ require 'ashikawa-core/connection'
|
|
5
5
|
describe Ashikawa::Core::Connection do
|
6
6
|
let(:request_stub) { Faraday::Adapter::Test::Stubs.new }
|
7
7
|
let(:response_headers) { { 'content-type' => 'application/json; charset=utf-8' } }
|
8
|
-
|
8
|
+
let(:options) { instance_double('Hash') }
|
9
|
+
subject { Ashikawa::Core::Connection.new(ARANGO_HOST, '_system', adapter: [:test, request_stub]) }
|
9
10
|
|
10
11
|
its(:scheme) { should eq('http') }
|
11
12
|
its(:host) { should eq('localhost') }
|
12
13
|
its(:port) { should eq(8529) }
|
13
14
|
|
15
|
+
describe 'initialization' do
|
16
|
+
it 'should create the Faraday connection using FaradayFactory' do
|
17
|
+
options = double('Options')
|
18
|
+
expect(Ashikawa::Core::FaradayFactory).to receive(:create_connection)
|
19
|
+
.with('http://localhost:8529/_db/my_db/_api', options)
|
20
|
+
Ashikawa::Core::Connection.new('http://localhost:8529', 'my_db', options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
14
24
|
it 'should send a get request' do
|
15
|
-
request_stub.get('/_api/my/path') do
|
25
|
+
request_stub.get('/_db/_system/_api/my/path') do
|
16
26
|
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
17
27
|
end
|
18
28
|
|
@@ -22,7 +32,7 @@ describe Ashikawa::Core::Connection do
|
|
22
32
|
end
|
23
33
|
|
24
34
|
it 'should send a post request' do
|
25
|
-
request_stub.post('/_api/my/path') do |request|
|
35
|
+
request_stub.post('/_db/_system/_api/my/path') do |request|
|
26
36
|
expect(request[:body]).to eq("{\"name\":\"new_collection\"}")
|
27
37
|
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
28
38
|
end
|
@@ -32,7 +42,7 @@ describe Ashikawa::Core::Connection do
|
|
32
42
|
end
|
33
43
|
|
34
44
|
it 'should send a put request' do
|
35
|
-
request_stub.put('/_api/my/path') do |request|
|
45
|
+
request_stub.put('/_db/_system/_api/my/path') do |request|
|
36
46
|
expect(request[:body]).to eq('{"name":"new_collection"}')
|
37
47
|
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
38
48
|
end
|
@@ -42,7 +52,7 @@ describe Ashikawa::Core::Connection do
|
|
42
52
|
end
|
43
53
|
|
44
54
|
it 'should send a delete request' do
|
45
|
-
request_stub.delete('/_api/my/path') do |_|
|
55
|
+
request_stub.delete('/_db/_system/_api/my/path') do |_|
|
46
56
|
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
47
57
|
end
|
48
58
|
|
@@ -53,12 +63,11 @@ describe Ashikawa::Core::Connection do
|
|
53
63
|
context 'with database suffix' do
|
54
64
|
let(:database_name) { 'ashikawa' }
|
55
65
|
subject do
|
56
|
-
Ashikawa::Core::Connection.new(
|
66
|
+
Ashikawa::Core::Connection.new(ARANGO_HOST, database_name, adapter: [:test, request_stub])
|
57
67
|
end
|
58
68
|
|
59
69
|
its(:database_name) { should eq database_name }
|
60
70
|
|
61
|
-
let(:options) { double('Options') }
|
62
71
|
it 'should be able to send a request without database suffix' do
|
63
72
|
expect(subject).to receive(:send_request)
|
64
73
|
.with("#{ARANGO_HOST}/_api/some_endpoint", options)
|
@@ -69,11 +78,10 @@ describe Ashikawa::Core::Connection do
|
|
69
78
|
|
70
79
|
context 'without database suffix' do
|
71
80
|
subject do
|
72
|
-
Ashikawa::Core::Connection.new(ARANGO_HOST, adapter: [:test, request_stub])
|
81
|
+
Ashikawa::Core::Connection.new(ARANGO_HOST, '_system', adapter: [:test, request_stub])
|
73
82
|
end
|
74
83
|
|
75
84
|
its(:database_name) { should eq '_system' }
|
76
|
-
let(:options) { double('Options') }
|
77
85
|
it 'should be able to send a request without database suffix' do
|
78
86
|
expect(subject).to receive(:send_request)
|
79
87
|
.with("#{ARANGO_HOST}/_api/some_endpoint", options)
|
@@ -95,7 +103,7 @@ describe Ashikawa::Core::Connection do
|
|
95
103
|
it 'should send the authentication data with every GET request' do
|
96
104
|
skip 'Find out how to check for basic auth via Faraday Stubs'
|
97
105
|
|
98
|
-
request_stub.get('/_api/my/path') do |_|
|
106
|
+
request_stub.get('/_db/_system/_api/my/path') do |_|
|
99
107
|
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
100
108
|
end
|
101
109
|
|
@@ -111,7 +119,8 @@ describe Ashikawa::Core::Connection do
|
|
111
119
|
let(:error_num) { 15 }
|
112
120
|
|
113
121
|
it "should throw a general client error for I'm a teapot" do
|
114
|
-
|
122
|
+
|
123
|
+
request_stub.get('/_db/_system/_api/bad/request') do
|
115
124
|
[
|
116
125
|
418,
|
117
126
|
response_headers,
|
@@ -127,7 +136,7 @@ describe Ashikawa::Core::Connection do
|
|
127
136
|
end
|
128
137
|
|
129
138
|
it 'should throw its own exception when doing a bad request' do
|
130
|
-
request_stub.get('/_api/bad/request') do
|
139
|
+
request_stub.get('/_db/_system/_api/bad/request') do
|
131
140
|
[400, response_headers, '{}']
|
132
141
|
end
|
133
142
|
|
@@ -139,7 +148,7 @@ describe Ashikawa::Core::Connection do
|
|
139
148
|
end
|
140
149
|
|
141
150
|
it 'should throw its own exception when doing a bad request' do
|
142
|
-
request_stub.get('/_api/secret') do
|
151
|
+
request_stub.get('/_db/_system/_api/secret') do
|
143
152
|
[401, response_headers, '']
|
144
153
|
end
|
145
154
|
|
@@ -151,7 +160,7 @@ describe Ashikawa::Core::Connection do
|
|
151
160
|
end
|
152
161
|
|
153
162
|
it 'should throw a general server error for the generic server error' do
|
154
|
-
request_stub.get('/_api/bad/request') do
|
163
|
+
request_stub.get('/_db/_system/_api/bad/request') do
|
155
164
|
[
|
156
165
|
500,
|
157
166
|
response_headers,
|
@@ -167,7 +176,7 @@ describe Ashikawa::Core::Connection do
|
|
167
176
|
end
|
168
177
|
|
169
178
|
it 'should raise an exception if a document is not found' do
|
170
|
-
request_stub.get('/_api/document/4590/333') do
|
179
|
+
request_stub.get('/_db/_system/_api/document/4590/333') do
|
171
180
|
[404, response_headers, '']
|
172
181
|
end
|
173
182
|
|
@@ -177,7 +186,7 @@ describe Ashikawa::Core::Connection do
|
|
177
186
|
end
|
178
187
|
|
179
188
|
it 'should raise an exception if a collection is not found' do
|
180
|
-
request_stub.get('/_api/collection/4590') do
|
189
|
+
request_stub.get('/_db/_system/_api/collection/4590') do
|
181
190
|
[404, response_headers, '']
|
182
191
|
end
|
183
192
|
|
@@ -187,7 +196,7 @@ describe Ashikawa::Core::Connection do
|
|
187
196
|
end
|
188
197
|
|
189
198
|
it 'should raise an exception if an index is not found' do
|
190
|
-
request_stub.get('/_api/index/4590/333') do
|
199
|
+
request_stub.get('/_db/_system/_api/index/4590/333') do
|
191
200
|
[404, response_headers, '']
|
192
201
|
end
|
193
202
|
|
@@ -197,7 +206,7 @@ describe Ashikawa::Core::Connection do
|
|
197
206
|
end
|
198
207
|
|
199
208
|
it 'should raise an exception for unknown pathes' do
|
200
|
-
request_stub.get('/_api/unknown_path/4590/333') do
|
209
|
+
request_stub.get('/_db/_system/_api/unknown_path/4590/333') do
|
201
210
|
[404, response_headers, '']
|
202
211
|
end
|
203
212
|
|
@@ -207,7 +216,7 @@ describe Ashikawa::Core::Connection do
|
|
207
216
|
end
|
208
217
|
|
209
218
|
it 'should raise an error if a malformed JSON was returned from the server' do
|
210
|
-
request_stub.get('/_api/document/4590/333') do
|
219
|
+
request_stub.get('/_db/_system/_api/document/4590/333') do
|
211
220
|
[200, response_headers, '{"a":1']
|
212
221
|
end
|
213
222
|
|
@@ -216,33 +225,4 @@ describe Ashikawa::Core::Connection do
|
|
216
225
|
request_stub.verify_stubbed_calls
|
217
226
|
end
|
218
227
|
end
|
219
|
-
|
220
|
-
describe 'initializing Faraday' do
|
221
|
-
subject { Ashikawa::Core::Connection }
|
222
|
-
let(:adapter) { double('Adapter') }
|
223
|
-
let(:logger) { double('Logger') }
|
224
|
-
let(:blocky) { double('Block') }
|
225
|
-
|
226
|
-
it 'should initalize with specific logger and adapter' do
|
227
|
-
expect(Faraday).to receive(:new).with("#{ARANGO_HOST}/_api").and_yield(blocky)
|
228
|
-
expect(blocky).to receive(:request).with(:json)
|
229
|
-
expect(blocky).to receive(:response).with(:logger, logger)
|
230
|
-
expect(blocky).to receive(:response).with(:error_response)
|
231
|
-
expect(blocky).to receive(:response).with(:json)
|
232
|
-
expect(blocky).to receive(:adapter).with(adapter)
|
233
|
-
|
234
|
-
subject.new(ARANGO_HOST, adapter: adapter, logger: logger)
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'should initialize with defaults when no specific logger and adapter was given' do
|
238
|
-
expect(Faraday).to receive(:new).with("#{ARANGO_HOST}/_api").and_yield(blocky)
|
239
|
-
expect(blocky).to receive(:request).with(:json)
|
240
|
-
expect(blocky).to receive(:response).with(:logger, NullLogger.instance)
|
241
|
-
expect(blocky).to receive(:response).with(:error_response)
|
242
|
-
expect(blocky).to receive(:response).with(:json)
|
243
|
-
expect(blocky).to receive(:adapter).with(Faraday.default_adapter)
|
244
|
-
|
245
|
-
subject.new(ARANGO_HOST)
|
246
|
-
end
|
247
|
-
end
|
248
228
|
end
|
data/spec/unit/cursor_spec.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'unit/spec_helper'
|
3
3
|
require 'ashikawa-core/cursor'
|
4
|
+
require 'ashikawa-core/database'
|
4
5
|
|
5
6
|
describe Ashikawa::Core::Cursor do
|
6
7
|
subject { Ashikawa::Core::Cursor }
|
7
|
-
let(:database) {
|
8
|
+
let(:database) { instance_double('Ashikawa::Core::Database') }
|
8
9
|
|
9
10
|
describe 'cursor for a non-complete batch' do
|
10
11
|
let(:response) { server_response('cursor/26011191') }
|
@@ -83,7 +84,7 @@ describe Ashikawa::Core::Cursor do
|
|
83
84
|
|
84
85
|
it 'should be enumerable' do
|
85
86
|
first = true
|
86
|
-
|
87
|
+
document = instance_double('Ashikawa::Core::Document')
|
87
88
|
|
88
89
|
expect(database).to receive(:send_request)
|
89
90
|
.twice
|
@@ -98,9 +99,9 @@ describe Ashikawa::Core::Cursor do
|
|
98
99
|
|
99
100
|
expect(Ashikawa::Core::Document).to receive(:new)
|
100
101
|
.exactly(5).times
|
101
|
-
.and_return(
|
102
|
+
.and_return(document)
|
102
103
|
|
103
|
-
expect(subject.map { |i| i }[0]).to eq(
|
104
|
+
expect(subject.map { |i| i }[0]).to eq(document)
|
104
105
|
end
|
105
106
|
|
106
107
|
it 'should return edge objects when recieving data from an edge collection' do
|
data/spec/unit/database_spec.rb
CHANGED
@@ -5,21 +5,12 @@ require 'ashikawa-core/database'
|
|
5
5
|
describe Ashikawa::Core::Database do
|
6
6
|
subject { Ashikawa::Core::Database }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:scheme) { double }
|
12
|
-
let(:connection) { double('connection', host: host, port: port, scheme: scheme) }
|
13
|
-
let(:js_function) { double }
|
14
|
-
let(:collections) { double }
|
15
|
-
let(:transaction) { double }
|
16
|
-
let(:logger) { double }
|
17
|
-
let(:adapter) { double }
|
18
|
-
let(:configuration) { double }
|
19
|
-
let(:raw_collection) { double }
|
20
|
-
let(:collection) { double }
|
8
|
+
let(:connection) { instance_double('Ashikawa::Core::Connection', host: 'localhost', port: 8529, scheme: 'https') }
|
9
|
+
let(:collection) { instance_double('Ashikawa::Core::Collection') }
|
10
|
+
let(:raw_collection) { double('RawCollection') }
|
21
11
|
|
22
12
|
it 'should initialize with a configuration object' do
|
13
|
+
configuration = instance_double('Ashikawa::Core::Configuration')
|
23
14
|
expect(Ashikawa::Core::Configuration).to receive(:new)
|
24
15
|
.and_return(configuration)
|
25
16
|
expect(configuration).to receive(:connection)
|
@@ -41,9 +32,8 @@ describe Ashikawa::Core::Database do
|
|
41
32
|
subject.query
|
42
33
|
end
|
43
34
|
|
44
|
-
let(:database_list) { double('DatabaseList') }
|
45
|
-
|
46
35
|
it 'should list all databases' do
|
36
|
+
database_list = %w(_system cupcakes ponies)
|
47
37
|
expect(connection).to receive(:send_request)
|
48
38
|
.with('database')
|
49
39
|
.and_return({ 'result' => database_list, 'error' => false, 'code' => 200 })
|
@@ -108,7 +98,6 @@ describe Ashikawa::Core::Database do
|
|
108
98
|
end
|
109
99
|
|
110
100
|
it 'should truncate all documents in all collections' do
|
111
|
-
collection = double('Collection')
|
112
101
|
allow(subject).to receive(:collections)
|
113
102
|
.and_return([collection])
|
114
103
|
expect(collection).to receive(:truncate)
|
@@ -210,6 +199,9 @@ describe Ashikawa::Core::Database do
|
|
210
199
|
end
|
211
200
|
|
212
201
|
it 'should create a transaction' do
|
202
|
+
js_function = 'function () { return 5; }'
|
203
|
+
collections = { read: ['collection_1'] }
|
204
|
+
transaction = instance_double('Ashikawa::Core::Transaction')
|
213
205
|
expect(Ashikawa::Core::Transaction).to receive(:new)
|
214
206
|
.with(subject, js_function, collections)
|
215
207
|
.and_return(transaction)
|
data/spec/unit/document_spec.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'unit/spec_helper'
|
3
3
|
require 'ashikawa-core/document'
|
4
|
+
require 'ashikawa-core/database'
|
4
5
|
|
5
6
|
describe Ashikawa::Core::Document do
|
6
|
-
let(:database) {
|
7
|
-
let(:id) {
|
8
|
-
let(:path) { 'document/
|
9
|
-
let(:key) {
|
10
|
-
let(:revision) {
|
11
|
-
let(:first_name) {
|
12
|
-
let(:last_name) {
|
13
|
-
let(:more_info) {
|
7
|
+
let(:database) { instance_double('Ashikawa::Core::Database') }
|
8
|
+
let(:id) { '23914039/25880119' }
|
9
|
+
let(:path) { 'document/23914039/25880119' }
|
10
|
+
let(:key) { '25880119' }
|
11
|
+
let(:revision) { '13728680' }
|
12
|
+
let(:first_name) { 'Jeff' }
|
13
|
+
let(:last_name) { 'Lebowski' }
|
14
|
+
let(:more_info) { 'This is valuable information' }
|
14
15
|
let(:delete_payload) { { delete: {} } }
|
15
16
|
let(:raw_data) do
|
16
17
|
{
|
@@ -59,7 +60,7 @@ describe Ashikawa::Core::Document do
|
|
59
60
|
describe 'initialized document with ID' do
|
60
61
|
subject { Ashikawa::Core::Document.new(database, raw_data) }
|
61
62
|
|
62
|
-
let(:new_last_name) {
|
63
|
+
let(:new_last_name) { 'Dudemeister' }
|
63
64
|
let(:raw_data_without_id_and_new_last_name) do
|
64
65
|
{
|
65
66
|
'first_name' => first_name,
|
@@ -91,7 +92,7 @@ describe Ashikawa::Core::Document do
|
|
91
92
|
.with(path, {})
|
92
93
|
.and_return({ 'name' => 'Jeff' })
|
93
94
|
|
94
|
-
refreshed_subject = subject.refresh
|
95
|
+
refreshed_subject = subject.refresh
|
95
96
|
expect(refreshed_subject).to eq(subject)
|
96
97
|
expect(subject['name']).to eq('Jeff')
|
97
98
|
end
|
data/spec/unit/edge_spec.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'unit/spec_helper'
|
3
3
|
require 'ashikawa-core/edge'
|
4
|
+
require 'ashikawa-core/database'
|
4
5
|
|
5
6
|
describe Ashikawa::Core::Edge do
|
6
|
-
let(:database) {
|
7
|
-
let(:id) {
|
8
|
-
let(:path) { 'edge/
|
9
|
-
let(:key) {
|
10
|
-
let(:revision) {
|
11
|
-
let(:from_id) {
|
12
|
-
let(:to_id) {
|
13
|
-
let(:first_name) {
|
14
|
-
let(:last_name) {
|
7
|
+
let(:database) { instance_double('Ashikawa::Core::Database') }
|
8
|
+
let(:id) { '23914039/25880119' }
|
9
|
+
let(:path) { 'edge/23914039/25880119' }
|
10
|
+
let(:key) { '25880119' }
|
11
|
+
let(:revision) { '13728680' }
|
12
|
+
let(:from_id) { 'nodes/source_node' }
|
13
|
+
let(:to_id) { 'nodes/target_node' }
|
14
|
+
let(:first_name) { 'Jeff' }
|
15
|
+
let(:last_name) { 'Lebowski' }
|
15
16
|
let(:raw_data) do
|
16
17
|
{
|
17
18
|
'_id' => id,
|
@@ -23,7 +24,7 @@ describe Ashikawa::Core::Edge do
|
|
23
24
|
'last_name' => last_name
|
24
25
|
}
|
25
26
|
end
|
26
|
-
let(:new_last_name) {
|
27
|
+
let(:new_last_name) { 'Dudemeister' }
|
27
28
|
let(:raw_data_without_meta_data_and_new_last_name) do
|
28
29
|
{
|
29
30
|
'first_name' => first_name,
|
@@ -57,7 +58,7 @@ describe Ashikawa::Core::Edge do
|
|
57
58
|
end
|
58
59
|
|
59
60
|
describe 'initializing edge with additional data' do
|
60
|
-
let(:more_info) {
|
61
|
+
let(:more_info) { 'Some very important information' }
|
61
62
|
let(:additional_data) { { more_info: more_info } }
|
62
63
|
subject { Ashikawa::Core::Edge.new(database, raw_data, additional_data) }
|
63
64
|
|
data/spec/unit/exception_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Ashikawa::Core::NoCollectionProvidedException do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe Ashikawa::Core::ClientError do
|
18
|
-
let(:error_message) {
|
18
|
+
let(:error_message) { 'The client did not do what it should do' }
|
19
19
|
subject { Ashikawa::Core::ClientError.new(error_message) }
|
20
20
|
its(:to_s) { should be(error_message) }
|
21
21
|
end
|
@@ -49,7 +49,7 @@ describe Ashikawa::Core::IndexNotFoundException do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe Ashikawa::Core::ServerError do
|
52
|
-
let(:error_message) {
|
52
|
+
let(:error_message) { 'The server is misbehaving' }
|
53
53
|
subject { Ashikawa::Core::ServerError.new(error_message) }
|
54
54
|
its(:to_s) { should be(error_message) }
|
55
55
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'unit/spec_helper'
|
3
|
+
require 'ashikawa-core/faraday_factory'
|
4
|
+
|
5
|
+
describe Ashikawa::Core::FaradayFactory do
|
6
|
+
describe 'FaradayFactory.create_connection' do
|
7
|
+
subject { Ashikawa::Core::FaradayFactory }
|
8
|
+
let(:config_block) { double('Block') }
|
9
|
+
let(:api_string) { double('ApiString') }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(Faraday).to receive(:new).with(api_string).and_yield(config_block)
|
13
|
+
allow(config_block).to receive(:request).with(:json)
|
14
|
+
allow(config_block).to receive(:response).with(:error_response)
|
15
|
+
allow(config_block).to receive(:response).with(:json)
|
16
|
+
allow(config_block).to receive(:adapter).with(Faraday.default_adapter)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should initialize with a specific logger' do
|
20
|
+
logger = double('Logger')
|
21
|
+
expect(config_block).to receive(:response).with(:minimal_logger, logger, debug_headers: false)
|
22
|
+
subject.create_connection(api_string, logger: logger)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should initialize with a specific adapter' do
|
26
|
+
adapter = double('Adapter')
|
27
|
+
expect(config_block).to receive(:adapter).with(adapter)
|
28
|
+
subject.create_connection(api_string, adapter: adapter)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should initialize with the default adapter when no specific adapter was given' do
|
32
|
+
expect(config_block).to receive(:adapter).with(Faraday.default_adapter)
|
33
|
+
subject.create_connection(api_string, {})
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should allow to add additional request middlewares with options' do
|
37
|
+
expect(config_block).to receive(:request).with(:my_middleware, :options)
|
38
|
+
subject.create_connection(api_string, additional_request_middlewares: [[:my_middleware, :options]])
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should allow to add additional response middlewares with options' do
|
42
|
+
expect(config_block).to receive(:response).with(:my_middleware, :options)
|
43
|
+
subject.create_connection(api_string, additional_response_middlewares: [[:my_middleware, :options]])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should allow to add additional middlewares with options' do
|
47
|
+
expect(config_block).to receive(:use).with(:my_middleware, :options)
|
48
|
+
subject.create_connection(api_string, additional_middlewares: [[:my_middleware, :options]])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|