flapjack-diner 2.0.0.pre.alpha.3 → 2.0.0

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -10
  3. data/README.md +165 -272
  4. data/flapjack-diner.gemspec +1 -1
  5. data/lib/flapjack-diner.rb +54 -25
  6. data/lib/flapjack-diner/argument_validator.rb +0 -17
  7. data/lib/flapjack-diner/configuration.rb +417 -0
  8. data/lib/flapjack-diner/log_formatter.rb +22 -0
  9. data/lib/flapjack-diner/query.rb +114 -0
  10. data/lib/flapjack-diner/relationships.rb +180 -0
  11. data/lib/flapjack-diner/request.rb +280 -0
  12. data/lib/flapjack-diner/resources.rb +64 -0
  13. data/lib/flapjack-diner/response.rb +91 -0
  14. data/lib/flapjack-diner/tools.rb +46 -456
  15. data/lib/flapjack-diner/utility.rb +16 -0
  16. data/lib/flapjack-diner/version.rb +1 -1
  17. data/spec/flapjack-diner_spec.rb +9 -18
  18. data/spec/{resources/relationships_spec.rb → relationships_spec.rb} +75 -29
  19. data/spec/resources/checks_spec.rb +7 -7
  20. data/spec/resources/contacts_spec.rb +21 -19
  21. data/spec/resources/events_spec.rb +13 -13
  22. data/spec/resources/maintenance_periods_spec.rb +3 -3
  23. data/spec/resources/media_spec.rb +3 -3
  24. data/spec/resources/metrics_spec.rb +1 -1
  25. data/spec/resources/rules_spec.rb +278 -0
  26. data/spec/resources/states_spec.rb +1 -1
  27. data/spec/resources/statistics_spec.rb +1 -1
  28. data/spec/resources/tags_spec.rb +75 -19
  29. data/spec/support/fixture_data.rb +57 -98
  30. metadata +21 -29
  31. data/.rubocop.yml +0 -21
  32. data/.rubocop_todo.yml +0 -135
  33. data/lib/flapjack-diner/resources/acceptors.rb +0 -77
  34. data/lib/flapjack-diner/resources/checks.rb +0 -52
  35. data/lib/flapjack-diner/resources/contacts.rb +0 -54
  36. data/lib/flapjack-diner/resources/events.rb +0 -54
  37. data/lib/flapjack-diner/resources/maintenance_periods.rb +0 -76
  38. data/lib/flapjack-diner/resources/media.rb +0 -75
  39. data/lib/flapjack-diner/resources/metrics.rb +0 -23
  40. data/lib/flapjack-diner/resources/rejectors.rb +0 -77
  41. data/lib/flapjack-diner/resources/relationships.rb +0 -314
  42. data/lib/flapjack-diner/resources/states.rb +0 -24
  43. data/lib/flapjack-diner/resources/statistics.rb +0 -24
  44. data/lib/flapjack-diner/resources/tags.rb +0 -47
  45. data/spec/resources/acceptors_spec.rb +0 -278
  46. data/spec/resources/rejectors_spec.rb +0 -278
@@ -0,0 +1,16 @@
1
+ module Flapjack
2
+ module Diner
3
+ module Utility
4
+ def self.symbolize(obj)
5
+ case obj
6
+ when Hash
7
+ obj.each_with_object({}) {|(k, v), a| a[k.to_sym] = symbolize(v) }
8
+ when Array
9
+ obj.each_with_object([]) {|e, a| a << symbolize(e) }
10
+ else
11
+ obj
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module Flapjack
2
2
  module Diner
3
- VERSION = '2.0.0-alpha.3'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
@@ -3,8 +3,6 @@ require 'flapjack-diner'
3
3
 
4
4
  describe Flapjack::Diner do
5
5
 
6
- # include_context 'fixture data'
7
-
8
6
  let(:server) { 'flapjack.com' }
9
7
 
10
8
  let(:time) { Time.now }
@@ -18,9 +16,9 @@ describe Flapjack::Diner do
18
16
  WebMock.reset!
19
17
  end
20
18
 
21
- context 'argument parsing' do
19
+ # context 'argument parsing' do
22
20
 
23
- end
21
+ # end
24
22
 
