Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/actions/route_transfer_owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module VCAP::CloudController
class RouteTransferOwner
class << self
def transfer(route, target_space, user_audit_info)
return route if target_space.name == route.space.name
return route if target_space.id == route.space.id

original_space = route.space
Route.db.transaction do
Expand Down
30 changes: 19 additions & 11 deletions spec/unit/actions/route_transfer_owner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module VCAP::CloudController
let(:route) { Route.make domain: SharedDomain.make, space: original_owning_space }
let(:original_owning_space) { Space.make name: 'original_owning_space' }
let(:target_space) { Space.make name: 'target_space' }
let(:target_space_dup_name) { Space.make name: 'original_owning_space' }
let(:shared_space) { Space.make name: 'shared_space' }
let(:user_audit_info) { UserAuditInfo.new(user_guid: 'user-guid-1', user_email: '[email protected]') }

Expand All @@ -17,7 +18,7 @@ module VCAP::CloudController

it 'makes the target space the new owner' do
RouteTransferOwner.transfer(route, target_space, user_audit_info)
expect(route.space.name).to eq target_space.name
expect(route.space.id).to eq target_space.id
end

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

it 'removes the target space from the list of shared spaces' do
expect(route.shared_spaces.map(&:name)).to include target_space.name
expect(route.shared_spaces.map(&:id)).to include target_space.id
RouteTransferOwner.transfer(route, target_space, user_audit_info)
route.reload
expect(route.shared_spaces.map(&:name)).not_to include target_space.name
expect(route.shared_spaces.map(&:id)).not_to include target_space.id
end
end

it 'shares the route with the original owning space' do
expect(route.shared_spaces.map(&:name)).not_to include original_owning_space.name
expect(route.shared_spaces.map(&:id)).not_to include original_owning_space.id
RouteTransferOwner.transfer(route, target_space, user_audit_info)
route.reload
expect(route.shared_spaces.map(&:name)).to include original_owning_space.name
expect(route.shared_spaces.map(&:id)).to include original_owning_space.id
end

context 'target space is already the owning space' do
it 'does nothing and succeeds' do
expect { RouteTransferOwner.transfer(route, original_owning_space, user_audit_info) }.not_to raise_error
expect(route.shared_spaces.map(&:name)).not_to include original_owning_space.name
expect(route.space.name).to eq original_owning_space.name
expect(route.shared_spaces.map(&:id)).not_to include original_owning_space.id
expect(route.space.id).to eq original_owning_space.id
end
end

context 'target space has the same name as the owning space' do
it 'makes the target space with the same name the new owner' do
RouteTransferOwner.transfer(route, target_space_dup_name, user_audit_info)
expect(route.space.id).to eq target_space.id
Comment thread
nookala marked this conversation as resolved.
Outdated
end
end

Expand All @@ -65,25 +73,25 @@ module VCAP::CloudController
expect_any_instance_of(Repositories::RouteEventRepository).not_to receive(:record_route_transfer_owner).with(
route, user_audit_info, original_owning_space, target_space.guid
)
expect(route.space.name).to eq original_owning_space.name
expect(route.space.id).to eq original_owning_space.id
expect do
RouteTransferOwner.transfer(route, target_space, user_audit_info)
end.to raise_error('db failure')
route.reload
expect(route.space.name).to eq original_owning_space.name
expect(route.space.id).to eq original_owning_space.id
end

it 'does not change the shared spaces' do
expect_any_instance_of(Repositories::RouteEventRepository).not_to receive(:record_route_transfer_owner).with(
route, user_audit_info, original_owning_space, target_space.guid
)
expect(route.shared_spaces.length).to eq 1
expect(route.shared_spaces.map(&:name)).to include shared_space.name
expect(route.shared_spaces.map(&:id)).to include shared_space.id
expect do
RouteTransferOwner.transfer(route, target_space, user_audit_info)
end.to raise_error('db failure')
route.reload
expect(route.shared_spaces.map(&:name)).to include shared_space.name
expect(route.shared_spaces.map(&:id)).to include shared_space.id
expect(route.shared_spaces.length).to eq 1
end
end
Expand Down
Loading