/
app_update_spec.rb
72 lines (58 loc) · 2.07 KB
/
app_update_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'spec_helper'
require 'actions/app_update'
module VCAP::CloudController
describe AppUpdate do
let(:app_update) { AppUpdate }
let(:app_model) { AppModel.make }
describe '#update' do
context 'when the desired_droplet does not exist' do
let(:message) { { 'desired_droplet_guid' => 'not_a_guid' } }
it 'raises a DropletNotFound exception' do
expect {
app_update.update(app_model, message)
}.to raise_error(AppUpdate::DropletNotFound)
end
end
context 'when the desired_droplet exists' do
let(:droplet) { DropletModel.make }
let(:droplet_guid) { droplet.guid }
let(:message) { { 'desired_droplet_guid' => droplet_guid } }
context 'the droplet is not associated with the app' do
it 'raises a DropletNotFound exception' do
expect {
app_update.update(app_model, message)
}.to raise_error(AppUpdate::DropletNotFound)
end
end
context 'the droplet is associated with the app' do
before do
app_model.add_droplet_by_guid(droplet_guid)
end
it 'sets the desired droplet guid' do
updated_app = app_update.update(app_model, message)
expect(updated_app.desired_droplet_guid).to eq(droplet_guid)
end
end
end
context 'when given a new name' do
let(:name) { 'new name' }
let(:message) { { 'name' => name } }
it 'updates the app name' do
app_update.update(app_model, message)
app_model.reload
expect(app_model.name).to eq(name)
end
end
context 'when the app is invalid' do
let(:name) { 'new name' }
let(:message) { { 'name' => name } }
before do
allow(app_model).to receive(:save).and_raise(Sequel::ValidationFailed.new('something'))
end
it 'raises an invalid app error' do
expect { app_update.update(app_model, message) }.to raise_error(AppUpdate::InvalidApp)
end
end
end
end
end