25
23
  context 'keys as strings' do
26
24
 
@@ -41,8 +39,8 @@ describe Flapjack::Diner do
41
39
  expect(result).not_to be_nil
42
40
  expect(result).to be_an_instance_of(Array)
43
41
  expect(result.length).to be(1)
44
- expect(result[0]).to be_an_instance_of(Hash)
45
- expect(result[0]).to have_key('id')
42
+ expect(result.first).to be_an_instance_of(Hash)
43
+ expect(result.first).to have_key('id')
46
44
  end
47
45
 
48
46
  end
@@ -60,9 +58,7 @@ describe Flapjack::Diner do
60
58
  req = stub_request(:get, "http://#{server}/contacts").
61
59
  to_return(:body => response)
62
60
 
63
- expect(logger).to receive(:info).with("GET http://#{server}/contacts")
64
- expect(logger).to receive(:info).with(" Response Code: 200")
65
- expect(logger).to receive(:info).with(" Response Body: #{response}")
61
+ expect(logger).to receive(:info).with(%r{\[Flapjack::Diner\] \[[^\]]+\] 200 "GET /contacts" - $})
66
62
 
67
63
  result = Flapjack::Diner.contacts
68
64
  expect(req).to have_been_requested
@@ -82,10 +78,8 @@ describe Flapjack::Diner do
82
78
  response = {:data => resp_data}.to_json
83
79
  req = stub_request(:post, "http://#{server}/test_notifications").
84
80
  to_return(:status => 201, :body => response)
85
- expect(logger).to receive(:info).with("POST http://#{server}/test_notifications\n" +
86
- " Body: {:data=>#{req_data.inspect}}")
87
- expect(logger).to receive(:info).with(" Response Code: 201")
88
- expect(logger).to receive(:info).with(" Response Body: #{response}")
81
+
82
+ expect(logger).to receive(:info).with(%r{\[Flapjack::Diner\] \[[^\]]+\] 201 "POST /test_notifications" - $})
89
83
 
90
84
  result = Flapjack::Diner.create_test_notifications(test_notification_data.merge(:check => check_data[:id]))
91
85
  expect(req).to have_been_requested
@@ -96,8 +90,8 @@ describe Flapjack::Diner do
96
90
  req = stub_request(:delete, "http://#{server}/scheduled_maintenances/#{scheduled_maintenance_data[:id]}").
97
91
  to_return(:status => 204)
98
92
 
99
- expect(logger).to receive(:info).with("DELETE http://#{server}/scheduled_maintenances/#{scheduled_maintenance_data[:id]}")
100
- expect(logger).to receive(:info).with(" Response Code: 204")
93
+ expect(logger).to receive(:info).
94
+ with(%r{\[Flapjack::Diner\] \[[^\]]+\] 204 "DELETE /scheduled_maintenances/#{scheduled_maintenance_data[:id]}" - $})
101
95
 
102
96
  result = Flapjack::Diner.delete_scheduled_maintenances(scheduled_maintenance_data[:id])
103
97
  expect(req).to have_been_requested
@@ -107,7 +101,6 @@ describe Flapjack::Diner do
107
101
  end
108
102
 
109
103
  context "problems" do
110
-
111
104
  it "raises an exception on network failure" do
112
105
  req = stub_request(:get, "http://#{server}/contacts").to_timeout
113
106
 
@@ -145,7 +138,5 @@ describe Flapjack::Diner do
145
138
  }.to raise_error(ArgumentError)
146
139
  expect(req).not_to have_been_requested
147
140
  end
148
-
149
141
  end
150
-
151
142
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::Relationships, :pact => true do
4
+ describe Flapjack::Diner::Relationships, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -13,11 +13,11 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
13
13
  upon_receiving("a POST request adding a tag to a check").
14
14
  with(:method => :post, :path => "/checks/#{check_data[:id]}/relationships/tags",
15
15
  :headers => {'Content-Type' => 'application/vnd.api+json'},
16
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]}).
16
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]}).
17
17
  will_respond_with(:status => 204,
18
18
  :body => '')
19
19
 
