-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathstack_delete_spec.rb
More file actions
82 lines (70 loc) · 2.67 KB
/
stack_delete_spec.rb
File metadata and controls
82 lines (70 loc) · 2.67 KB
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
73
74
75
76
77
78
79
80
81
82
require 'spec_helper'
require 'actions/stack_delete'
module VCAP::CloudController
RSpec.describe StackDelete do
let(:user) { User.make }
let(:user_email) { 'user@example.com' }
let(:user_audit_info) { UserAuditInfo.new(user_guid: user.guid, user_email: user_email) }
subject(:stack_delete) { StackDelete.new(user_audit_info) }
describe '#delete' do
context 'when the stack exists' do
let!(:stack) { Stack.make }
it 'deletes the stack record' do
expect do
stack_delete.delete(stack)
end.to change(Stack, :count).by(-1)
expect { stack.refresh }.to raise_error(Sequel::Error, 'Record not found')
end
it 'creates an audit event' do
stack_guid = stack.guid
stack_name = stack.name
stack_delete.delete(stack)
expect(VCAP::CloudController::Event.count).to eq(1)
stack_delete_event = VCAP::CloudController::Event.find(type: 'audit.stack.delete')
expect(stack_delete_event).to exist
expect(stack_delete_event.values).to include(
type: 'audit.stack.delete',
actor: user_audit_info.user_guid,
actor_type: 'user',
actor_name: user_audit_info.user_email,
actee: stack_guid,
actee_type: 'stack',
actee_name: stack_name,
space_guid: '',
organization_guid: ''
)
expect(stack_delete_event.metadata).to eq({})
expect(stack_delete_event.timestamp).to be
end
it 'deletes associated labels' do
label = StackLabelModel.make(resource_guid: stack.guid, key_name: 'test1', value: 'bommel')
expect do
stack_delete.delete(stack)
end.to change(StackLabelModel, :count).by(-1)
expect(label).not_to exist
expect(stack).not_to exist
end
it 'deletes associated annotations' do
annotation = StackAnnotationModel.make(resource_guid: stack.guid, key_name: 'test1', value: 'bommel')
expect do
stack_delete.delete(stack)
end.to change(StackAnnotationModel, :count).by(-1)
expect(annotation).not_to exist
expect(stack).not_to exist
end
context 'when there are apps associated with the stack' do
let!(:app) { AppModel.make }
before do
stack.apps << app
end
it 'does not delete the stack and raises an error' do
expect do
stack_delete.delete(stack)
end.to raise_error(Stack::AppsStillPresentError)
expect(stack).to exist
end
end
end
end
end
end