Skip to content

Commit

Permalink
Add cluster_name to Apps
Browse files Browse the repository at this point in the history
  • Loading branch information
pushm0v committed May 14, 2018
1 parent 9ce93af commit d021e36
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180514044340_add_cluster_name_to_apps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddClusterNameToApps < ActiveRecord::Migration
def change
add_column :apps, :cluster_name, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/factories/apps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
setup_status "PENDING"
app_status "INACTIVE"
tps_config_id "small"
cluster_name "some"

app_group
end
Expand Down
11 changes: 11 additions & 0 deletions spec/models/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d021e36

Please sign in to comment.