20
- result = Flapjack::Diner.create_check_link_tags(check_data[:id], tag_data[:name])
20
+ result = Flapjack::Diner.create_check_link_tags(check_data[:id], tag_data[:id])
21
21
  expect(result).to be true
22
22
  end
23
23
 
@@ -26,13 +26,13 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
26
26
  upon_receiving("a POST request adding two tags to a check").
27
27
  with(:method => :post, :path => "/checks/#{check_data[:id]}/relationships/tags",
28
28
  :headers => {'Content-Type' => 'application/vnd.api+json'},
29
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'},
30
- {:id => tag_2_data[:name], :type => 'tag'}]}).
29
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'},
30
+ {:id => tag_2_data[:id], :type => 'tag'}]}).
31
31
  will_respond_with(:status => 204,
32
32
  :body => '')
33
33
 
34
34
  result = Flapjack::Diner.create_check_link_tags(check_data[:id],
35
- tag_data[:name], tag_2_data[:name])
35
+ tag_data[:id], tag_2_data[:id])
36
36
  expect(result).to be true
37
37
  end
38
38
 
@@ -43,15 +43,15 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
43
43
  will_respond_with(
44
44
  :status => 200,
45
45
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
46
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]})
46
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]})
47
47
 
48
48
  result = Flapjack::Diner.check_link_tags(check_data[:id])
49
- expect(result).to eq([{:id => tag_data[:name], :type => 'tag'}])
49
+ expect(result).to eq([{:id => tag_data[:id], :type => 'tag'}])
50
50
  end
51
51
 
52
52
  it 'gets tags for a check with full tag records' do
53
53
  included_data = [
54
- tag_json(tag_data).merge(:relationships => tag_rel(tag_data))
54
+ tag_json(tag_data)
55
55
  ]
56
56
 
57
57
  flapjack.given("a check with a tag exists").
@@ -62,35 +62,37 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
62
62
  will_respond_with(
63
63
  :status => 200,
64
64
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
65
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'}],
65
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'}],
66
66
  :included => included_data})
67
67
 
68
68
  result = Flapjack::Diner.check_link_tags(check_data[:id], :include => 'tags')
69
- expect(result).to eq([{:id => tag_data[:name], :type => 'tag'}])
70
- expect(Flapjack::Diner.context[:included]).to eq([resultify(included_data[0])])
69
+ expect(result).to eq([{:id => tag_data[:id], :type => 'tag'}])
70
+ expect(Flapjack::Diner.context[:included]).to eq('tag' => {tag_data[:id] => resultify(included_data[0])})
71
71
  end
72
72
 
73
73
  it 'gets tags for a check with full tag and rule record' do
74
74
  included_data = [
75
- tag_json(tag_data).merge(:relationships => tag_rel(tag_data)),
76
- acceptor_json(acceptor_data).merge(:relationships => acceptor_rel(acceptor_data))
75
+ tag_json(tag_data),
76
+ rule_json(rule_data)
77
77
  ]
78
78
 
79
- flapjack.given("a check with a tag and an acceptor exists").
80
- upon_receiving("a GET request for all tags on a check, with full tag and acceptor records").
79
+ flapjack.given("a check with a tag and a rule exists").
80
+ upon_receiving("a GET request for all tags on a check, with full tag and rule records").
81
81
  with(:method => :get,
82
82
  :path => "/checks/#{check_data[:id]}/tags",
83
- :query => 'include=tags.acceptors').
83
+ :query => 'include=tags.rules').
84
84
  will_respond_with(
85
85
  :status => 200,
86
86
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
87
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'}],
87
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'}],
88
88
  :included => included_data})
89
89
 
90
- result = Flapjack::Diner.check_link_tags(check_data[:id], :include => 'acceptors')
91
- expect(result).to eq([{:id => tag_data[:name], :type => 'tag'}])
92
- expect(Flapjack::Diner.context[:included]).to eq([resultify(included_data[0]),
93
- resultify(included_data[1])])
90
+ result = Flapjack::Diner.check_link_tags(check_data[:id], :include => 'rules')
91
+ expect(result).to eq([{:id => tag_data[:id], :type => 'tag'}])
92
+ expect(Flapjack::Diner.context[:included]).to eq(
93
+ 'tag' => {tag_data[:id] => resultify(included_data[0])},
94
+ 'rule' => {rule_data[:id] => resultify(included_data[1])}
95
+ )
94
96
  end
