Skip to content

Commit 543d248

Browse files
committed
Can't move routes to other orgs if the space has the same name as owner space
Compare the space id instead of name for route transfer
1 parent 3e1d2f4 commit 543d248

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

app/actions/route_transfer_owner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module VCAP::CloudController
44
class RouteTransferOwner
55
class << self
66
def transfer(route, target_space, user_audit_info)
7-
return route if target_space.name == route.space.name
7+
return route if target_space.id == route.space.id
88

99
original_space = route.space
1010
Route.db.transaction do

spec/unit/actions/route_transfer_owner_spec.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module VCAP::CloudController
77
let(:route) { Route.make domain: SharedDomain.make, space: original_owning_space }
88
let(:original_owning_space) { Space.make name: 'original_owning_space' }
99
let(:target_space) { Space.make name: 'target_space' }
10+
let(:target_space_dup_name) { Space.make name: 'original_owning_space' }
1011
let(:shared_space) { Space.make name: 'shared_space' }
1112
let(:user_audit_info) { UserAuditInfo.new(user_guid: 'user-guid-1', user_email: '[email protected]') }
1213

@@ -17,7 +18,7 @@ module VCAP::CloudController
1718

1819
it 'makes the target space the new owner' do
1920
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
2122
end
2223

2324
context 'route was previously shared with the target space' do
@@ -26,25 +27,32 @@ module VCAP::CloudController
2627
end
2728

2829
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
3031
RouteTransferOwner.transfer(route, target_space, user_audit_info)
3132
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
3334
end
3435
end
3536

3637
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
3839
RouteTransferOwner.transfer(route, target_space, user_audit_info)
3940
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
4142
end
4243

4344
context 'target space is already the owning space' do
4445
it 'does nothing and succeeds' do
4546
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.id
4856
end
4957
end
5058

@@ -65,25 +73,25 @@ module VCAP::CloudController
6573
expect_any_instance_of(Repositories::RouteEventRepository).not_to receive(:record_route_transfer_owner).with(
6674
route, user_audit_info, original_owning_space, target_space.guid
6775
)
68-
expect(route.space.name).to eq original_owning_space.name
76+
expect(route.space.id).to eq original_owning_space.id
6977
expect do
7078
RouteTransferOwner.transfer(route, target_space, user_audit_info)
7179
end.to raise_error('db failure')
7280
route.reload
73-
expect(route.space.name).to eq original_owning_space.name
81+
expect(route.space.id).to eq original_owning_space.id
7482
end
7583

7684
it 'does not change the shared spaces' do
7785
expect_any_instance_of(Repositories::RouteEventRepository).not_to receive(:record_route_transfer_owner).with(
7886
route, user_audit_info, original_owning_space, target_space.guid
7987
)
8088
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
8290
expect do
8391
RouteTransferOwner.transfer(route, target_space, user_audit_info)
8492
end.to raise_error('db failure')
8593
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
8795
expect(route.shared_spaces.length).to eq 1
8896
end
8997
end

0 commit comments

Comments
 (0)