Skip to content

Commit 2af6885

Browse files
committed
Address review comments
1 parent 61493be commit 2af6885

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

app/actions/route_update.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ module VCAP::CloudController
22
class RouteUpdate
33
def update(route:, message:)
44
Route.db.transaction do
5-
route.options = route.options.symbolize_keys.merge(message.options).compact if message.requested?(:options)
6-
5+
if message.requested?(:options)
6+
route.options = route.options.symbolize_keys.merge(message.options).compact
7+
route.apps.each do |process|
8+
ProcessRouteHandler.new(process).notify_backend_of_route_update
9+
end
10+
end
711
route.save
812
MetadataUpdate.update(route, message)
9-
10-
route.apps.each do |process|
11-
ProcessRouteHandler.new(process).notify_backend_of_route_update
12-
end
1313
end
14-
1514
route
1615
end
1716
end

spec/unit/actions/route_update_spec.rb

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,16 @@ module VCAP::CloudController
4141
end
4242

4343
let(:message) { RouteUpdateMessage.new(body) }
44-
let(:space) { Space.make }
45-
let(:route) { Route.make(space:) }
44+
let(:process) { ProcessModel.make }
45+
let(:route_mapping) { RouteMappingModel.make(app: process.app) }
46+
let(:route) { route_mapping.route }
4647

4748
subject { RouteUpdate.new }
4849
describe '#update metadata' do
50+
before do
51+
expect(ProcessRouteHandler).not_to receive(:new)
52+
end
53+
4954
context 'when the route has no existing metadata' do
5055
context 'when no metadata is specified' do
5156
let(:body) do
@@ -136,6 +141,13 @@ module VCAP::CloudController
136141
end
137142

138143
describe '#update options' do
144+
let(:fake_route_handler) { instance_double(ProcessRouteHandler) }
145+
146+
before do
147+
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
148+
allow(fake_route_handler).to receive(:notify_backend_of_route_update)
149+
end
150+
139151
context 'when the route has no existing options' do
140152
context 'when no options are specified' do
141153
let(:body) do
@@ -144,17 +156,15 @@ module VCAP::CloudController
144156

145157
it 'adds no options' do
146158
expect(message).to be_valid
147-
148-
fake_route_handler = instance_double(ProcessRouteHandler)
149-
process = ProcessModelFactory.make(space: space, state: 'STARTED', diego: false)
150-
RouteMappingModel.make(app: process.app, route: route, process_type: process.type)
151-
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
152-
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
153-
154159
subject.update(route:, message:)
155160
route.reload
156161
expect(route.options).to eq({})
157162
end
163+
164+
it 'does not notifies the backend' do
165+
expect(fake_route_handler).not_to receive(:notify_backend_of_route_update)
166+
subject.update(route:, message:)
167+
end
158168
end
159169

160170
context 'when an option is specified' do
@@ -168,17 +178,15 @@ module VCAP::CloudController
168178

169179
it 'adds the route option' do
170180
expect(message).to be_valid
171-
172-
fake_route_handler = instance_double(ProcessRouteHandler)
173-
process = ProcessModelFactory.make(space: space, state: 'STARTED', diego: false)
174-
RouteMappingModel.make(app: process.app, route: route, process_type: process.type)
175-
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
176-
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
177-
178181
subject.update(route:, message:)
179182
route.reload
180183
expect(route[:options]).to eq('{"loadbalancing":"round-robin"}')
181184
end
185+
186+
it 'notifies the backend' do
187+
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
188+
subject.update(route:, message:)
189+
end
182190
end
183191
end
184192

@@ -194,17 +202,15 @@ module VCAP::CloudController
194202

195203
it 'modifies nothing' do
196204
expect(message).to be_valid
197-
198-
fake_route_handler = instance_double(ProcessRouteHandler)
199-
process = ProcessModelFactory.make(space: space, state: 'STARTED', diego: false)
200-
RouteMappingModel.make(app: process.app, route: route, process_type: process.type)
201-
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
202-
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
203-
204205
subject.update(route:, message:)
205206
route.reload
206207
expect(route.options).to include({ 'loadbalancing' => 'round-robin' })
207208
end
209+
210+
it 'does not notifies the backend' do
211+
expect(fake_route_handler).not_to receive(:notify_backend_of_route_update)
212+
subject.update(route:, message:)
213+
end
208214
end
209215

210216
context 'when an option is specified' do
@@ -218,18 +224,15 @@ module VCAP::CloudController
218224

219225
it 'updates the option' do
220226
expect(message).to be_valid
221-
222-
fake_route_handler = instance_double(ProcessRouteHandler)
223-
process = ProcessModelFactory.make(space: space, state: 'STARTED', diego: false)
224-
RouteMappingModel.make(app: process.app, route: route, process_type: process.type)
225-
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
226-
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
227-
228227
subject.update(route:, message:)
229228
route.reload
230-
231229
expect(route.options).to include({ 'loadbalancing' => 'least-connection' })
232230
end
231+
232+
it 'notifies the backend' do
233+
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
234+
subject.update(route:, message:)
235+
end
233236
end
234237

235238
context 'when the option value is set to null' do
@@ -243,17 +246,15 @@ module VCAP::CloudController
243246

244247
it 'removes this option' do
245248
expect(message).to be_valid
246-
247-
fake_route_handler = instance_double(ProcessRouteHandler)
248-
process = ProcessModelFactory.make(space: space, state: 'STARTED', diego: false)
249-
RouteMappingModel.make(app: process.app, route: route, process_type: process.type)
250-
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
251-
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
252-
253249
subject.update(route:, message:)
254250
route.reload
255251
expect(route.options).to eq({})
256252
end
253+
254+
it 'notifies the backend' do
255+
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
256+
subject.update(route:, message:)
257+
end
257258
end
258259
end
259260
end

0 commit comments

Comments
 (0)