Skip to content

Commit 3606e35

Browse files
committed
Add/Fix tests
1 parent 625dd2b commit 3606e35

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

app/messages/route_create_message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class RouteOptions < BaseMessage
9595
register_allowed_keys %i[lb_algo]
9696
validates_with NoAdditionalKeysValidator
9797
validates :lb_algo,
98-
inclusion: { in: %w[least-connections round-robin], message: 'must be \'least-connections\' or \'round-robin\'' },
98+
inclusion: { in: %w[least-connections round-robin], message: "'%<value>s' is not a supported load-balancing algorithm" },
9999
presence: true,
100100
allow_nil: true
101101
end

app/models/runtime/route.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def options_with_serialization=(opts)
8585

8686
def options_with_serialization
8787
string = options_without_serialization
88-
return {} if string.blank?
88+
return nil if string.blank?
8989

9090
Oj.load(string)
9191
end

spec/unit/presenters/v3/route_presenter_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module VCAP::CloudController::Presenters::V3
55
RSpec.describe RoutePresenter do
66
let!(:app) { VCAP::CloudController::AppModel.make }
77
let(:space) { VCAP::CloudController::Space.make }
8+
let(:options) { { lb_algo: 'round-robin' } }
89
let(:org) { space.organization }
910
let(:route_host) { 'host' }
1011
let(:path) { '/path' }
@@ -20,7 +21,8 @@ module VCAP::CloudController::Presenters::V3
2021
host: route_host,
2122
path: path,
2223
space: space,
23-
domain: domain
24+
domain: domain,
25+
options: options
2426
)
2527
end
2628

@@ -70,6 +72,7 @@ module VCAP::CloudController::Presenters::V3
7072
expect(subject[:updated_at]).to be_a(Time)
7173
expect(subject[:host]).to eq(route_host)
7274
expect(subject[:path]).to eq(path)
75+
expect(subject[:options]).to eq('lb_algo' => 'round-robin')
7376
expect(subject[:url]).to eq("#{route.host}.#{domain.name}#{route.path}")
7477

7578
expected_destinations = [
@@ -125,6 +128,21 @@ module VCAP::CloudController::Presenters::V3
125128
end
126129
end
127130

131+
context 'when options is empty' do
132+
let(:route) do
133+
VCAP::CloudController::Route.make(
134+
host: 'foobar',
135+
path: path,
136+
space: space,
137+
domain: domain,
138+
)
139+
end
140+
141+
it 'does not output options' do
142+
expect(subject[:options]).to be_nil
143+
end
144+
end
145+
128146
context 'when there are decorators' do
129147
let(:banana_decorator) do
130148
Class.new do

0 commit comments

Comments
 (0)