Added unit tests for the EpicsController::show method. Created the show
html. Added commands to edit the epic, view all epics and return to the
proejct list, and also to delete an epic.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/epics_controller.rb | 4 +++-
app/views/epics/index.html.erb | 2 +-
app/views/epics/show.html.erb | 29 +++++++++++++++++++++++++++--
test/fixtures/epics.yml | 3 +++
test/functional/epics_controller_test.rb | 30 ++++++++++++++++++++++++++++++
5 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/app/controllers/epics_controller.rb b/app/controllers/epics_controller.rb
index b51eb34..6f7f819 100644
--- a/app/controllers/epics_controller.rb
+++ b/app/controllers/epics_controller.rb
@@ -18,7 +18,7 @@
class EpicsController < ApplicationController
before_filter :authenticated, :only => [:new, :edit, :create, :update, :destroy]
before_filter :load_project
- before_filter :load_epic, :only => [:edit, :update, :destroy]
+ before_filter :load_epic, :only => [:show, :edit, :update, :destroy]
# GET /projects/1/epics
def index
@@ -32,7 +32,9 @@ class EpicsController < ApplicationController
end
end
+ # GET/projects/1/epics/1
def show
+ @title = "Epic:#{@epic.title}"
end
# GET /projects/1/epics/new
diff --git a/app/views/epics/index.html.erb b/app/views/epics/index.html.erb
index d1a1d35..dae7da9 100644
--- a/app/views/epics/index.html.erb
+++ b/app/views/epics/index.html.erb
@@ -21,7 +21,7 @@
<td><%= epic.priority %></td>
<td class="name">
<%= link_to "#{epic.title}", project_epic_path(@project, epic) %>
- <%= RedCloth.new(get_first_sentence epic.description).to_html %>
+ <%= RedCloth.new(get_first_sentence(epic.description)).to_html %>
</td>
<td><%= epic.user_stories.size %></td>
<td><%= show_date epic.created_at %></td>
diff --git a/app/views/epics/show.html.erb b/app/views/epics/show.html.erb
index a4b53c6..2c28250 100644
--- a/app/views/epics/show.html.erb
+++ b/app/views/epics/show.html.erb
@@ -1,2 +1,27 @@
-<h1>Epics#show</h1>
-<p>Find me in app/views/epics/show.html.erb</p>
+<div id="content">
+ <div id="page-details">
+ <dl>
+ <dt><%= "#{(a)epic.title} (Priority: #{(a)epic.priority})"
%></dt>
+ <dd><%= RedCloth.new((a)epic.description).to_html %></dd>
+ </dl>
+ </div>
+</div>
+
+<div id="sidebar">
+ <%= link_to "View parent project",
+ project_path(@project), :class => "command" %>
+
+ <%= link_to "View all epics for this project",
+ project_epics_path(@project), :class => "command" %>
+
+ <% if @epic.can_edit?(@user) %>
+ <%= link_to "Edit this epic",
+ edit_project_epic_path(@project, @epic), :class => "command" %>
+ <% end %>
+
+ <% if @epic.can_delete?(@user) %>
+ <%= link_to "Delete this epic...",
+ project_epic_path(@project, @epic), :class => "command",
+ :confirm => "Delete this epic? Are you sure?", :method => :delete
%>
+ <% end %>
+</div>
diff --git a/test/fixtures/epics.yml b/test/fixtures/epics.yml
index ee25170..3654b8d 100644
--- a/test/fixtures/epics.yml
+++ b/test/fixtures/epics.yml
@@ -2,13 +2,16 @@ user_stories_epic:
project_id: <%= Fixtures.identify(:projxp) %>
priority: 1
title: User stories capture individual features.
+ description: User stories.
login_epic:
project_id: <%= Fixtures.identify(:projxp) %>
priority: 2
title: Covers all login attempts.
+ description: Login stories.
no_user_story_epic:
project_id: <%= Fixtures.identify(:projxp) %>
priority: 3
title: Has no user stories.
+ description: Epic with no user stories.
diff --git a/test/functional/epics_controller_test.rb
b/test/functional/epics_controller_test.rb
index 9ea00e3..5660f32 100644
--- a/test/functional/epics_controller_test.rb
+++ b/test/functional/epics_controller_test.rb
@@ -51,6 +51,36 @@ class EpicsControllerTest < ActionController::TestCase
assert assigns['project'], "Failed to load the project."
end
+ # Ensures that viewing an epic requires a valid project.
+ def test_show_with_invalid_project
+ get :show, { }
+
+ assert_redirected_to error_path
+ end
+
+ # Ensures that a valid epic id is required.
+ def test_show_with_invalid_epic
+ get :show, {:project_id => @project.id}
+
+ assert_redirected_to error_path
+ end
+
+ # Ensures that the epic and project must match.
+ def test_show_with_project_epic_mismatch
+ get :show, {:project_id => @other_project.id, :id => @epic.id}
+
+ assert_redirected_to error_path
+ end
+
+ # Ensures that showing an epic works as expected.
+ def test_show
+ get :show, {:project_id => @project.id, :id => @epic.id}
+
+ assert_response :success
+ assert assigns['epic'], "Failed to load the epic."
+ assert_equal @epic.id, assigns['epic'].id, "Loaded the wrong
epic."
+ end
+
# Ensures that anonymous users cannot create new epics.
def test_new_as_anonymous
get :new
--
1.6.0.6