Add a few more testcases
[selectricity] / test / functional / quickvote_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'quickvote_controller'
3
4 class ActionController::TestSession
5   def session_id
6     # Override this so we can set session ID
7     # pass in the 'test_session_id' session variable to override default
8     (@session and @session['test_session_id'])  or "12345678"
9   end
10 end
11 # Re-raise errors caught by the controller.
12 class QuickvoteController; def rescue_action(e) raise e end; end
13
14 class QuickvoteControllerTest < Test::Unit::TestCase
15   def setup
16     @controller = QuickvoteController.new
17     @request    = ActionController::TestRequest.new
18     @response   = ActionController::TestResponse.new
19   end
20
21   # Replace this with your real tests.
22   def test_index
23     get :index
24     assert_response 302
25   end
26
27   def test_create_quickvote
28     post(:create, {'commit' =>"Create Quickvote", 'quickvote' =>{'name' =>"variable", 'description' =>"Favorite variable."}}, nil, {:candlist=>["foo", "bar", "foobar"]})
29     assert_template "quickvote/success"
30     get :index, { 'ident' => "variable"}
31     assert_response :success
32   end
33
34   def test_create_quickvote_badname
35     post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => ["foo", "bar", "foobar"]})
36     assert_template "quickvote/create"
37   end
38
39   def test_create_quickvote_dupe_candidate
40     post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => ["foo", "bar", "bar",  "foobar"]})
41     assert_template "quickvote/create"
42   end
43   
44   def test_get_quickvote_nonexistent
45     get :index, { 'ident' => "idontexist" }
46     assert_redirected_to :controller => 'site'
47   end
48 end

Benjamin Mako Hill || Want to submit a patch?