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).
Basic Tests for Forum Implementation - Implementing the User Stories (Page 3 of 4 )
As in previous chapters, we will show you how to use the TDD approach while implementing the forum. This means that you will first create the unit tests, or in this chapter, integration tests. In Chapter 3, we introduced integration testing and mentioned some of the benefits of using integration tests, including multiple session support and tests that span multiple controllers. A forum can be accessed by many users at the same time, which makes it a good candidate for integration testing. For example, George might be replying to a post at the same time as Jill is creating a new post. Integration tests make it possible to simulate this by allowing us to open multiple sessions in the test and execute each action in a different session.
The forum needs some posts for the other user stories to make any sense, so we'll start by implementing the Post to Forum user story.
Implementing the Post to Forum User Story
The Post to Forum user story describes how a customer, or George himself, submits a new post to the forum. This is done by filling out the required information, including the name of the person creating the post, plus the subject and body of the post. To publish the post to the forum, the user should click the Post button. This saves the post in the database and redirects the user to the main page of the forum, where he can see the post at the top of the page.