18733048979d34d2b351ab4798fb1220f589fac9
[selectricity] / test / functional / election_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'elections_controller'
3
4 # Re-raise errors caught by the controller.
5 class ElectionsController; def rescue_action(e) raise e end; end
6
7 class ElectionsControllerTest < Test::Unit::TestCase
8   fixtures :elections
9
10   def setup
11     @controller = ElectionsController.new
12     @request    = ActionController::TestRequest.new
13     @response   = ActionController::TestResponse.new
14   end
15
16   def test_index
17     get :index
18     assert_response :success
19     assert_template 'list'
20   end
21
22   def test_list
23     get :list
24
25     assert_response :success
26     assert_template 'list'
27
28     assert_not_nil assigns(:elections)
29   end
30
31   def test_show
32     get :show, :id => 1
33
34     assert_response :success
35     assert_template 'show'
36
37     assert_not_nil assigns(:election)
38     assert assigns(:election).valid?
39   end
40
41   def test_new
42     get :new
43
44     assert_response :success
45     assert_template 'new'
46
47     assert_not_nil assigns(:election)
48   end
49
50   def test_create
51     num_elections = Election.count
52
53     post :create, :election => {}
54
55     assert_response :redirect
56     assert_redirected_to :action => 'list'
57
58     assert_equal num_elections + 1, Election.count
59   end
60
61   def test_edit
62     get :edit, :id => 1
63
64     assert_response :success
65     assert_template 'edit'
66
67     assert_not_nil assigns(:election)
68     assert assigns(:election).valid?
69   end
70
71   def test_update
72     post :update, :id => 1
73     assert_response :redirect
74     assert_redirected_to :action => 'show', :id => 1
75   end
76
77   def test_destroy
78     assert_not_nil Election.find(1)
79
80     post :destroy, :id => 1
81     assert_response :redirect
82     assert_redirected_to :action => 'list'
83
84     assert_raise(ActiveRecord::RecordNotFound) {
85       Election.find(1)
86     }
87   end
88 end

Benjamin Mako Hill || Want to submit a patch?