* Fix the session_id accessor. Previous version looks for wrong method
[selectricity] / test / functional / quickvote_controller_test.rb
index 07c9278696053d3615636a1b176e0e88327800d4..a390d9462b19453558a2f993c9ce29296e64da76 100644 (file)
@@ -5,7 +5,10 @@ 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"
+    return "12345678" unless @attributes
+    if @attributes.has_key? 'test_session_id'
+      return @attributes['test_session_id']
+    end
   end
 end
 # Re-raise errors caught by the controller.
@@ -31,6 +34,13 @@ class QuickvoteControllerTest < Test::Unit::TestCase
     assert_response :success
   end
 
+  def test_create_dupe_quickvote
+    test_create_quickvote
+    assert_raise(Test::Unit::AssertionFailedError) do
+      test_create_quickvote
+    end
+  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"
@@ -65,4 +75,29 @@ class QuickvoteControllerTest < Test::Unit::TestCase
     assert_redirected_to :controller => 'site'
   end
 
+  def test_get_result_with_a_vote
+    test_cast_quickvote
+    get :results, { 'ident' => 'variable' }
+    assert_response :success
+  end
+
+  def test_get_result_multi_votes
+    test_create_quickvote
+    votes = QuickVote.ident_to_quickvote('variable').candidates.collect { |c| c.id}
+    5.times do |time|
+      get :index, { 'ident' => 'variable' }, { 'test_session_id'  =>  (time+1)*50 }
+      assert_response :success
+      post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} }, { 'test_session_id' => (time+1)*50 }
+      assert_template 'quickvote/thanks'
+    end
+    get :results, { 'ident' => 'variable' }
+    assert_response :success
+  end
+
+  def test_cast_quickvote
+    test_create_quickvote
+    votes = QuickVote.ident_to_quickvote('variable').candidates.collect { |c| c.id}
+    post :confirm, { 'ident' => 'variable', 'rankings-list' => votes.sort_by {rand} }
+    assert_template 'quickvote/thanks'
+  end
 end

Benjamin Mako Hill || Want to submit a patch?