airborne 0.0.21 → 0.0.22

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.
@@ -1,26 +1,26 @@
1
1
  require 'rest_client'
2
2
 
3
3
  module Airborne
4
- module RestClientRequester
5
- def make_request(method, url, options = {})
6
- headers = (options[:headers] || {}).merge({content_type: :json})
7
- base_headers = Airborne.configuration.headers || {}
8
- headers = base_headers.merge(headers)
9
- res = if method == :post || method == :patch || method == :put
10
- begin
11
- RestClient.send(method, get_url(url), options[:body].nil? ? "" : options[:body].to_json, headers)
12
- rescue RestClient::Exception => e
13
- e.response
14
- end
15
- else
16
- begin
17
- RestClient.send(method, get_url(url), headers)
18
- rescue RestClient::Exception => e
19
- e.response
20
- end
4
+ module RestClientRequester
5
+ def make_request(method, url, options = {})
6
+ headers = (options[:headers] || {}).merge({content_type: :json})
7
+ base_headers = Airborne.configuration.headers || {}
8
+ headers = base_headers.merge(headers)
9
+ res = if method == :post || method == :patch || method == :put
10
+ begin
11
+ RestClient.send(method, get_url(url), options[:body].nil? ? "" : options[:body].to_json, headers)
12
+ rescue RestClient::Exception => e
13
+ e.response
14
+ end
15
+ else
16
+ begin
17
+ RestClient.send(method, get_url(url), headers)
18
+ rescue RestClient::Exception => e
19
+ e.response
20
+ end
21
21
 
22
- end
23
- res
24
- end
25
- end
22
+ end
23
+ res
24
+ end
25
+ end
26
26
  end
@@ -1,54 +1,54 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'base spec' do
4
- it 'when request is made response should be set' do
5
- mock_get('simple_get')
6
- get '/simple_get'
7
- expect(response).to_not be(nil)
8
- end
9
-
10
- it 'when request is made headers should be set' do
11
- mock_get('simple_get')
12
- get '/simple_get'
13
- expect(headers).to_not be(nil)
14
- end
15
-
16
- it 'when request is made headers should be hash with indifferent access' do
17
- mock_get('simple_get', {'Content-Type' => 'application/json'})
18
- get '/simple_get'
19
- expect(headers).to be_kind_of(Hash)
20
- expect(headers[:content_type]).to eq('application/json')
21
- expect(headers['content_type']).to eq('application/json')
22
- end
23
-
24
- it 'when request is made body should be set' do
25
- mock_get('simple_get')
26
- get '/simple_get'
27
- expect(body).to_not be(nil)
28
- end
29
-
30
- it 'when request is made json body should be symbolized hash' do
31
- mock_get('simple_get')
32
- get '/simple_get'
33
- expect(json_body).to be_kind_of(Hash)
34
- expect(json_body.first[0]).to be_kind_of(Symbol)
35
- end
36
-
37
- it 'should not error on invalid JSON' do
38
- mock_get('invalid_get')
39
- get '/invalid_get'
40
- expect(json_body).to be(nil)
41
- end
42
-
43
- it 'should handle a 500 error on get' do
44
- mock_get('simple_get', {}, [500, "Internal Server Error"])
45
- get '/simple_get'
46
- expect(json_body).to_not be(nil)
47
- end
48
-
49
- it 'should handle a 500 error on post' do
50
- mock_post('simple_post', {}, [500, "Internal Server Error"])
51
- post '/simple_post', {}
52
- expect(json_body).to_not be(nil)
53
- end
4
+ it 'when request is made response should be set' do
5
+ mock_get('simple_get')
6
+ get '/simple_get'
7
+ expect(response).to_not be(nil)
8
+ end
9
+
10
+ it 'when request is made headers should be set' do
11
+ mock_get('simple_get')
12
+ get '/simple_get'
13
+ expect(headers).to_not be(nil)
14
+ end
15
+
16
+ it 'when request is made headers should be hash with indifferent access' do
17
+ mock_get('simple_get', {'Content-Type' => 'application/json'})
18
+ get '/simple_get'
19
+ expect(headers).to be_kind_of(Hash)
20
+ expect(headers[:content_type]).to eq('application/json')
21
+ expect(headers['content_type']).to eq('application/json')
22
+ end
23
+
24
+ it 'when request is made body should be set' do
25
+ mock_get('simple_get')
26
+ get '/simple_get'
27
+ expect(body).to_not be(nil)
28
+ end
29
+
30
+ it 'when request is made json body should be symbolized hash' do
31
+ mock_get('simple_get')
32
+ get '/simple_get'
33
+ expect(json_body).to be_kind_of(Hash)
34
+ expect(json_body.first[0]).to be_kind_of(Symbol)
35
+ end
36
+
37
+ it 'should not error on invalid JSON' do
38
+ mock_get('invalid_get')
39
+ get '/invalid_get'
40
+ expect(json_body).to be(nil)
41
+ end
42
+
43
+ it 'should handle a 500 error on get' do
44
+ mock_get('simple_get', {}, [500, "Internal Server Error"])
45
+ get '/simple_get'
46
+ expect(json_body).to_not be(nil)
47
+ end
48
+
49
+ it 'should handle a 500 error on post' do
50
+ mock_post('simple_post', {}, [500, "Internal Server Error"])
51
+ post '/simple_post', {}
52
+ expect(json_body).to_not be(nil)
53
+ end
54
54
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'delete' do
4
- it 'should allow testing on delete requests' do
5
- mock_delete 'simple_delete'
6
- delete '/simple_delete'
7
- expect_status(200)
8
- end
4
+ it 'should allow testing on delete requests' do
5
+ mock_delete 'simple_delete'
6
+ delete '/simple_delete'
7
+ expect_status(200)
8
+ end
9
9
  end