95
97
 
96
98
  it 'updates tags for a check' do
@@ -98,12 +100,12 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
98
100
  upon_receiving("a PATCH request updating tags for a check").
99
101
  with(:method => :patch, :path => "/checks/#{check_data[:id]}/relationships/tags",
100
102
  :headers => {'Content-Type' => 'application/vnd.api+json'},
101
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]}).
103
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]}).
102
104
  will_respond_with(:status => 204,
103
105
  :body => '')
104
106
 
105
107
  result = Flapjack::Diner.update_check_link_tags(check_data[:id],
106
- tag_data[:name])
108
+ tag_data[:id])
107
109
  expect(result).to be true
108
110
  end
109
111
 
@@ -125,12 +127,12 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
125
127
  upon_receiving("a DELETE request deleting a tag from a check").
126
128
  with(:method => :delete, :path => "/checks/#{check_data[:id]}/relationships/tags",
127
129
  :headers => {'Content-Type' => 'application/vnd.api+json'},
128
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'}]}).
130
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'}]}).
129
131
  will_respond_with(:status => 204,
130
132
  :body => '')
131
133
 
132
134
  result = Flapjack::Diner.delete_check_link_tags(check_data[:id],
133
- tag_data[:name])
135
+ tag_data[:id])
134
136
  expect(result).to be true
135
137
  end
136
138
 
@@ -139,13 +141,13 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
139
141
  upon_receiving("a DELETE request deleting two tags from a check").
140
142
  with(:method => :delete, :path => "/checks/#{check_data[:id]}/relationships/tags",
141
143
  :headers => {'Content-Type' => 'application/vnd.api+json'},
142
- :body => {:data => [{:id => tag_data[:name], :type => 'tag'},
143
- {:id => tag_2_data[:name], :type => 'tag'}]}).
144
+ :body => {:data => [{:id => tag_data[:id], :type => 'tag'},
145
+ {:id => tag_2_data[:id], :type => 'tag'}]}).
144
146
  will_respond_with(:status => 204,
145
147
  :body => '')
146
148
 
147
149
  result = Flapjack::Diner.delete_check_link_tags(check_data[:id],
148
- tag_data[:name], tag_2_data[:name])
150
+ tag_data[:id], tag_2_data[:id])
149
151
  expect(result).to be true
150
152
  end
151
153
 
@@ -162,4 +164,48 @@ describe Flapjack::Diner::Resources::Relationships, :pact => true do
162
164
  expect(result).to eq(:id => contact_data[:id], :type => 'contact')
163
165
  end
164
166
 
167
+ it "doesn't duplicate linked data references in included data" do
168
+ resp_check = check_json(check_data)
169
+ resp_check[:relationships] = {
170
+ :current_state => {
171
+ :data => {:type => 'state', :id => state_data[:id]}
172
+ },
173
+ :latest_notifications => {
174
+ :data => [{:type => 'state', :id => state_data[:id]}]
175
+ }
176
+ }
177
+
178
+ sd = state_data.delete_if {|k, _| [:created_at, :updated_at].include?(k)}
179
+
180
+ included_data = [
181
+ resp_check,
182
+ state_json(sd)
183
+ ]
184
+
185
+ flapjack.given("a check with a tag, current state and a latest notification exists").
186
+ upon_receiving("a GET request for a check (via tag)'s state and notifications").
187
+ with(:method => :get,
188
+ :path => "/tags/#{tag_data[:id]}/checks",
189
+ :query => 'include=checks.current_state%2Cchecks.latest_notifications').
190
+ will_respond_with(
191
+ :status => 200,
192
+ :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
193
+ :body => {
194
+ :data => [
195
+ {:id => check_data[:id], :type => 'check'},
196
+ ],
197
+ :included => included_data
198
+ })
199
+
200
+ result = Flapjack::Diner.tag_link_checks(tag_data[:id],
201
+ :include => ['checks.current_state', 'checks.latest_notifications'])
202
+ expect(result).to eq([
203
+ {:id => check_data[:id], :type => 'check'}
204
+ ])
205
+ expect(Flapjack::Diner.context[:included]).to eq(
206
+ 'check' => {check_data[:id] => resultify(resp_check)},
207
+ 'state' => {sd[:id] => resultify(state_json(sd))}
208
+ )
209
+ end
210
+
165
211
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::Checks, :pact => true do
4
+ describe Flapjack::Diner::Resources, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -55,7 +55,7 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
55
55
  req_data = check_json(check_data).merge(
56
56
  :relationships => {
57
57
  :tags => {
58
- :data => [{:type => 'tag', :id => tag_data[:name]}]
58
+ :data => [{:type => 'tag', :id => tag_data[:id]}]
59
59
  }
60
60
  }
61
61
  )
