Commit 88b03bb5 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Rename method in test

parent 58368fbc
...@@ -404,29 +404,34 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -404,29 +404,34 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def ci_environments_status def ci_environments_status
render json: @merge_request.environments.map do |environment| environments =
next unless can?(current_user, :read_environment, environment) begin
@merge_request.environments.map do |environment|
deployment = environment.first_deployment_for(@merge_request.diff_head_commit) next unless can?(current_user, :read_environment, environment)
deployment = environment.first_deployment_for(@merge_request.diff_head_commit)
environment_data = {
name: environment.name,
id: environment.id,
url: namespace_project_environment_path(@project.namespace, @project, environment),
external_url: environment.external_url,
deployed_at: deployment ? deployment.created_at : nil
}
environment_data = { if environment_data[:external_url]
name: environment.name, environment_data[:external_url_formatted] = environment_data[:external_url].gsub(/\A.*?:\/\//, '')
id: environment.id, end
url: namespace_project_environment_path(@project.namespace, @project, environment),
external_url: environment.external_url,
deployed_at: deployment ? deployment.created_at : nil
}
if environment_data[:external_url] if environment_data[:deployed_at]
environment_data[:external_url_formatted] = environment_data[:external_url].gsub(/\A.*?:\/\//, '') environment_data[:deployed_at_formatted] = environment_data[:deployed_at].to_time.in_time_zone.to_s(:medium)
end end
if environment_data[:deployed_at] environment_data
environment_data[:deployed_at_formatted] = environment_data[:deployed_at].to_time.in_time_zone.to_s(:medium) end.compact
end end
environment_data render json: environments
end.compact
end end
protected protected
......
...@@ -83,4 +83,9 @@ Rails.application.routes.draw do ...@@ -83,4 +83,9 @@ Rails.application.routes.draw do
draw :group draw :group
draw :user draw :user
draw :project draw :project
# Get all keys of user
get ':username.keys' => 'profiles/keys#get_keys', constraints: { username: /.*/ }
root to: "root#index"
end end
...@@ -64,7 +64,7 @@ describe Environment, models: true do ...@@ -64,7 +64,7 @@ describe Environment, models: true do
end end
end end
describe '#deployment_id_for' do describe '#first_deployment_for' do
let(:project) { create(:project) } let(:project) { create(:project) }
let!(:environment) { create(:environment, project: project) } let!(:environment) { create(:environment, project: project) }
let!(:deployment) { create(:deployment, environment: environment, ref: commit.parent.id) } let!(:deployment) { create(:deployment, environment: environment, ref: commit.parent.id) }
...@@ -73,11 +73,11 @@ describe Environment, models: true do ...@@ -73,11 +73,11 @@ describe Environment, models: true do
let(:commit) { project.commit.parent } let(:commit) { project.commit.parent }
it 'returns deployment id for the environment' do it 'returns deployment id for the environment' do
expect(environment.deployment_id_for(commit)).to eq deployment1.id expect(environment.first_deployment_for(commit)).to eq deployment1
end end
it 'return nil when no deployment is found' do it 'return nil when no deployment is found' do
expect(environment.deployment_id_for(head_commit)).to eq nil expect(environment.first_deployment_for(head_commit)).to eq nil
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment