jsonapi-consumer 0.1.0.pre.1 → 0.1.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: caaedec2074ee4aafca24c5afea80f6ae9422c49
4
- data.tar.gz: f38a0c0d33691186de1b2ecf24603a0132a52925
3
+ metadata.gz: 1c44382ce45f9e6375af4a33e129302baae53d16
4
+ data.tar.gz: 47acb47a6f0e799782c7d6ed6923da2cfd69735c
5
5
  SHA512:
6
- metadata.gz: 4326500565a0f142502c2db9ac40084875f3345942e97ea7fe5ab3b505d9193e8289f49fd481aaffb836e929bb0aa2a9f50aec27f5a162df50e2c7b9e73a2a90
7
- data.tar.gz: 06ab89c5bddfe9bfad758b1ddf4a21d6ff3c74ff6dbeb01684f03b8a714a740dc1f408c3322e339b03baef315df42593cc7c3f690af08d7780bc590999d1b0b1
6
+ metadata.gz: d2542085168cdf9a67f53b41d4fa0a8543b681e8703b828e72cc9c299732120c65eec114238bfbbff24f55e80348b10c1f9551cd79ce01e8a18341e0b4829f4c
7
+ data.tar.gz: 7aafc9bb7f7b25b69465ab86787af082d1bd38fdf7c1451063b6695d39a564ae99fec6abcbb209755095e5f8fdd7bdde3c75826410521c7c319f27ecfe16ed39
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
 
2
- 0.1.0.pre (unreleased) / 2014-10-19
2
+ 0.1.0.pre.2 / 2014-11-11
3
+ ==================
4
+
5
+ * Set Accept header properly to 'application/json'
6
+ * Add spec for Resource.all with params
7
+
8
+ 0.1.0.pre.1 / 2014-10-19
3
9
  ==================
4
10
 
5
11
  * Add yarddoc to associations_concern
@@ -19,6 +19,7 @@ require "jsonapi/consumer/errors"
19
19
  require "jsonapi/consumer/middleware"
20
20
  require "jsonapi/consumer/middleware/parse_json"
21
21
  require "jsonapi/consumer/middleware/raise_error"
22
+ require "jsonapi/consumer/middleware/request_headers"
22
23
  require "jsonapi/consumer/middleware/request_timeout"
23
24
 
24
25
  require "jsonapi/consumer/parser"
@@ -0,0 +1,20 @@
1
+ module JSONAPI::Consumer::Middleware
2
+ class RequestHeaders < Faraday::Middleware
3
+
4
+ def initialize(app, headers)
5
+ super(app)
6
+ @headers = headers
7
+ end
8
+
9
+ def call(env)
10
+ @headers.each do |header, value|
11
+ env[:request_headers][header] ||= value
12
+ end
13
+ @app.call(env)
14
+ end
15
+
16
+ end
17
+ end
18
+
19
+ Faraday::Request.register_middleware request_headers: JSONAPI::Consumer::Middleware::RequestHeaders
20
+
@@ -27,6 +27,7 @@ module JSONAPI::Consumer
27
27
  @connection ||= begin
28
28
  Faraday.new(url: self.host, ssl: self.ssl) do |conn|
29
29
  conn.request :json
30
+ conn.request :request_headers, accept: "application/json"
30
31
 
31
32
  conn.use Middleware::RequestTimeout
32
33
  conn.use Middleware::ParseJson
@@ -1,5 +1,5 @@
1
1
  module Jsonapi
2
2
  module Consumer
3
- VERSION = "0.1.0.pre.1"
3
+ VERSION = "0.1.0.pre.2"
4
4
  end
5
5
  end
@@ -13,6 +13,7 @@ RSpec.describe 'Connection' do
13
13
  describe '.all' do
14
14
  it 'returns all results as objects' do
15
15
  stub_request(:get, "http://localhost:3000/api/records")
16
+ .with(headers: {accept: 'application/json'})
16
17
  .to_return(headers: {content_type: "application/json"}, body: {
17
18
  records: [
18
19
  {id: '1', name: "foo.example"},
@@ -27,11 +28,32 @@ RSpec.describe 'Connection' do
27
28
  record = records.first
28
29
  expect(record).to be_a(Record)
29
30
  end
31
+
32
+ it 'accepts additional params' do
33
+ stub_request(:get, "http://localhost:3000/api/records")
34
+ .with(headers: {accept: 'application/json'})
35
+ .to_return(headers: {content_type: "application/json"}, body: {
36
+ records: []
37
+ }.to_json) # This should not get called.
38
+
39
+ stub_request(:get, "http://localhost:3000/api/records?name=foo&email=bar@example.com")
40
+ .with(headers: {accept: 'application/json'})
41
+ .to_return(headers: {content_type: "application/json"}, body: {
42
+ records: [
43
+ {id: '1', name: 'bar', email: "bar.example"},
44
+ {id: '2', name: 'foo', email: "bar.example"},
45
+ ]
46
+ }.to_json)
47
+
48
+ records = test_class.all(name: 'foo', email: 'bar@example.com')
49
+ expect(records.size).to eql(2)
50
+ end
30
51
  end
31
52
 
32
53
  describe '.find' do
33
54
  it 'returns proper objects' do
34
55
  stub_request(:get, "http://localhost:3000/api/records/1")
56
+ .with(headers: {accept: 'application/json'})
35
57
  .to_return(headers: {content_type: "application/json"}, body: {
36
58
  records: [
37
59
  {id: '1', name: "foobar.example"}
@@ -51,6 +73,7 @@ RSpec.describe 'Connection' do
51
73
  describe '#save' do
52
74
  it 'can save successfully if called on a new item' do
53
75
  stub_request(:post, "http://localhost:3000/api/records")
76
+ .with(headers: {accept: 'application/json', content_type: "application/json"})
54
77
  .to_return(headers: {content_type: "application/json"}, status: 201, body: {
55
78
  records: [
56
79
  {id: '1', name: "foobar.example", created_at: "2014-10-16T18:49:40Z", updated_at: "2014-10-18T18:59:40Z"}
@@ -72,6 +95,7 @@ RSpec.describe 'Connection' do
72
95
 
73
96
  it 'can update when called on an existing item' do
74
97
  stub_request(:put, "http://localhost:3000/api/records/1")
98
+ .with(headers: {accept: 'application/json', content_type: "application/json"})
75
99
  .to_return(headers: {content_type: "application/json"}, body: {
76
100
  records: [
77
101
  {id: '1', name: "foobar.example", created_at: "2014-10-16T18:49:40Z", updated_at: "2016-10-18T18:59:40Z"}
@@ -92,6 +116,7 @@ RSpec.describe 'Connection' do
92
116
 
93
117
  it 'returns true when successful' do
94
118
  stub_request(:delete, "http://localhost:3000/api/records/1")
119
+ .with(headers: {accept: "application/json"})
95
120
  .to_return(status: 204, body: nil)
96
121
 
97
122
  expect(obj.destroy).to eql(true)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.1
4
+ version: 0.1.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -170,6 +170,7 @@ files:
170
170
  - lib/jsonapi/consumer/middleware.rb
171
171
  - lib/jsonapi/consumer/middleware/parse_json.rb
172
172
  - lib/jsonapi/consumer/middleware/raise_error.rb
173
+ - lib/jsonapi/consumer/middleware/request_headers.rb
173
174
  - lib/jsonapi/consumer/middleware/request_timeout.rb
174
175
  - lib/jsonapi/consumer/parser.rb
175
176
  - lib/jsonapi/consumer/query.rb