@@ -71,7 +71,7 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
71
71
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
72
72
  :body => {:data => resp_data})
73
73
 
74
- result = Flapjack::Diner.create_checks(check_data.merge(:tags => [tag_data[:name]]))
74
+ result = Flapjack::Diner.create_checks(check_data.merge(:tags => [tag_data[:id]]))
75
75
  expect(result).to eq(resultify(resp_data))
76
76
  end
77
77
 
@@ -218,7 +218,7 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
218
218
 
219
219
  result = Flapjack::Diner.checks(check_data[:id])
220
220
  expect(result).to be_nil
221
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
221
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
222
222
  :detail => "could not find Check record, id: '#{check_data[:id]}'"}])
223
223
  end
224
224
  end
@@ -277,7 +277,7 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
277
277
 
278
278
  result = Flapjack::Diner.update_checks(:id => check_data[:id], :enabled => false)
279
279
  expect(result).to be_nil
280
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
280
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
281
281
  :detail => "could not find Check record, id: '#{check_data[:id]}'"}])
282
282
  end
283
283
 
@@ -287,7 +287,7 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
287
287
  :type => 'check',
288
288
  :relationships => {
289
289
  :tags => {
290
- :data => [{:type => 'tag', :id => tag_data[:name]}]
290
+ :data => [{:type => 'tag', :id => tag_data[:id]}]
291
291
  }
292
292
  }
293
293
  }
@@ -302,7 +302,7 @@ describe Flapjack::Diner::Resources::Checks, :pact => true do
302
302
  :status => 204,
303
303
  :body => '' )
304
304
 
305
- result = Flapjack::Diner.update_checks(:id => check_data[:id], :tags => [tag_data[:name]])
305
+ result = Flapjack::Diner.update_checks(:id => check_data[:id], :tags => [tag_data[:id]])
306
306
  expect(result).to be_a(TrueClass)
307
307
  end
308
308
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack-diner'
3
3
 
4
- describe Flapjack::Diner::Resources::Contacts, :pact => true do
4
+ describe Flapjack::Diner::Resources, :pact => true do
5
5
 
6
6
  before(:each) do
7
7
  Flapjack::Diner.base_uri('localhost:19081')
@@ -70,7 +70,7 @@ describe Flapjack::Diner::Resources::Contacts, :pact => true do
70
70
 
71
71
  result = Flapjack::Diner.create_contacts(contact_data)
72
72
  expect(result).to be_nil
73
- expect(Flapjack::Diner.last_error).to eq([{:status => '409',
73
+ expect(Flapjack::Diner.error).to eq([{:status => '409',
74
74
  :detail => "Contacts already exist with the following ids: #{contact_data[:id]}"}])
75
75
  end
76
76
 
@@ -146,7 +146,7 @@ describe Flapjack::Diner::Resources::Contacts, :pact => true do
146
146
 
147
147
  result = Flapjack::Diner.contacts(contact_data[:id])
148
148
  expect(result).to be_nil
149
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
149
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
150
150
  :detail => "could not find Contact record, id: '#{contact_data[:id]}'"}])
151
151
  end
152
152
 
@@ -159,7 +159,7 @@ describe Flapjack::Diner::Resources::Contacts, :pact => true do
159
159
  resp_data[:relationships][:media][:data] = [
160
160
  {:type => 'medium', :id => email_data[:id]}
161
161
  ]
162
- resp_included = [medium_json(email_data).merge(:relationships => medium_rel(email_data))]
162
+ resp_included = [medium_json(email_data)]
163
163
 
