Add some empty request testcases.
[selectricity] / test / functional / quickvote_controller_test.rb
index d0b37d90c170891a78723739631300e12ec9c88a..07c9278696053d3615636a1b176e0e88327800d4 100644 (file)
@@ -1,6 +1,13 @@
 require File.dirname(__FILE__) + '/../test_helper'
 require 'quickvote_controller'
 
+class ActionController::TestSession
+  def session_id
+    # Override this so we can set session ID
+    # pass in the 'test_session_id' session variable to override default
+    (@session and @session['test_session_id'])  or "12345678"
+  end
+end
 # Re-raise errors caught by the controller.
 class QuickvoteController; def rescue_action(e) raise e end; end
 
@@ -12,7 +19,50 @@ class QuickvoteControllerTest < Test::Unit::TestCase
   end
 
   # Replace this with your real tests.
-  def test_truth
-    assert true
+  def test_index
+    get :index
+    assert_response 302
+  end
+
+  def test_create_quickvote
+    post(:create, {'commit' =>"Create Quickvote", 'quickvote' =>{'name' =>"variable", 'description' =>"Favorite variable."}}, nil, {:candlist=>["foo", "bar", "foobar"]})
+    assert_template "quickvote/success"
+    get :index, { 'ident' => "variable"}
+    assert_response :success
+  end
+
+  def test_create_quickvote_badname
+    post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => ["foo", "bar", "foobar"]})
+    assert_template "quickvote/create"
+  end
+
+  def test_create_quickvote_dupe_candidate
+    post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => ["foo", "bar", "bar",  "foobar"]})
+    assert_template "quickvote/create"
   end
+  
+  def test_create_quickvote_nil_candidate
+    post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => nil})
+    assert_template "quickvote/create"
+    post(:create, {'commit' => "Create Quickvote", 'quickvote' => {'name' => "has a space", 'description' => "Foobar"}}, nil, {:candlist => []})
+    assert_template "quickvote/create"
+  end
+
+  def test_get_quickvote_nonexistent
+    get :index, { 'ident' => "idontexist" }
+    assert_redirected_to :controller => 'site'
+  end
+
+  def test_get_result_empty_vote
+    test_create_quickvote
+    get :results, { 'ident' => 'variable' }
+    assert_response :success
+  end
+
+  def test_get_result_nonexistent
+    test_create_quickvote
+    get :results, { 'ident' => 'asdflaksdjf' }
+    assert_redirected_to :controller => 'site'
+  end
+
 end

Benjamin Mako Hill || Want to submit a patch?