From 8ef1128f672266c789fc135500e1287ab389bb16 Mon Sep 17 00:00:00 2001
From: Thong Kuah <tkuah@gitlab.com>
Date: Thu, 31 Jan 2019 12:21:03 +1300
Subject: [PATCH] Update version column after application is updated

Note: updating version column after :updating is not ideal in the
updating -> update_erroed case. This will mean that the application now
records the version as the version that failed to upgrade, not the
version that it is currently on.
---
 app/models/clusters/concerns/application_version.rb    |  4 ++++
 .../cluster_application_status_shared_examples.rb      | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/app/models/clusters/concerns/application_version.rb b/app/models/clusters/concerns/application_version.rb
index ccad74dc35a..285c9d98935 100644
--- a/app/models/clusters/concerns/application_version.rb
+++ b/app/models/clusters/concerns/application_version.rb
@@ -10,6 +10,10 @@ module Clusters
           after_transition any => [:installing] do |application|
             application.update(version: application.class.const_get(:VERSION))
           end
+
+          before_transition any => :updated do |application|
+            application.version = application.class.const_get(:VERSION)
+          end
         end
       end
     end
diff --git a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
index c391cc48f4e..bd12d94b2c2 100644
--- a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
+++ b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
@@ -78,6 +78,16 @@ shared_examples 'cluster application status specs' do |application_name|
 
         expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION)
       end
+
+      it 'updates the version for the application' do
+        subject.update!(version: '0.0.0')
+
+        subject.make_updated!
+
+        subject.reload
+
+        expect(subject.version).to eq(subject.class.const_get(:VERSION))
+      end
     end
 
     describe '#make_errored' do
-- 
2.30.9