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
  end

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

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 = GamesController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
    login_as 'quentin'
  end
... snip ...
  def test_index_should_require_authenticated
    assert_requires_login {|c| c.get :index}
  end

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

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


No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.