Merge from jdong
authorJohn Dong <jdong@mit.edu>
Wed, 22 Aug 2007 02:33:12 +0000 (22:33 -0400)
committerJohn Dong <jdong@mit.edu>
Wed, 22 Aug 2007 02:33:12 +0000 (22:33 -0400)
app/views/quickvote/results.rhtml
test/functional/graph_controller_test.rb

index 7ab73efc23926bfc73db059bb5421d4b30e31be0..9727d81289e6690597f298f4d5a0d8bb4a545e5e 100644 (file)
@@ -53,7 +53,7 @@
     <td><% begin %>
         <% raise ArgumentError.new, "Local Server" if voter.ipaddress == "127.0.0.1" %>
         <% raise ArgumentError.new, "XML-RPC Voter" if voter.ipaddress == "XMLRPC Request" %>
-        <% w= Whois::Whois.new(IPAddr.new(voter.ipaddress).to_s,true)%>
+        <% w= Whois::Whois.new(IPAddr.new(voter.ipaddress),true)%>
         <%=h((w.host == nil or w.host.empty?) ? voter.ipaddress : w.host)%>
       </td>
       <td>
       <%=h err %>
     </td>
     <td><%=h err%>
+    <% rescue NoMethodError %>
+      DNS Unreachable
+    </td>
+    <td> DNS Unreachable
     <% end %>
     </td>
   <td><%= voter.vote.votestring %></td>
index 45943351ceac77e198f75d70b9594dc2f449bf0b..e5c279008339815d1aa9835a3fdcb2f57a33025b 100644 (file)
@@ -1,5 +1,6 @@
 require File.dirname(__FILE__) + '/../test_helper'
 require 'graph_controller'
+require 'selectricity_service_controller'
 
 # Re-raise errors caught by the controller.
 class GraphController; def rescue_action(e) raise e end; end
@@ -12,11 +13,105 @@ class GraphControllerTest < Test::Unit::TestCase
     @controller = GraphController.new
     @request    = ActionController::TestRequest.new
     @response   = ActionController::TestResponse.new
+    @SS         = SelectricityService.new
+    @election = nil
   end
 
   # TODO Replace this with your actual tests
-  def test_show
-    assert true
+  def test_show_nonexist_votes_per_interval
+    assert_raise(ActiveRecord::RecordNotFound) { get :votes_per_interval, { :id => 42 } }
+  end
+
+  def test_show_nonexist_borda_bar
+    assert_raise(ActiveRecord::RecordNotFound) { get :borda_bar, { :id => 42 } }
+  end
+
+  def test_show_nonexist_choices_positions
+    assert_raise(ActiveRecord::RecordNotFound) { get :choices_positions, { :id => 42 } }
+  end
+  
+  def test_show_empty_votes_per_interval
+    make_election
+    get :votes_per_interval, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+  
+  def test_show_empty_borda_bar
+    make_election
+    get :borda_bar, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+
+  def test_show_empty_choices_positions
+    make_election
+    get :choices_positions, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+  
+  def test_show_single_votes_per_interval
+    make_election
+    cast_vote
+    get :votes_per_interval, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+  
+  def test_show_single_borda_bar
+    make_election
+    cast_vote
+    get :borda_bar, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+
+  def test_show_single_choices_positions
+    make_election
+    cast_vote
+    get :choices_positions, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+
+  def test_show_many_votes_per_interval
+    make_election
+    20.times {cast_vote}
+    get :votes_per_interval, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+  
+  def test_show_many_borda_bar
+    make_election
+    20.times {cast_vote}
+    get :borda_bar, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+
+  def test_show_many_choices_positions
+    make_election
+    20.times {cast_vote}
+    get :choices_positions, { :id => @election.id }
+    assert_response :success
+    assert_equal 'image/png', @response.headers['Content-Type']
+  end
+
+
+  private
+  def make_election
+    e=ElectionStruct.new( :name => "test", :description => "This is a test",
+                          :candidate_names => ['choice1', 'choice2', 'choice3'])
+    @SS.create_quickvote e
+    @election = @SS.list_quickvotes[0]
+    assert_not_nil @election
+  end
+
+  private
+  def cast_vote
+    @SS.cast_quickvote @election.name, 42, [@election.candidate_ids.sort_by {rand}]
   end
   
 end

Benjamin Mako Hill || Want to submit a patch?