|
5 | 5 | module VCAP::CloudController |
6 | 6 | RSpec.describe AppFeatureUpdate do |
7 | 7 | subject(:app_feature_update) { AppFeatureUpdate } |
8 | | - let(:app) { AppModel.make(enable_ssh: false, revisions_enabled: false) } |
9 | | - let(:message) { AppFeatureUpdateMessage.new(enabled: true) } |
| 8 | + let(:app) { AppModel.make(enable_ssh: false, revisions_enabled: false, service_binding_k8s_enabled: false, file_based_vcap_services_enabled: false) } |
10 | 9 |
|
11 | 10 | describe '.update' do |
| 11 | + let(:message) { AppFeatureUpdateMessage.new(enabled: true) } |
| 12 | + |
12 | 13 | context 'when the feature name is ssh' do |
13 | 14 | it 'updates the enable_ssh column on the app' do |
14 | 15 | expect do |
@@ -41,5 +42,85 @@ module VCAP::CloudController |
41 | 42 | end |
42 | 43 | end |
43 | 44 | end |
| 45 | + |
| 46 | + describe '.bulk_update' do |
| 47 | + let(:features) do |
| 48 | + { |
| 49 | + ssh: false, |
| 50 | + revisions: false, |
| 51 | + 'service-binding-k8s': false, |
| 52 | + 'file-based-vcap-services': false |
| 53 | + } |
| 54 | + end |
| 55 | + let(:message) { ManifestFeaturesUpdateMessage.new(features:) } |
| 56 | + |
| 57 | + context 'when the ssh feature is specified' do |
| 58 | + before do |
| 59 | + features[:ssh] = true |
| 60 | + end |
| 61 | + |
| 62 | + it 'updates the enable_ssh column on the app' do |
| 63 | + expect do |
| 64 | + AppFeatureUpdate.bulk_update(app, message) |
| 65 | + end.to change { app.reload.enable_ssh }.to(true) |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + context 'when the revisions feature is specified' do |
| 70 | + before do |
| 71 | + features[:revisions] = true |
| 72 | + end |
| 73 | + |
| 74 | + it 'updates the revisions_enabled column on the app' do |
| 75 | + expect do |
| 76 | + AppFeatureUpdate.bulk_update(app, message) |
| 77 | + end.to change { app.reload.revisions_enabled }.to(true) |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + context 'when the service-binding-k8s feature is specified' do |
| 82 | + before do |
| 83 | + features[:'service-binding-k8s'] = true |
| 84 | + end |
| 85 | + |
| 86 | + it 'updates the service_binding_k8s_enabled column on the app' do |
| 87 | + expect do |
| 88 | + AppFeatureUpdate.bulk_update(app, message) |
| 89 | + end.to change { app.reload.service_binding_k8s_enabled }.to(true) |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + context 'when the file-based-vcap-services feature is specified' do |
| 94 | + before do |
| 95 | + features[:'file-based-vcap-services'] = true |
| 96 | + end |
| 97 | + |
| 98 | + it 'updates the file_based_vcap_services_enabled column on the app' do |
| 99 | + expect do |
| 100 | + AppFeatureUpdate.bulk_update(app, message) |
| 101 | + end.to change { app.reload.file_based_vcap_services_enabled }.to(true) |
| 102 | + end |
| 103 | + end |
| 104 | + |
| 105 | + context 'when multiple features are specified' do |
| 106 | + before do |
| 107 | + features[:ssh] = true |
| 108 | + features[:'service-binding-k8s'] = true |
| 109 | + end |
| 110 | + |
| 111 | + it 'updates the corresponding columns in a single database call' do |
| 112 | + expect(app.enable_ssh).to be(false) |
| 113 | + expect(app.service_binding_k8s_enabled).to be(false) |
| 114 | + |
| 115 | + expect do |
| 116 | + AppFeatureUpdate.bulk_update(app, message) |
| 117 | + end.to have_queried_db_times(/update .apps./i, 1) |
| 118 | + |
| 119 | + app.reload |
| 120 | + expect(app.enable_ssh).to be(true) |
| 121 | + expect(app.service_binding_k8s_enabled).to be(true) |
| 122 | + end |
| 123 | + end |
| 124 | + end |
44 | 125 | end |
45 | 126 | end |
0 commit comments