164
164
  flapjack.given("a contact with one medium exists").
165
165
  upon_receiving("a GET request for a single contact with media").
@@ -173,39 +173,41 @@ describe Flapjack::Diner::Resources::Contacts, :pact => true do
173
173
  result = Flapjack::Diner.contacts(contact_data[:id], :include => 'media')
174
174
  expect(result).not_to be_nil
175
175
  expect(result).to eq(resultify(resp_data))
176
- expect(Flapjack::Diner.context).to eq(:included => resultify(resp_included))
176
+ expect(Flapjack::Diner.context).to eq(:included => {'medium' => {email_data[:id] => resultify(resp_included.first)}})
177
177
  end
178
178
 
179
- it 'returns a contact with media and acceptors' do
179
+ it 'returns a contact with media and rules' do
180
180
  resp_data = contact_json(contact_data).merge(:relationships => contact_rel(contact_data))
181
181
  resp_data[:relationships][:media][:data] = [
182
182
  {:type => 'medium', :id => email_data[:id]}
183
183
  ]
184
- resp_data[:relationships][:acceptors][:data] = [
185
- {:type => 'acceptor', :id => acceptor_data[:id]}
184
+ resp_data[:relationships][:rules][:data] = [
185
+ {:type => 'rule', :id => rule_data[:id]}
186
186
  ]
187
187
  resp_included = [
188
- medium_json(email_data).merge(:relationships => medium_rel(email_data)),
189
- acceptor_json(acceptor_data).merge(:relationships => acceptor_rel(acceptor_data))
188
+ medium_json(email_data),
189
+ rule_json(rule_data)
190
190
  ]
191
191
 
192
- flapjack.given("a contact with one medium and one acceptor exists").
193
- upon_receiving("a GET request for a single contact with media and acceptors").
192
+ flapjack.given("a contact with one medium and one rule exists").
193
+ upon_receiving("a GET request for a single contact with media and rules").
194
194
  with(:method => :get, :path => "/contacts/#{contact_data[:id]}",
195
- :query => 'include=media%2Cacceptors').
195
+ :query => 'include=media%2Crules').
196
196
  will_respond_with(
197
197
  :status => 200,
198
198
  :headers => {'Content-Type' => 'application/vnd.api+json; supported-ext=bulk; charset=utf-8'},
199
199
  :body => {:data => resp_data, :included => resp_included})
200
200
 
201
- result = Flapjack::Diner.contacts(contact_data[:id], :include => ['media', 'acceptors'])
201
+ result = Flapjack::Diner.contacts(contact_data[:id], :include => ['media', 'rules'])
202
202
  expect(result).not_to be_nil
203
203
  expect(result).to eq(resultify(resp_data))
204
- expect(Flapjack::Diner.context).to eq(:included => [resultify(resp_included[0]), resultify(resp_included[1])])
205
- end
204
+ expect(Flapjack::Diner.context).to eq(:included => {
205
+ 'medium' => {email_data[:id] => resultify(resp_included[0])},
206
+ 'rule' => {rule_data[:id] => resultify(resp_included[1])}
207
+ })
206
208
 
209
+ end
207
210
  end
208
-
209
211
  end
210
212
 
211
213
  context 'update' do
@@ -261,7 +263,7 @@ describe Flapjack::Diner::Resources::Contacts, :pact => true do
261
263
 
262
264
  result = Flapjack::Diner.update_contacts(:id => contact_data[:id], :name => 'Hello There')
263
265
  expect(result).to be_nil
264
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
266
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
265
267
  :detail => "could not find Contact record, id: '#{contact_data[:id]}'"}])
266
268
  end
267
269
  end
@@ -315,7 +317,7 @@ describe Flapjack::Diner::Resources::Contacts, :pact => true do
315
317
 
316
318
  result = Flapjack::Diner.delete_contacts(contact_data[:id])
317
319
  expect(result).to be_nil
318
- expect(Flapjack::Diner.last_error).to eq([{:status => '404',
320
+ expect(Flapjack::Diner.error).to eq([{:status => '404',
319
321
  :detail => "could not find Contact record, id: '#{contact_data[:id]}'"}])
320
322
  end
321
323
  end