Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Use slugs in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Dunn committed Jan 6, 2016
1 parent a6dca68 commit 2de8c4e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 15 deletions.
3 changes: 0 additions & 3 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ class ProjectsController < ApplicationController
def index
@projects = Project.all
end
def show
@project = Project.find(params[:id])
end
end
9 changes: 5 additions & 4 deletions app/controllers/runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class RunsController < ApplicationController
skip_before_action :verify_authenticity_token

def show
@suite = Suite.find(params[:suite_id])
@run = @suite.runs.find_by_sequential_id(params[:id])
@project = Project.find_by_slug(params[:project_slug])
@suite = @project.suites.find_by_slug(params[:suite_slug])
@run = @suite.runs.find_by_sequential_id(params[:sequential_id])
@tests = TestFilters.new(@run.tests, params)
end

Expand All @@ -14,12 +15,12 @@ def new
def create
@project = Project.find_by_name(params[:project])
if @project.nil?
@project = Project.create(name: params[:project])
@project = Project.create(name: params[:project], slug: params[:project].parameterize)
end

@suite = @project.suites.find_by_name(params[:suite])
if @suite.nil?
@suite = @project.suites.create(name: params[:suite])
@suite = @project.suites.create(name: params[:suite], slug: params[:suite].parameterize)
end

@run = @suite.runs.create
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/suites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SuitesController < ApplicationController
def show
@suite = Suite.find(params[:id])
@project = Project.find_by_slug(params[:project_slug])
@suite = @project.suites.find_by_slug(params[:slug])
@baselines = TestFilters.new(@suite.baselines, params)
end
end
4 changes: 4 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class Project < ActiveRecord::Base
has_many :suites

def to_param
slug
end
end
6 changes: 3 additions & 3 deletions app/models/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def self.reversed
order('created_at DESC')
end

# def to_param
# self.sequential_id.to_s
# end
def to_param
sequential_id.to_s
end

def passing_tests
self.tests.where(pass: true).count
Expand Down
4 changes: 4 additions & 0 deletions app/models/suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ def latest_run
def baselines
tests.where(baseline: true)
end

def to_param
slug
end
end
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

get '/' => redirect('/projects')

resources :projects, only: [:index] do
resources :suites, only: [:show] do
resources :runs, only: [:show]
resources :projects, param: :slug, only: [:index] do
resources :suites, param: :slug, only: [:show] do
resources :runs, param: :sequential_id, only: [:show]
end
end

Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20160106085402_add_slugs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSlugs < ActiveRecord::Migration
def change
add_column :projects, :slug, :string
add_column :suites, :slug, :string
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: 20160105085402) do
ActiveRecord::Schema.define(version: 20160106085402) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -20,6 +20,7 @@
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
end

create_table "runs", force: :cascade do |t|
Expand All @@ -36,6 +37,7 @@
t.integer "project_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
end

create_table "tests", force: :cascade do |t|
Expand Down

0 comments on commit 2de8c4e

Please sign in to comment.