Skip to content

Commit

Permalink
Revert "Revert "Change DeployGroup links to use PermaLinks to user-fr…
Browse files Browse the repository at this point in the history
…iendliness""
  • Loading branch information
henders committed Dec 2, 2015
1 parent fd902b0 commit bc0a2f6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/deploy_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ def allowed_deploy_group_params
end

def deploy_group
@deploy_group ||= DeployGroup.find(params[:id])
@deploy_group ||= DeployGroup.find_by_param!(params[:id])
end
end
2 changes: 1 addition & 1 deletion app/controllers/deploy_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def show
private

def find_deploy_group
@deploy_group = DeployGroup.find(params[:id])
@deploy_group = DeployGroup.find_by_param!(params[:id])
end
end
6 changes: 6 additions & 0 deletions app/models/deploy_group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class DeployGroup < ActiveRecord::Base
include Permalinkable

has_soft_deletion default_scope: true

belongs_to :environment
Expand Down Expand Up @@ -28,6 +30,10 @@ def long_name

private

def permalink_base
name
end

def touch_stages
stages.update_all(updated_at: Time.now)
end
Expand Down
17 changes: 17 additions & 0 deletions db/migrate/20151201104205_add_permalink_to_deploy_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class AddPermalinkToDeployGroups < ActiveRecord::Migration
def change
add_column :deploy_groups, :permalink, :string
add_index :deploy_groups, :permalink, unique: true

DeployGroup.reset_column_information

DeployGroup.with_deleted do
DeployGroup.find_each do |deploy_group|
deploy_group.send(:generate_permalink)
deploy_group.update_column(:permalink, deploy_group.permalink)
end
end

change_column :deploy_groups, :permalink, :string, null: false
end
end
4 changes: 3 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: 20151116174240) do
ActiveRecord::Schema.define(version: 20151201104205) do

create_table "build_statuses", force: :cascade do |t|
t.integer "build_id", null: false
Expand Down Expand Up @@ -60,9 +60,11 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "env_value", limit: 255, null: false
t.string "permalink", null: false
end

add_index "deploy_groups", ["environment_id"], name: "index_deploy_groups_on_environment_id", using: :btree
add_index "deploy_groups", ["permalink"], name: "index_deploy_groups_on_permalink", unique: true

create_table "deploy_groups_stages", id: false, force: :cascade do |t|
t.integer "deploy_group_id", limit: 4
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/admin/deploy_groups_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def self.it_renders_index
deploy_group_count = DeployGroup.count
post :create, deploy_group: {name: nil}
assert_template :edit
flash[:error].must_equal ["Name can't be blank", "Environment can't be blank"]
flash[:error].must_equal ["Permalink can't be blank", "Name can't be blank", "Environment can't be blank"]
DeployGroup.count.must_equal deploy_group_count
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/deploy_groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ pod1:
name: Pod1
env_value: pod1
environment: production
permalink: pod1

pod2:
name: Pod2
env_value: pod2
environment: production
permalink: pod2

pod100:
name: Pod 100
env_value: pod100
environment: staging
permalink: pod100

0 comments on commit bc0a2f6

Please sign in to comment.