From d021e36732414b986af25b759870e86ecdf8bb5b Mon Sep 17 00:00:00 2001 From: Bherly Novrandy Date: Mon, 14 May 2018 11:57:02 +0700 Subject: [PATCH] Add cluster_name to Apps --- app/controllers/apps_controller.rb | 1 + app/models/app.rb | 4 ++++ db/migrate/20180514044340_add_cluster_name_to_apps.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories/apps.rb | 1 + spec/models/app_spec.rb | 11 +++++++++++ 6 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180514044340_add_cluster_name_to_apps.rb diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index ab758122..5a0db7d2 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -31,6 +31,7 @@ def create if @app.save blueprint = Blueprint.new(@app, @tps_config, @chef_configs) blueprint.to_file + @app.set_cluster_name(blueprint.cluster_name) format.html { redirect_to controller: 'apps', action: 'infra_setup', id: @app.id , notice: 'App was successfully created.' } format.json { render :show, status: :created, location: @app } else diff --git a/app/models/app.rb b/app/models/app.rb index 38df8e31..a89d9b21 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -40,6 +40,10 @@ def set_app_status_inactive set_app_status('INACTIVE') end + def set_cluster_name(cluster_name) + update_column(:cluster_name, cluster_name) + end + private def set_setup_status(status) diff --git a/db/migrate/20180514044340_add_cluster_name_to_apps.rb b/db/migrate/20180514044340_add_cluster_name_to_apps.rb new file mode 100644 index 00000000..8c82482a --- /dev/null +++ b/db/migrate/20180514044340_add_cluster_name_to_apps.rb @@ -0,0 +1,5 @@ +class AddClusterNameToApps < ActiveRecord::Migration + def change + add_column :apps, :cluster_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 76bffd9e..74152f2c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180508084519) do +ActiveRecord::Schema.define(version: 20180514044340) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -33,6 +33,7 @@ t.string "setup_status", default: "PENDING" t.string "app_status", default: "INACTIVE" t.string "tps_config_id" + t.string "cluster_name" end add_index "apps", ["app_status"], name: "index_apps_on_app_status", using: :btree diff --git a/spec/factories/apps.rb b/spec/factories/apps.rb index f50317fd..3e05975e 100644 --- a/spec/factories/apps.rb +++ b/spec/factories/apps.rb @@ -4,6 +4,7 @@ setup_status "PENDING" app_status "INACTIVE" tps_config_id "small" + cluster_name "some" app_group end diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index 8fa1f394..33a2cfa3 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -46,6 +46,17 @@ end end + context 'cluster name' do + it 'has cluster name after blueprint creation' do + app = FactoryBot.create(:app, cluster_name: '') + tps_config = FactoryBot.build(:tps_config) + chef_configs = FactoryBot.build(:chef_configs) + blueprint = Blueprint.new(app, tps_config, chef_configs) + app.set_cluster_name(blueprint.cluster_name) + expect(app.cluster_name).to eq(blueprint.cluster_name) + end + end + context 'after_create' do it 'should has pending setup status' do app = FactoryBot.create(:app)