apill 3.1.2 → 3.1.3

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
  SHA1:
3
- metadata.gz: 3fa791e44bdfd3bfb19922debfcd161d62d7ce98
4
- data.tar.gz: 58b303379f9ebf84ad8dc93584967abef46da482
3
+ metadata.gz: d4626664836143aaf78bf2b5b3484ba7da329a7d
4
+ data.tar.gz: 70758012561218a831754e3a6f85678f92da35c7
5
5
  SHA512:
6
- metadata.gz: b914237f554c1a02846e2fbcd0c3b563b9614d53a3d3f92835e09578567083340d608afcb7a122da6bd570b9daf22c4bfb064b12f73eb9735d6f35463d45766b
7
- data.tar.gz: a7c5cf857dc8a32d617e6cea906135c9995fd726aa37d0ce04f16d0c67f38da9cbf7ddb4203b788e57624a425e991e18cc5fc70bb212b049b5f40a92c51fdc4c
6
+ metadata.gz: e4fe0941c2ce6d10a1cf60950bd4742a78a6cb3fd3f5a17701932b1b35ec95c177637eddcd9caf75a0ad19ff872252266dda004c028d7cc254d2d247bd3b7c50
7
+ data.tar.gz: d021d2ebc2314c817889df412c77fa2718433b4f314a6066a6a74b503620f8512e0e99f31c767d03fbfb7e4d83750f379391d09c1519df392d7efe2d156d5ef9
@@ -8,6 +8,8 @@ require 'apill/responses/invalid_subdomain_response'
8
8
  module Apill
9
9
  module Middleware
10
10
  class ApiRequest
11
+ JSON_API_MIME_TYPE_PATTERN = %r{application/vnd\.api\+json(?=\z|;)}
12
+
11
13
  def initialize(app)
12
14
  @app = app
13
15
  end
@@ -22,10 +24,10 @@ class ApiRequest
22
24
  Matchers::AcceptHeaderMatcher.new.matches?(env)
23
25
 
24
26
  env['QUERY_STRING'] = Parameters.process(env['QUERY_STRING'])
25
-
26
- if env['CONTENT_TYPE'] == 'application/vnd.api+json'
27
- env['CONTENT_TYPE'] = 'application/json'
28
- end
27
+ env['CONTENT_TYPE'] = env['CONTENT_TYPE'].
28
+ to_s.
29
+ gsub! JSON_API_MIME_TYPE_PATTERN,
30
+ 'application/json'
29
31
 
30
32
  @app.call(env)
31
33
  else
data/lib/apill/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apill
2
- VERSION = '3.1.2'
2
+ VERSION = '3.1.3'
3
3
  end
@@ -143,6 +143,42 @@ describe ApiRequest, singletons: HumanError::Configuration do
143
143
  'nice_to_meet=you-bob&' \
144
144
  'hows_the_weather=today-bob'
145
145
  end
146
+
147
+ it 'properly converts the content type for Rails when it is the only one' do
148
+ api_request_middleware = ApiRequest.new(app)
149
+
150
+ request = {
151
+ 'CONTENT_TYPE' => 'application/vnd.api+json',
152
+ 'HTTP_HOST' => 'matrix.example.com',
153
+ 'HTTP_ACCEPT' => '',
154
+ 'QUERY_STRING' => '',
155
+ }
156
+
157
+ allow(app).to receive(:call)
158
+
159
+ _response = api_request_middleware.call(request)
160
+
161
+ expect(app).to have_received(:call).
162
+ with(a_hash_including('CONTENT_TYPE' => 'application/json'))
163
+ end
164
+
165
+ it 'properly converts the content type for Rails when it is not the only one' do
166
+ api_request_middleware = ApiRequest.new(app)
167
+
168
+ request = {
169
+ 'CONTENT_TYPE' => 'application/vnd.api+json;other',
170
+ 'HTTP_HOST' => 'matrix.example.com',
171
+ 'HTTP_ACCEPT' => '',
172
+ 'QUERY_STRING' => '',
173
+ }
174
+
175
+ allow(app).to receive(:call)
176
+
177
+ _response = api_request_middleware.call(request)
178
+
179
+ expect(app).to have_received(:call).
180
+ with(a_hash_including('CONTENT_TYPE' => 'application/json;other'))
181
+ end
146
182
  end
147
183
  end
148
184
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apill
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jfelchner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-22 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: human_error
@@ -147,3 +147,4 @@ test_files:
147
147
  - spec/apill/resource/processors/indexing_spec.rb
148
148
  - spec/apill/resource/processors/paging_spec.rb
149
149
  - spec/apill/resource/processors/sorting_spec.rb
150
+ has_rdoc: