Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 7f98f4b

Browse files
committed
V2 apps return correct app guid in links
- Fix incorrect implementation from 0ae0b8a - Fix setup for test so process guid is actually different than the app guid - url_for_guid should be a class method instead of an instance method [cloudfoundry#1523] Authored-by: Greg Cobb <gcobb@pivotal.io>
1 parent 514e924 commit 7f98f4b

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

app/controllers/runtime/apps_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def self.translate_memory_validation_exception(memory_errors)
122122
end
123123
end
124124

125+
def self.url_for_guid(_, process)
126+
super(process.app_guid, process)
127+
end
128+
125129
def inject_dependencies(dependencies)
126130
super
127131
@app_event_repository = dependencies.fetch(:app_event_repository)
@@ -196,10 +200,6 @@ def upload_droplet(guid)
196200
[HTTP::CREATED, JobPresenter.new(enqueued_job).to_json]
197201
end
198202

199-
def url_for_guid(_, process)
200-
super(process.app_guid, process)
201-
end
202-
203203
def read(guid)
204204
process = find_guid(guid)
205205
raise CloudController::Errors::ApiError.new_from_details('AppNotFound', guid) unless process.web?

app/presenters/v2/relations_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def add_relationship_url_to_response(response, controller, associated_controller
8989
if association.is_a?(VCAP::CloudController::RestController::ControllerDSL::ToOneAttribute)
9090
associated_model_instance = get_preloaded_association_contents!(obj, association)
9191
if associated_model_instance
92-
associated_url = associated_controller.url_for_guid(associated_model_instance.guid)
92+
associated_url = associated_controller.url_for_guid(associated_model_instance.guid, associated_model_instance)
9393
end
9494
else
9595
associated_url = "#{controller.url_for_guid(obj.guid, obj)}/#{relationship_name}"

spec/unit/controllers/runtime/apps_controller_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,13 @@ def update_app
622622
context 'when the app has rolled to a new web process' do
623623
before do
624624
process.destroy
625-
ProcessModelFactory.make(instances: 1, app: app_model)
626625
end
627626

627+
let!(:new_process) { ProcessModel.make(type: ProcessTypes::WEB, app: app_model) }
628+
628629
it 'returns the app with the appropriate app guid' do
630+
expect(app_guid).not_to eq(new_process.guid)
631+
629632
get "/v2/apps/#{app_guid}"
630633
expect(decoded_response['metadata']).to include({
631634
'guid' => app_guid.to_s,

0 commit comments

Comments
 (0)