@@ -1,21 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json_keys' do
4
- it 'should fail when json keys are missing' do
5
- mock_get('simple_json')
6
- get '/simple_json', {}
7
- expect{expect_json_keys([:foo, :bar, :baz, :bax])}.to raise_error
8
- end
4
+ it 'should fail when json keys are missing' do
5
+ mock_get('simple_json')
6
+ get '/simple_json', {}
7
+ expect{expect_json_keys([:foo, :bar, :baz, :bax])}.to raise_error
8
+ end
9
9
 
10
- it 'should ensure correct json keys' do
11
- mock_get('simple_json')
12
- get '/simple_json', {}
13
- expect_json_keys([:foo, :bar, :baz])
14
- end
10
+ it 'should ensure correct json keys' do
11
+ mock_get('simple_json')
12
+ get '/simple_json', {}
13
+ expect_json_keys([:foo, :bar, :baz])
14
+ end
15
15
 
16
- it 'should ensure correct partial json keys' do
17
- mock_get('simple_json')
18
- get '/simple_json', {}
19
- expect_json_keys([:foo, :bar])
20
- end
16
+ it 'should ensure correct partial json keys' do
17
+ mock_get('simple_json')
18
+ get '/simple_json', {}
19
+ expect_json_keys([:foo, :bar])
20
+ end
21
+
22
+ it 'should ensure json keys with path' do
23
+ mock_get('simple_nested_path')
24
+ get '/simple_nested_path', {}
25
+ expect_json_keys('address', [:street, :city])
26
+ end
27
+
28
+ it 'should fail when keys are missing with path' do
29
+ mock_get('simple_nested_path')
30
+ get '/simple_nested_path', {}
31
+ expect{expect_json_keys('address', [:bad])}.to raise_error
32
+ end
21
33
  end
@@ -1,65 +1,65 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json' do
4
- it 'should ensure correct json values' do
5
- mock_get('simple_get')
6
- get '/simple_get'
7
- expect_json({name: "Alex", age: 32 })
8
- end
4
+ it 'should ensure correct json values' do
5
+ mock_get('simple_get')
6
+ get '/simple_get'
7
+ expect_json({name: "Alex", age: 32 })
8
+ end
9
9
 
