Skip to content

Commit fdd3b80

Browse files
committed
Fix bool casting on mysql for service plan features
1 parent cda0403 commit fdd3b80

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎app/models/services/service_plan.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ def self.plan_ids_for_visible_service_instances(user)
161161
end
162162

163163
def bindable?
164-
return bindable unless bindable.nil?
164+
return ActiveModel::Type::Boolean.new.cast(bindable) unless bindable.nil?
165165

166166
service.bindable?
167167
end
168168

169169
def plan_updateable?
170-
return plan_updateable unless plan_updateable.nil?
170+
return ActiveModel::Type::Boolean.new.cast(plan_updateable) unless plan_updateable.nil?
171171

172172
!!service.plan_updateable
173173
end

‎spec/unit/models/services/service_plan_spec.rb‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,22 @@ module VCAP::CloudController
378378
specify { expect(service_plan).to be_bindable }
379379
end
380380
end
381+
382+
context 'when the bindable value is returned as an integer (e.g. from a UNION query)' do
383+
let(:service) { Service.make(bindable: true) }
384+
385+
it 'returns true when the integer value is 1' do
386+
service_plan = ServicePlan.make(service: service, bindable: true)
387+
allow(service_plan).to receive(:bindable).and_return(1)
388+
expect(service_plan.bindable?).to be(true)
389+
end
390+
391+
it 'returns false when the integer value is 0' do
392+
service_plan = ServicePlan.make(service: service, bindable: true)
393+
allow(service_plan).to receive(:bindable).and_return(0)
394+
expect(service_plan.bindable?).to be(false)
395+
end
396+
end
381397
end
382398

383399
describe '#plan_updateable?' do
@@ -440,6 +456,22 @@ module VCAP::CloudController
440456
specify { expect(service_plan.plan_updateable?).to be(false) }
441457
end
442458
end
459+
460+
context 'when the plan_updateable value is returned as an integer (e.g. from a UNION query)' do
461+
let(:service) { Service.make(plan_updateable: true) }
462+
463+
it 'returns true when the integer value is 1' do
464+
service_plan = ServicePlan.make(service: service, plan_updateable: true)
465+
allow(service_plan).to receive(:plan_updateable).and_return(1)
466+
expect(service_plan.plan_updateable?).to be(true)
467+
end
468+
469+
it 'returns false when the integer value is 0' do
470+
service_plan = ServicePlan.make(service: service, plan_updateable: true)
471+
allow(service_plan).to receive(:plan_updateable).and_return(0)
472+
expect(service_plan.plan_updateable?).to be(false)
473+
end
474+
end
443475
end
444476

445477
describe '#broker_space_scoped?' do

0 commit comments

Comments
 (0)