Commit 16fc61d6 authored by Shinya Maeda's avatar Shinya Maeda

Rever add action follow up 1

parent 9c811566
...@@ -9,7 +9,7 @@ class EnvironmentsFinder ...@@ -9,7 +9,7 @@ class EnvironmentsFinder
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def execute def execute
deployments = project.deployments.success deployments = project.deployments
deployments = deployments =
if ref if ref
deployments_query = params[:with_tags] ? 'ref = :ref OR tag IS TRUE' : 'ref = :ref' deployments_query = params[:with_tags] ? 'ref = :ref OR tag IS TRUE' : 'ref = :ref'
......
...@@ -132,7 +132,7 @@ class Deployment < ActiveRecord::Base ...@@ -132,7 +132,7 @@ class Deployment < ActiveRecord::Base
def previous_deployment def previous_deployment
@previous_deployment ||= @previous_deployment ||=
project.deployments.success.joins(:environment) project.deployments.joins(:environment)
.where(environments: { name: self.environment.name }, ref: self.ref) .where(environments: { name: self.environment.name }, ref: self.ref)
.where.not(id: self.id) .where.not(id: self.id)
.take .take
......
...@@ -96,7 +96,7 @@ class Environment < ActiveRecord::Base ...@@ -96,7 +96,7 @@ class Environment < ActiveRecord::Base
end end
def last_deployed_at def last_deployed_at
last_deployment.try(:finished_at) last_deployment.try(:created_at)
end end
def update_merge_request_metrics? def update_merge_request_metrics?
......
...@@ -47,6 +47,8 @@ class EnvironmentStatus ...@@ -47,6 +47,8 @@ class EnvironmentStatus
# Since frontend has not supported all statuses yet, BE has to # Since frontend has not supported all statuses yet, BE has to
# proxy some status to a supported status. # proxy some status to a supported status.
def status def status
return unless deployment
case deployment.status case deployment.status
when 'created' when 'created'
'running' 'running'
......
...@@ -927,6 +927,35 @@ ActiveRecord::Schema.define(version: 20181106135939) do ...@@ -927,6 +927,35 @@ ActiveRecord::Schema.define(version: 20181106135939) do
add_index "forked_project_links", ["forked_to_project_id"], name: "index_forked_project_links_on_forked_to_project_id", unique: true, using: :btree add_index "forked_project_links", ["forked_to_project_id"], name: "index_forked_project_links_on_forked_to_project_id", unique: true, using: :btree
create_table "gcp_clusters", force: :cascade do |t|
t.integer "project_id", null: false
t.integer "user_id"
t.integer "service_id"
t.integer "status"
t.integer "gcp_cluster_size", null: false
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.boolean "enabled", default: true
t.text "status_reason"
t.string "project_namespace"
t.string "endpoint"
t.text "ca_cert"
t.text "encrypted_kubernetes_token"
t.string "encrypted_kubernetes_token_iv"
t.string "username"
t.text "encrypted_password"
t.string "encrypted_password_iv"
t.string "gcp_project_id", null: false
t.string "gcp_cluster_zone", null: false
t.string "gcp_cluster_name", null: false
t.string "gcp_machine_type"
t.string "gcp_operation_id"
t.text "encrypted_gcp_token"
t.string "encrypted_gcp_token_iv"
end
add_index "gcp_clusters", ["project_id"], name: "index_gcp_clusters_on_project_id", unique: true, using: :btree
create_table "gpg_key_subkeys", force: :cascade do |t| create_table "gpg_key_subkeys", force: :cascade do |t|
t.integer "gpg_key_id", null: false t.integer "gpg_key_id", null: false
t.binary "keyid" t.binary "keyid"
...@@ -1827,7 +1856,6 @@ ActiveRecord::Schema.define(version: 20181106135939) do ...@@ -1827,7 +1856,6 @@ ActiveRecord::Schema.define(version: 20181106135939) do
end end
add_index "redirect_routes", ["path"], name: "index_redirect_routes_on_path", unique: true, using: :btree add_index "redirect_routes", ["path"], name: "index_redirect_routes_on_path", unique: true, using: :btree
add_index "redirect_routes", ["path"], name: "index_redirect_routes_on_path_text_pattern_ops", using: :btree, opclasses: {"path"=>"varchar_pattern_ops"}
add_index "redirect_routes", ["source_type", "source_id"], name: "index_redirect_routes_on_source_type_and_source_id", using: :btree add_index "redirect_routes", ["source_type", "source_id"], name: "index_redirect_routes_on_source_type_and_source_id", using: :btree
create_table "releases", force: :cascade do |t| create_table "releases", force: :cascade do |t|
...@@ -2411,6 +2439,9 @@ ActiveRecord::Schema.define(version: 20181106135939) do ...@@ -2411,6 +2439,9 @@ ActiveRecord::Schema.define(version: 20181106135939) do
add_foreign_key "fork_network_members", "projects", on_delete: :cascade add_foreign_key "fork_network_members", "projects", on_delete: :cascade
add_foreign_key "fork_networks", "projects", column: "root_project_id", name: "fk_e7b436b2b5", on_delete: :nullify add_foreign_key "fork_networks", "projects", column: "root_project_id", name: "fk_e7b436b2b5", on_delete: :nullify
add_foreign_key "forked_project_links", "projects", column: "forked_to_project_id", name: "fk_434510edb0", on_delete: :cascade add_foreign_key "forked_project_links", "projects", column: "forked_to_project_id", name: "fk_434510edb0", on_delete: :cascade
add_foreign_key "gcp_clusters", "projects", on_delete: :cascade
add_foreign_key "gcp_clusters", "services", on_delete: :nullify
add_foreign_key "gcp_clusters", "users", on_delete: :nullify
add_foreign_key "gpg_key_subkeys", "gpg_keys", on_delete: :cascade add_foreign_key "gpg_key_subkeys", "gpg_keys", on_delete: :cascade
add_foreign_key "gpg_keys", "users", on_delete: :cascade add_foreign_key "gpg_keys", "users", on_delete: :cascade
add_foreign_key "gpg_signatures", "gpg_key_subkeys", on_delete: :nullify add_foreign_key "gpg_signatures", "gpg_key_subkeys", on_delete: :nullify
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
end end
def value def value
@value ||= @project.deployments.success.where("created_at > ?", @from).count @value ||= @project.deployments.where("created_at > ?", @from).count
end end
end end
end end
......
...@@ -72,30 +72,6 @@ describe Environment do ...@@ -72,30 +72,6 @@ describe Environment do
end end
end end
describe '#last_deployed_at' do
subject { environment.last_deployed_at }
let(:environment) { create(:environment) }
context 'when the latest deployment is successful' do
let!(:deployment) { create(:deployment, :success, environment: environment) }
it { expect(subject).to be_within(1.second).of(deployment.finished_at) }
end
context 'when the latest deployment failed' do
let!(:deployment) { create(:deployment, :failed, environment: environment) }
it { is_expected.to be_nil }
end
context 'when the latest deployment is running' do
let!(:deployment) { create(:deployment, :running, environment: environment) }
it { is_expected.to be_nil }
end
end
describe '#folder_name' do describe '#folder_name' do
context 'when it is inside a folder' do context 'when it is inside a folder' do
subject(:environment) do subject(:environment) do
...@@ -177,6 +153,26 @@ describe Environment do ...@@ -177,6 +153,26 @@ describe Environment do
end end
end end
describe '#first_deployment_for' do
let(:project) { create(:project, :repository) }
let!(:deployment) { create(:deployment, :succeed, environment: environment, ref: commit.parent.id) }
let!(:deployment1) { create(:deployment, :succeed, environment: environment, ref: commit.id) }
let(:head_commit) { project.commit }
let(:commit) { project.commit.parent }
it 'returns deployment id for the environment' do
expect(environment.first_deployment_for(commit.id)).to eq deployment1
end
it 'return nil when no deployment is found' do
expect(environment.first_deployment_for(head_commit.id)).to eq nil
end
it 'returns a UTF-8 ref' do
expect(environment.first_deployment_for(commit.id).ref).to be_utf8
end
end
describe '#environment_type' do describe '#environment_type' do
subject { environment.environment_type } subject { environment.environment_type }
......
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