Home arrow Ruby-on-Rails arrow Page 2 - Basic Tests for Forum Implementation

Basic Tests for Forum Implementation

In this second part of a four-part series on setting up a forum in Ruby on Rails, you'll learn how to unit test a model, generate a forum controller and view, and more. This article is excerpted from chapter six of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
May 21, 2010
  1. · Basic Tests for Forum Implementation
  2. · Generating the Controller and View
  3. · Implementing the User Stories
  4. · Creating the Integration Test

print this article

Basic Tests for Forum Implementation - Generating the Controller and View
(Page 2 of 4 )

George has given us a tight schedule. We could create the forum controller and view files manually, but instead, we decide to save some time and use the generate script. Run the generate script with the following parameters to generate the controller:

$ script/generate controller Forum index reply show post create

exists app/controllers/
exists app/helpers/
create app/views/forum
exists test/functional/
create app/controllers/forum_controller.rb
create test/functional/forum_controller_test.rb
create app/helpers/forum_helper.rb
create app/views/forum/index.rhtml
create app/views/forum/reply.rhtml
create app/views/forum/show.rhtml
create app/views/forum/post.rhtml
create app/views/forum/create.rhtml










Note that each action in the controller maps to a user story:

  1. The index action implements the View Forum user story.
  2. The reply action implements the Reply to Post user story. 
  3. The show action implements the View Post user story. 
  4. The post and create actions implement the Post to Forum user story.

Open app/controllers/forum_controller.rb in your editor. You should see the following code (note that we have left out part of the file):

class ForumController < ApplicationController

  def index

  def reply

Next, we will implement each of the forum user stories.

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials