@@ -7,6 +7,7 @@ module VCAP::CloudController
7
7
let ( :route ) { Route . make domain : SharedDomain . make , space : original_owning_space }
8
8
let ( :original_owning_space ) { Space . make name : 'original_owning_space' }
9
9
let ( :target_space ) { Space . make name : 'target_space' }
10
+ let ( :target_space_dup_name ) { Space . make name : 'original_owning_space' }
10
11
let ( :shared_space ) { Space . make name : 'shared_space' }
11
12
let ( :user_audit_info ) { UserAuditInfo . new ( user_guid :
'user-guid-1' , user_email :
'[email protected] ' ) }
12
13
@@ -17,7 +18,7 @@ module VCAP::CloudController
17
18
18
19
it 'makes the target space the new owner' do
19
20
RouteTransferOwner . transfer ( route , target_space , user_audit_info )
20
- expect ( route . space . name ) . to eq target_space . name
21
+ expect ( route . space . id ) . to eq target_space . id
21
22
end
22
23
23
24
context 'route was previously shared with the target space' do
@@ -26,25 +27,32 @@ module VCAP::CloudController
26
27
end
27
28
28
29
it 'removes the target space from the list of shared spaces' do
29
- expect ( route . shared_spaces . map ( &:name ) ) . to include target_space . name
30
+ expect ( route . shared_spaces . map ( &:id ) ) . to include target_space . id
30
31
RouteTransferOwner . transfer ( route , target_space , user_audit_info )
31
32
route . reload
32
- expect ( route . shared_spaces . map ( &:name ) ) . not_to include target_space . name
33
+ expect ( route . shared_spaces . map ( &:id ) ) . not_to include target_space . id
33
34
end
34
35
end
35
36
36
37
it 'shares the route with the original owning space' do
37
- expect ( route . shared_spaces . map ( &:name ) ) . not_to include original_owning_space . name
38
+ expect ( route . shared_spaces . map ( &:id ) ) . not_to include original_owning_space . id
38
39
RouteTransferOwner . transfer ( route , target_space , user_audit_info )
39
40
route . reload
40
- expect ( route . shared_spaces . map ( &:name ) ) . to include original_owning_space . name
41
+ expect ( route . shared_spaces . map ( &:id ) ) . to include original_owning_space . id
41
42
end
42
43
43
44
context 'target space is already the owning space' do
44
45
it 'does nothing and succeeds' do
45
46
expect { RouteTransferOwner . transfer ( route , original_owning_space , user_audit_info ) } . not_to raise_error
46
- expect ( route . shared_spaces . map ( &:name ) ) . not_to include original_owning_space . name
47
- expect ( route . space . name ) . to eq original_owning_space . name
47
+ expect ( route . shared_spaces . map ( &:id ) ) . not_to include original_owning_space . id
48
+ expect ( route . space . id ) . to eq original_owning_space . id
49
+ end
50
+ end
51
+
52
+ context 'target space has the same name as the owning space' do
53
+ it 'makes the target space with the same name the new owner' do
54
+ RouteTransferOwner . transfer ( route , target_space_dup_name , user_audit_info )
55
+ expect ( route . space . id ) . to eq target_space_dup_name . id
48
56
end
49
57
end
50
58
@@ -65,25 +73,25 @@ module VCAP::CloudController
65
73
expect_any_instance_of ( Repositories ::RouteEventRepository ) . not_to receive ( :record_route_transfer_owner ) . with (
66
74
route , user_audit_info , original_owning_space , target_space . guid
67
75
)
68
- expect ( route . space . name ) . to eq original_owning_space . name
76
+ expect ( route . space . id ) . to eq original_owning_space . id
69
77
expect do
70
78
RouteTransferOwner . transfer ( route , target_space , user_audit_info )
71
79
end . to raise_error ( 'db failure' )
72
80
route . reload
73
- expect ( route . space . name ) . to eq original_owning_space . name
81
+ expect ( route . space . id ) . to eq original_owning_space . id
74
82
end
75
83
76
84
it 'does not change the shared spaces' do
77
85
expect_any_instance_of ( Repositories ::RouteEventRepository ) . not_to receive ( :record_route_transfer_owner ) . with (
78
86
route , user_audit_info , original_owning_space , target_space . guid
79
87
)
80
88
expect ( route . shared_spaces . length ) . to eq 1
81
- expect ( route . shared_spaces . map ( &:name ) ) . to include shared_space . name
89
+ expect ( route . shared_spaces . map ( &:id ) ) . to include shared_space . id
82
90
expect do
83
91
RouteTransferOwner . transfer ( route , target_space , user_audit_info )
84
92
end . to raise_error ( 'db failure' )
85
93
route . reload
86
- expect ( route . shared_spaces . map ( &:name ) ) . to include shared_space . name
94
+ expect ( route . shared_spaces . map ( &:id ) ) . to include shared_space . id
87
95
expect ( route . shared_spaces . length ) . to eq 1
88
96
end
89
97
end
0 commit comments