1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'quickvote_controller'
4 class ActionController::TestSession
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"
11 # Re-raise errors caught by the controller.
12 class QuickvoteController; def rescue_action(e) raise e end; end
14 class QuickvoteControllerTest < Test::Unit::TestCase
16 @controller = QuickvoteController.new
17 @request = ActionController::TestRequest.new
18 @response = ActionController::TestResponse.new
21 # Replace this with your real tests.
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
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"
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"
44 def test_create_quickvote_nil_candidate
45 post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => nil})
46 assert_template "quickvote/create"
47 post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => []})
48 assert_template "quickvote/create"
51 def test_get_quickvote_nonexistent
52 get :index, { 'ident' => "idontexist" }
53 assert_redirected_to :controller => 'site'
56 def test_get_result_empty_vote
58 get :results, { 'ident' => 'variable' }
59 assert_response :success
62 def test_get_result_nonexistent
64 get :results, { 'ident' => 'asdflaksdjf' }
65 assert_redirected_to :controller => 'site'