airborne 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e256829001b2f4c9198e37427ad95e07ae82cd5c77362fc5f8129ab5bc7005e
4
- data.tar.gz: 6150f90eb59e9e52ad13ddf162e6417ba26bcb6bd078bedcf648757f6ff8f5d6
3
+ metadata.gz: 90e549d9b143f595ddd2549a2d3c3ed73a87070da7c4f3e500f94e7617a3a5b9
4
+ data.tar.gz: ff9e58e5865cb84137f24139a343a500cc3e7e0f4994916715a1cacb7565f19c
5
5
  SHA512:
6
- metadata.gz: 32ced4be6df4546b7e3e900179d916f451a3c7cc0a5732e63f31d1aa45cea5ccaf2faba890d8b7310ca576ed6a84f86e4c57e2e0f9f4f26151dbc37a660e1979
7
- data.tar.gz: f91e180752c9be0064239fcaef4f2b3f20a5dad5a4efa42698c6af1be6d2f41da322c1beb662898f2770e391ddd84c8a4315068004cef7d0a4ed88cb92806f63
6
+ metadata.gz: 8d77b67f75dcc2fdba964bda66506f0680cf694edc0b0793abae1ccc5260e1429974473ce71cb45adb3adde3a894f414a17923fa0887fe3d5fa0a36bc7ae8561
7
+ data.tar.gz: 3e1c7d000e82533784199e3b18fd67f5c946f02b3832dba65a3425975e88d24dc9c3650da8a7516933f6cd23c9707fcd1ee871c8999392ab5ae6ebdaf8718813
@@ -0,0 +1,8 @@
1
+ version: 1
2
+
3
+ update_configs:
4
+ - package_manager: "ruby:bundler"
5
+ directory: "./"
6
+ update_schedule: "daily"
7
+ # https://dependabot.com/docs/config-file/#version_requirement_updates
8
+ version_requirement_updates: auto
data/README.md CHANGED
@@ -137,12 +137,19 @@ When calling any of the methods above, you can pass request headers to be used.
137
137
  get 'http://example.com/api/v1/my_api', { 'x-auth-token' => 'my_token' }
138
138
  ```
139
139
 
140
- For requests that require a body (`post`, `put`, `patch`) you can pass the body as a hash as well:
140
+ For requests that require a body (`post`, `put`, `patch`) you can pass the body as well:
141
141
 
142
142
  ```ruby
143
143
  post 'http://example.com/api/v1/my_api', { :name => 'John Doe' }, { 'x-auth-token' => 'my_token' }
144
144
  ```
145
145
 
146
+ The body may be any JSON-serializable type, as long as you want to post `application/json` content type.
147
+ You may set a different content type and post a string body this way:
148
+
149
+ ```ruby
150
+ post 'http://example.com/api/v1/my_api', "Hello there!", { content_type: 'text/plain' }
151
+ ```
152
+
146
153
  For requests that require Query params you can pass a params hash into headers.
147
154
 
148
155
  ```ruby
data/airborne.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'airborne'
5
- s.version = '0.3.0'
5
+ s.version = '0.3.1'
6
6
  s.date = Date.today.to_s
7
7
  s.summary = 'RSpec driven API testing framework'
8
8
  s.authors = ['Alex Friedman', 'Seth Pollack']
@@ -7,7 +7,7 @@ module Airborne
7
7
  res = if method == :post || method == :patch || method == :put
8
8
  begin
9
9
  request_body = options[:body].nil? ? '' : options[:body]
10
- request_body = request_body.to_json if options[:body].is_a?(Hash)
10
+ request_body = request_body.to_json if is_json_request(headers)
11
11
  RestClient.send(method, get_url(url), request_body, headers)
12
12
  rescue RestClient::Exception => e
13
13
  e.response
@@ -24,6 +24,11 @@ module Airborne
24
24
 
25
25
  private
26
26
 
27
+ def is_json_request(headers)
28
+ header = headers.fetch(:content_type)
29
+ header == :json || /application\/([a-zA-Z0-9\.\_\-]*\+?)json/ =~ header
30
+ end
31
+
27
32
  def base_headers
28
33
  { content_type: :json }.merge(Airborne.configuration.headers || {})
29
34
  end
@@ -33,4 +33,25 @@ describe 'client requester' do
33
33
  expect(RestClient).to have_received(:send)
34
34
  .with(:get, 'http://www.example.com/foo', { content_type: 'text/plain' })
35
35
  end
36
+
37
+ it 'should serialize body to json when :content_type is (default) :json' do
38
+ post '/foo', { test: 'serialized' }
39
+
40
+ expect(RestClient).to have_received(:send)
41
+ .with(:post, 'http://www.example.com/foo', '{"test":"serialized"}', { content_type: :json })
42
+ end
43
+
44
+ it 'should serialize body to json when :content_type is any enhanced JSON content type' do
45
+ post '/foo', { test: 'serialized' }, { content_type: 'application/vnd.airborne.2+json' }
46
+
47
+ expect(RestClient).to have_received(:send)
48
+ .with(:post, 'http://www.example.com/foo', '{"test":"serialized"}', { content_type: 'application/vnd.airborne.2+json' })
49
+ end
50
+
51
+ it 'should not serialize body to json when :content_type does not match JSON' do
52
+ post '/foo', { test: 'not serialized' }, { content_type: 'text/plain' }
53
+
54
+ expect(RestClient).to have_received(:send)
55
+ .with(:post, 'http://www.example.com/foo', { test: 'not serialized' }, { content_type: 'text/plain' })
56
+ end
36
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airborne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Friedman
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".coveralls.yml"
119
+ - ".dependabot/config.yml"
119
120
  - ".gitignore"
120
121
  - ".rspec"
121
122
  - ".travis.yml"
@@ -199,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  - !ruby/object:Gem::Version
200
201
  version: '0'
201
202
  requirements: []
202
- rubygems_version: 3.0.3
203
+ rubygems_version: 3.0.1
203
204
  signing_key:
204
205
  specification_version: 4
205
206
  summary: RSpec driven API testing framework