10
- it 'should fail when incorrect json is tested' do
11
- mock_get('simple_get')
12
- get '/simple_get'
13
- expect{expect_json({bad: "data"})}.to raise_error
14
- end
15
-
16
- it 'should allow simple path and verify only that path' do
17
- mock_get('simple_path_get')
18
- get '/simple_path_get'
19
- expect_json('address', {street: "Area 51", city: "Roswell", state: "NM"})
20
- end
21
-
22
- it 'should allow full object graph' do
23
- mock_get('simple_path_get')
24
- get '/simple_path_get'
25
- expect_json({name: "Alex", address: {street: "Area 51", city: "Roswell", state: "NM"}})
26
- end
10
+ it 'should fail when incorrect json is tested' do
11
+ mock_get('simple_get')
12
+ get '/simple_get'
13
+ expect{expect_json({bad: "data"})}.to raise_error
14
+ end
15
+
16
+ it 'should allow simple path and verify only that path' do
17
+ mock_get('simple_path_get')
18
+ get '/simple_path_get'
19
+ expect_json('address', {street: "Area 51", city: "Roswell", state: "NM"})
20
+ end
21
+
22
+ it 'should allow full object graph' do
23
+ mock_get('simple_path_get')
24
+ get '/simple_path_get'
25
+ expect_json({name: "Alex", address: {street: "Area 51", city: "Roswell", state: "NM"}})
26
+ end
27
27
 
28
- it 'should allow nested paths' do
29
- mock_get('simple_nested_path')
30
- get '/simple_nested_path'
31
- expect_json('address.coordinates', {lattitude: 33.3872, longitutde: 104.5281} )
32
- end
28
+ it 'should allow nested paths' do
29
+ mock_get('simple_nested_path')
30
+ get '/simple_nested_path'
31
+ expect_json('address.coordinates', {lattitude: 33.3872, longitutde: 104.5281} )
32
+ end
33
33
 
34
- it 'should index into array and test against specific element' do
35
- mock_get('array_with_index')
36
- get '/array_with_index'
37
- expect_json('cars.0', {make: "Tesla", model: "Model S"})
38
- end
39
-
40
- it 'should test against all elements in the array' do
41
- mock_get('array_with_index')
42
- get '/array_with_index'
43
- expect_json('cars.?', {make: "Tesla", model: "Model S"})
44
- expect_json('cars.?', {make: "Lamborghini", model: "Aventador"})
45
- end
34
+ it 'should index into array and test against specific element' do
35
+ mock_get('array_with_index')
36
+ get '/array_with_index'
37
+ expect_json('cars.0', {make: "Tesla", model: "Model S"})
38
+ end
39
+
40
+ it 'should test against all elements in the array' do
41
+ mock_get('array_with_index')
42
+ get '/array_with_index'
43
+ expect_json('cars.?', {make: "Tesla", model: "Model S"})
44
+ expect_json('cars.?', {make: "Lamborghini", model: "Aventador"})
45
+ end
46
46
 
47
- it 'should invoke proc passed in' do
48
- mock_get('simple_get')
49
- get '/simple_get'
50
- expect_json({name: -> (name){expect(name.length).to eq(4)}})
51
- end
47
+ it 'should invoke proc passed in' do
48
+ mock_get('simple_get')
49
+ get '/simple_get'
50
+ expect_json({name: -> (name){expect(name.length).to eq(4)}})
51
+ end
52
52
 
53
- it 'should test against regex' do
54
- mock_get('simple_get')
55
- get '/simple_get'
56
- expect_json({name: regex("^A")})
57
- end
53
+ it 'should test against regex' do
54
+ mock_get('simple_get')
55
+ get '/simple_get'
56
+ expect_json({name: regex("^A")})
57
+ end
58
58
 
59
- it 'should raise an error if regex does not match' do
60
- mock_get('simple_get')
61
- get '/simple_get'
62
- expect{expect_json({name: regex("^B")})}.to raise_error
63
- end
59
+ it 'should raise an error if regex does not match' do
60
+ mock_get('simple_get')
61
+ get '/simple_get'
62
+ expect{expect_json({name: regex("^B")})}.to raise_error
63
+ end
64
64
 
