Quest for the Holy Rails

October 15, 2007

The Games People Play (Part 2)

Filed under: Uncategorized — Jake Brownson @ 3:42 am

This was a partial post I was working on before I stopped the project, I might as well post it.

In the last post we wrote our Game model. In this post we will modify the games controller and views so players can create games.

Players need to be able to create games, delete games (forfeit), and display games but there they won’t ever update them. Let’s drop the functional tests for updating since that feature isn’t needed. When a user makes a move we could call that editing a game, but I prefer to think of it as creating a move (we’ll do the Move model later).

Let’s remove the following tests from test/functional/games_controller_test.rb:

   def test_should_get_edit
    get :edit, :id => 1
    assert_response :success

  def test_should_update_game
    put :update, :id => 1, :game => { }
    assert_redirected_to game_path(assigns(:game))

Now we can trim the edit, update actions from the app/controllers/games_controller.rb, and delete app/views/games/edit.rhtml.

Let’s require login to access the games controller, first add a test in test/functional/games_controller.rb:

  def setup
    @controller =
    @request    =
    @response   =
    login_as 'quentin'
... snip ...
  def test_index_should_require_authenticated
    assert_requires_login {|c| c.get :index}

  def test_new_should_require_authenticated
    assert_requires_login {|c| c.get :new}

Now we add the code to make it pass in app/controllers/games_controller.rb:

  before_filter :login_required

We need to add some attributes to the Game model


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: