* Add one more assertion in testcase for dupe candidates
[selectricity-live] / test / unit / selectricityservice_test.rb
index e3f59061021edf93eb87db2eec0260144826043a..446520b4f2f1f0b5a845e839c2752a16367cc895 100644 (file)
@@ -84,11 +84,11 @@ class SelectricityServiceTest < Test::Unit::TestCase
     assert_create_quickvote_fails election
   end
   def test_create_quickvote_candidates_nil
-    election = ElectionStruct.new :name => "foobar", :description => nil, :candidate_names => nil
+    election = ElectionStruct.new :name => "foobar", :description => "valid", :candidate_names => nil
     assert_create_quickvote_fails election
   end
   def test_create_quickvote_insufficient_candidates
-    election = ElectionStruct.new :name => "foobar", :description => nil, :candidate_names => ["Apple"]
+    election = ElectionStruct.new :name => "foobar", :description => "valid", :candidate_names => ["Apple"]
     assert_create_quickvote_fails election
   end
   def test_create_quickvote_candidates_whitespace
@@ -96,19 +96,26 @@ class SelectricityServiceTest < Test::Unit::TestCase
     assert_create_quickvote_fails election
   end
   def test_create_quickvote_dupe_candidates
-    election = ElectionStruct.new :name => "foobar", :description => nil, :candidate_names => ["Apple", "Apple", "Apple", "Apple"]
+    election = ElectionStruct.new :name => "foobar", :description => "valid", :candidate_names => ["Apple", "Apple", "Apple", "Apple"]
+    assert_create_quickvote_fails election
+
+    # Previous may pass coincidentally if a uniq! then a sizecheck reveals too few unique names
+    # We don't want this to happen. Dupe canidates should fail regardless of how many are left.
+
+    election = ElectionStruct.new :name => "foobar", :description => "valid", :candidate_names => ["Apple", "Apple", "Orange", "Orange", "Pineapple" ,  "Pineapple"]
     assert_create_quickvote_fails election
   end
   def test_create_quickvote_candidates_nil_mixed
-    election = ElectionStruct.new :name => "foobar", :description => nil, :candidate_names => ["Apple", nil ]
+    election = ElectionStruct.new :name => "foobar", :description => "valid", :candidate_names => ["Apple", nil ]
     assert_create_quickvote_fails election
   end
-  def test_create_quickvote_description_htmlescape
-    election = ElectionStruct.new :name => "foobar", :description => "<a>test</a>", :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]
+  def test_create_quickvote_description_xmlescape
+    # Will an embedded XML element bork the table?
+    election = ElectionStruct.new :name => "foobar", :description => "test </string>", :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]
     result = invoke_delegated :vote, :create_quickvote, election
     assert_equal result, ""
     reflection = invoke_delegated :vote, :get_quickvote, election.name
-    assert_not_equal election.description, reflection.description
+    assert_equal election.description, reflection.description
     assert_not_equal reflection.description.length, 0
   end
   private

Benjamin Mako Hill || Want to submit a patch?