Added a new controller for working with epic stories. Also added new
routing for epics to RESTfully place them below projects.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/epics_controller.rb | 62 ++++++++++++++++++++++++++++++
app/helpers/epics_helper.rb | 2 +
app/models/epic.rb | 2 +
app/views/epics/create.html.erb | 2 +
app/views/epics/destroy.html.erb | 2 +
app/views/epics/edit.html.erb | 2 +
app/views/epics/index.html.erb | 25 ++++++++++++
app/views/epics/new.html.erb | 2 +
app/views/epics/show.html.erb | 2 +
app/views/epics/update.html.erb | 2 +
config/routes.rb | 3 +
test/functional/epics_controller_test.rb | 41 ++++++++++++++++++++
12 files changed, 147 insertions(+), 0 deletions(-)
create mode 100644 app/controllers/epics_controller.rb
create mode 100644 app/helpers/epics_helper.rb
create mode 100644 app/views/epics/create.html.erb
create mode 100644 app/views/epics/destroy.html.erb
create mode 100644 app/views/epics/edit.html.erb
create mode 100644 app/views/epics/index.html.erb
create mode 100644 app/views/epics/new.html.erb
create mode 100644 app/views/epics/show.html.erb
create mode 100644 app/views/epics/update.html.erb
create mode 100644 test/functional/epics_controller_test.rb
diff --git a/app/controllers/epics_controller.rb b/app/controllers/epics_controller.rb
new file mode 100644
index 0000000..d58a507
--- /dev/null
+++ b/app/controllers/epics_controller.rb
@@ -0,0 +1,62 @@
+# stories_controller.rb
+# Copyright (C) 2008, Darryl L. Pierce <mcpierce(a)gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <
http://www.gnu.org/licenses/>.
+
+# +EpicsController+ allows users to work with +Epic+ stories.
+class EpicsController < ApplicationController
+ before_filter :load_project, :only => [:index]
+
+ # GET /projects/1/epics
+ def index
+ @title = "Epic stories for #{(a)project.name}"
+ @epics = Epic.paginate(:page => params[:page],
+ :per_page => 10,
+ :conditions => ["project_id = ?", @project.id],
+ :order => "priority")
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ def show
+ end
+
+ def new
+ end
+
+ def edit
+ end
+
+ def create
+ end
+
+ def update
+ end
+
+ def destroy
+ end
+
+ private
+
+ def load_project
+ @project = Project.find_by_id(params[:project_id])
+ unless @project
+ flash[:message] = "Missing or invalid project id."
+ respond_to do |format|
+ format.html { redirect_to projects_path}
+ end
+ end
+ end
+end
diff --git a/app/helpers/epics_helper.rb b/app/helpers/epics_helper.rb
new file mode 100644
index 0000000..18d9ee1
--- /dev/null
+++ b/app/helpers/epics_helper.rb
@@ -0,0 +1,2 @@
+module EpicsHelper
+end
diff --git a/app/models/epic.rb b/app/models/epic.rb
index b86e7f7..e0224d6 100644
--- a/app/models/epic.rb
+++ b/app/models/epic.rb
@@ -32,6 +32,8 @@ class Epic < ActiveRecord::Base
validates_presence_of :title
+ has_many :user_stories
+
# Returns a title that's geared for selection lists.
def selectable_title
"#{title} (#{priority})"
diff --git a/app/views/epics/create.html.erb b/app/views/epics/create.html.erb
new file mode 100644
index 0000000..e43f678
--- /dev/null
+++ b/app/views/epics/create.html.erb
@@ -0,0 +1,2 @@
+<h1>Epics#create</h1>
+<p>Find me in app/views/epics/create.html.erb</p>
diff --git a/app/views/epics/destroy.html.erb b/app/views/epics/destroy.html.erb
new file mode 100644
index 0000000..1cf72ac
--- /dev/null
+++ b/app/views/epics/destroy.html.erb
@@ -0,0 +1,2 @@
+<h1>Epics#destroy</h1>
+<p>Find me in app/views/epics/destroy.html.erb</p>
diff --git a/app/views/epics/edit.html.erb b/app/views/epics/edit.html.erb
new file mode 100644
index 0000000..9a0cd29
--- /dev/null
+++ b/app/views/epics/edit.html.erb
@@ -0,0 +1,2 @@
+<h1>Epics#edit</h1>
+<p>Find me in app/views/epics/edit.html.erb</p>
diff --git a/app/views/epics/index.html.erb b/app/views/epics/index.html.erb
new file mode 100644
index 0000000..16acf86
--- /dev/null
+++ b/app/views/epics/index.html.erb
@@ -0,0 +1,25 @@
+<%= will_paginate @epics %>
+
+<table class="main-list">
+ <caption><%= "Epic Stories For #{(a)project.name}"
%></caption>
+ <thead>
+ <tr>
+ <th scope="col">#</th>
+ <th scope="col">Rank</th>
+ <th scope="col" class="name">Title</th>
+ <th scope="col">User Stories</th>
+ <th scope="col">Created</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @epics.each do |epic| %>
+ <tr class="<%= cycle('odd', 'even') %>">
+ <td><%= epic.id %></td>
+ <td><%= epic.priority %></td>
+ <td><%= epic.title %></td>
+ <td><%= epic.user_stories.size %></td>
+ <td><%= show_date epic.created_at, true %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
diff --git a/app/views/epics/new.html.erb b/app/views/epics/new.html.erb
new file mode 100644
index 0000000..b26bfe2
--- /dev/null
+++ b/app/views/epics/new.html.erb
@@ -0,0 +1,2 @@
+<h1>Epics#new</h1>
+<p>Find me in app/views/epics/new.html.erb</p>
diff --git a/app/views/epics/show.html.erb b/app/views/epics/show.html.erb
new file mode 100644
index 0000000..a4b53c6
--- /dev/null
+++ b/app/views/epics/show.html.erb
@@ -0,0 +1,2 @@
+<h1>Epics#show</h1>
+<p>Find me in app/views/epics/show.html.erb</p>
diff --git a/app/views/epics/update.html.erb b/app/views/epics/update.html.erb
new file mode 100644
index 0000000..9dac74b
--- /dev/null
+++ b/app/views/epics/update.html.erb
@@ -0,0 +1,2 @@
+<h1>Epics#update</h1>
+<p>Find me in app/views/epics/update.html.erb</p>
diff --git a/config/routes.rb b/config/routes.rb
index aa2b8fc..5f14233 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -21,6 +21,9 @@ ActionController::Routing::Routes.draw do |map|
admin.resource :server, :controller => 'ServerSettings'
end
+ map.resources :projects do |project|
+ project.resources :epics
+ end
map.resources :projects, :member =>
{
:approve => :put,
diff --git a/test/functional/epics_controller_test.rb
b/test/functional/epics_controller_test.rb
new file mode 100644
index 0000000..1119238
--- /dev/null
+++ b/test/functional/epics_controller_test.rb
@@ -0,0 +1,41 @@
+# stories_controller_test.rb
+# Copyright (C) 2008, Darryl L. Pierce <mcpierce(a)gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <
http://www.gnu.org/licenses/>.
+#
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class EpicsControllerTest < ActionController::TestCase
+ fixtures :projects
+
+ def setup
+ @project = projects(:projxp)
+ end
+
+ # Ensures that viewing a list of epics requires a valid project.
+ def test_index_with_invalid_project
+ get :index, {:project => 9999}
+
+ assert_redirected_to projects_path
+ end
+
+ # Ensures that viewing a list of epics works as expected.
+ def test_index
+ get :index, {:project_id => @project.id}
+
+ assert_response :success
+ assert assigns['project'], "Failed to load the project."
+ end
+end
--
1.6.0.6