65
65
  end
@@ -1,111 +1,111 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'expect_json_types' do
4
- it 'should detect current type' do
5
- mock_get('simple_get')
6
- get '/simple_get'
7
- expect_json_types({name: :string, age: :int})
8
- end
9
-
10
- it 'should fail when incorrect json types tested' do
11
- mock_get('simple_get')
12
- get '/simple_get'
13
- expect{expect_json_types({bad: :bool})}.to raise_error
14
- end
15
-
16
- it 'should not fail when optional property is not present' do
17
- mock_get('simple_get')
18
- get '/simple_get'
19
- expect_json_types({name: :string, age: :int, optional: :bool_or_null })
20
- end
21
-
22
- it 'should allow simple path and verify only that path' do
23
- mock_get('simple_path_get')
24
- get '/simple_path_get'
25
- expect_json_types('address', {street: :string, city: :string, state: :string})
26
- end
27
-
28
- it 'should allow full object graph' do
29
- mock_get('simple_path_get')
30
- get '/simple_path_get'
31
- expect_json_types({name: :string, address: {street: :string, city: :string, state: :string}})
32
- end
33
-
34
- it 'should allow nested paths' do
35
- mock_get('simple_nested_path')
36
- get '/simple_nested_path'
37
- expect_json_types('address.coordinates', {lattitude: :float, longitutde: :float} )
38
- end
39
-
40
- it 'should index into array and test against specific element' do
41
- mock_get('array_with_index')
42
- get '/array_with_index'
43
- expect_json_types('cars.0', {make: :string, model: :string})
44
- end
45
-
46
- it 'should test against all elements in the array' do
47
- mock_get('array_with_index')
48
- get '/array_with_index'
49
- expect_json_types('cars.*', {make: :string, model: :string})
50
- end
51
-
52
- it 'should ensure all elements of array are valid' do
53
- mock_get('array_with_index')
54
- get '/array_with_index'
55
- expect{expect_json_types('cars.*', {make: :string, model: :int})}.to raise_error
56
- end
57
-
58
- it 'should check all nested arrays for specified elements' do
59
- mock_get('array_with_nested')
60
- get '/array_with_nested'
61
- expect_json_types('cars.*.owners.*', {name: :string})
62
- end
63
-
64
- it 'should ensure all nested arrays contain correct data' do
65
- mock_get('array_with_nested_bad_data')
66
- get '/array_with_nested_bad_data'
67
- expect{expect_json_types('cars.*.owners.*', {name: :string})}.to raise_error
68
- end
69
-
70
- it 'should check all types in a simple array' do
71
- mock_get('array_of_values')
72
- get '/array_of_values'
73
- expect_json_types({grades: :array_of_ints})
74
- end
75
-
76
- it 'should ensure all valid types in a simple array' do
77
- mock_get('array_of_values')
78
- get '/array_of_values'
79
- expect{expect_json_types({bad: :array_of_ints})}.to raise_error
80
- end
81
-
82
- it 'should deep symbolize array responses' do
83
- mock_get('array_response')
84
- get '/array_response'
85
- expect_json_types("*", {name: :string})
86
- end
87
-
88
- it 'should allow empty array' do
89
- mock_get('array_of_values')
90
- get '/array_of_values'
91
- expect_json_types({emptyArray: :array_of_ints})
92
- end
93
-
94
- it 'should test optional nested hash when exists' do
95
- mock_get('simple_nested_path')
96
- get '/simple_nested_path'
97
- expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float}))
98
- end
99
-
100
- it 'should allow optional nested hash' do
101
- mock_get('simple_path_get')
102
- get '/simple_path_get'
103
- expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float}))
104
- end
105
-
106
- it 'should invoke proc passed in' do
107
- mock_get('simple_get')
108
- get '/simple_get'
109
- expect_json_types({name: -> (name){expect(name.length).to eq(4)}})
110
- end
4
+ it 'should detect current type' do
5
+ mock_get('simple_get')
6
+ get '/simple_get'
7
+ expect_json_types({name: :string, age: :int})
8
+ end
9
+
10
+ it 'should fail when incorrect json types tested' do
11
+ mock_get('simple_get')
12
+ get '/simple_get'
13
+ expect{expect_json_types({bad: :bool})}.to raise_error
14
+ end
15
+
16
+ it 'should not fail when optional property is not present' do
17
+ mock_get('simple_get')
18
+ get '/simple_get'
19
+ expect_json_types({name: :string, age: :int, optional: :bool_or_null })
20
+ end
21
+
22
+ it 'should allow simple path and verify only that path' do
23
+ mock_get('simple_path_get')
24
+ get '/simple_path_get'
25
+ expect_json_types('address', {street: :string, city: :string, state: :string})
26
+ end
27
+
28
+ it 'should allow full object graph' do
29
+ mock_get('simple_path_get')
30
+ get '/simple_path_get'
31
+ expect_json_types({name: :string, address: {street: :string, city: :string, state: :string}})
32
+ end
33
+
34
+ it 'should allow nested paths' do
35
+ mock_get('simple_nested_path')
36
+ get '/simple_nested_path'
37
+ expect_json_types('address.coordinates', {lattitude: :float, longitutde: :float} )
38
+ end
39
+
40
+ it 'should index into array and test against specific element' do
41
+ mock_get('array_with_index')
42
+ get '/array_with_index'
43
+ expect_json_types('cars.0', {make: :string, model: :string})
44
+ end
45
+
46
+ it 'should test against all elements in the array' do
47
+ mock_get('array_with_index')
48
+ get '/array_with_index'
49
+ expect_json_types('cars.*', {make: :string, model: :string})
50
+ end
51
+
52
+ it 'should ensure all elements of array are valid' do
53
+ mock_get('array_with_index')
54
+ get '/array_with_index'
55
+ expect{expect_json_types('cars.*', {make: :string, model: :int})}.to raise_error
56
+ end
57
+
58
+ it 'should check all nested arrays for specified elements' do
59
+ mock_get('array_with_nested')
60
+ get '/array_with_nested'
61
+ expect_json_types('cars.*.owners.*', {name: :string})
62
+ end
63
+
64
+ it 'should ensure all nested arrays contain correct data' do
65
+ mock_get('array_with_nested_bad_data')
66
+ get '/array_with_nested_bad_data'
67
+ expect{expect_json_types('cars.*.owners.*', {name: :string})}.to raise_error
68
+ end
69
+
70
+ it 'should check all types in a simple array' do
71
+ mock_get('array_of_values')
72
+ get '/array_of_values'
73
+ expect_json_types({grades: :array_of_ints})
74
+ end
75
+
76
+ it 'should ensure all valid types in a simple array' do
77
+ mock_get('array_of_values')
78
+ get '/array_of_values'
79
+ expect{expect_json_types({bad: :array_of_ints})}.to raise_error
80
+ end
81
+
82
+ it 'should deep symbolize array responses' do
83
+ mock_get('array_response')
84
+ get '/array_response'
85
+ expect_json_types("*", {name: :string})
86
+ end
87
+
88
+ it 'should allow empty array' do
89
+ mock_get('array_of_values')
90
+ get '/array_of_values'
91
+ expect_json_types({emptyArray: :array_of_ints})
92
+ end
93
+
94
+ it 'should test optional nested hash when exists' do
95
+ mock_get('simple_nested_path')
96
+ get '/simple_nested_path'
97
+ expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float}))
98
+ end
99
+
100
+ it 'should allow optional nested hash' do
101
+ mock_get('simple_path_get')
102
+ get '/simple_path_get'
103
+ expect_json_types("address.coordinates", optional({lattitude: :float, longitutde: :float}))
104
+ end
105
+
106
+ it 'should invoke proc passed in' do
107
+ mock_get('simple_get')
108
+ get '/simple_get'
109
+ expect_json_types({name: -> (name){expect(name.length).to eq(4)}})
110
+ end
111
111
  end