Rename Selectricity API calls to more explicitly call itself quickvotes.
authorJohn Dong <jdong@mit.edu>
Tue, 28 Aug 2007 20:11:45 +0000 (16:11 -0400)
committerJohn Dong <jdong@mit.edu>
Tue, 28 Aug 2007 20:11:45 +0000 (16:11 -0400)
app/apis/selectricity_api.rb
app/models/selectricity_service.rb
db/schema.rb
test/functional/graph_controller_test.rb
test/unit/selectricityservice_test.rb

index 9c95369d9a798917ee68babb9d2f578c0a6b3b04..005985b41db7c55763426e76ef11376065f8e476 100644 (file)
@@ -1,11 +1,11 @@
-class ElectionStruct < ActionWebService::Struct
+class QuickVoteStruct < ActionWebService::Struct
   member :name, :string
   member :description, :string
   member :candidate_ids, [:int]
   member :candidate_names, [:string]
   member :id, :int
 end
-class VoteInfo < ActionWebService::Struct
+class QuickVoterInfo < ActionWebService::Struct
   member :voter_id, :int
   member :voter_session_id, :string
   member :voter_ipaddress, :string
@@ -13,26 +13,24 @@ class VoteInfo < ActionWebService::Struct
   member :vote, [:int]
 end
 
-class VoteResultStruct < ActionWebService::Struct
+class QuickVoteResultStruct < ActionWebService::Struct
   member :plurality_winners, [:int]
   member :approval_winners, [:int]
   member :condorcet_winners, [:int]
   member :ssd_winners, [:int]
   member :borda_winners, [:int]
 end
-class CandidateMap < ActionWebService::Struct
+class QuickVoteCandidateMap < ActionWebService::Struct
   member :candidate_ids, [:int]
   member :candidate_names, [:string]
 end
 class SelectricityAPI < ActionWebService::API::Base
   api_method :cast_quickvote, :expects => [:string, :int, [[:int]]], :returns => [:string]
-  api_method :get_quickvote_results, :expects => [:string], :returns => [VoteResultStruct]
-  api_method :get_quickvote_candidate_map, :expects => [:string], :returns => [CandidateMap]
+  api_method :get_quickvote_results, :expects => [:string], :returns => [QuickVoteResultStruct]
+  api_method :get_quickvote_candidate_map, :expects => [:string], :returns => [QuickVoteCandidateMap]
   api_method :quickvote_candidate_ids_to_names, :expects => [:string,[:int]], :returns => [[:string]]
-  api_method :get_quickvote_votes, :expects => [:string], :returns => [ [VoteInfo] ]
-  api_method :list_quickvotes, :expects => [], :returns => [[ElectionStruct]]
-  api_method :get_quickvote, :expects => [:string], :returns => [ElectionStruct]
-  api_method :create_quickvote, :expects => [ElectionStruct], :returns => [:string]
+  api_method :get_quickvote_votes, :expects => [:string], :returns => [ [QuickVoterInfo] ]
+  api_method :list_quickvotes, :expects => [], :returns => [[QuickVoteStruct]]
+  api_method :get_quickvote, :expects => [:string], :returns => [QuickVoteStruct]
+  api_method :create_quickvote, :expects => [QuickVoteStruct], :returns => [:string]
 end
-
-
index 544b618d7c78fddce9fb5d91f8a3a65cf263264c..a3de89f4923a6f225c1dbe60e5e4d62909a2aed9 100644 (file)
@@ -45,7 +45,7 @@ class SelectricityService < ActionWebService::Base
   def get_quickvote_results(shortname)
     #TODO: Validate shortname
     qv=QuickVote.ident_to_quickvote(shortname)
-    result=VoteResultStruct.new
+    result=QuickVoteResultStruct.new
     unless qv
       raise ArgumentError.new("No quickvote with name #{shortname} found!")
     end
@@ -59,7 +59,7 @@ class SelectricityService < ActionWebService::Base
   end
   def get_quickvote_candidate_map(shortname)
     qv=QuickVote.ident_to_quickvote(shortname)
-    result=CandidateMap.new
+    result=QuickVoteCandidateMap.new
     unless qv
       raise ArgumentError.new("No quickvote with name #{shortname} found!")
     end
@@ -78,7 +78,7 @@ class SelectricityService < ActionWebService::Base
     end
 
     qv.votes.collect do |vote|
-       VoteInfo.new(:voter_id => vote.voter.id,
+       QuickVoterInfo.new(:voter_id => vote.voter.id,
                     :voter_ipaddress => vote.voter.ipaddress,
                     :vote_time => vote.time.to_i,
                     :vote => vote.votes,
@@ -97,7 +97,7 @@ class SelectricityService < ActionWebService::Base
       raise ArgumentError.new("Cannot find QuickVote named #{shortname}")
     end
 
-    ElectionStruct.new(
+    QuickVoteStruct.new(
       :id => election.id,
       :name => election.name,
       :description => election.description,
index 4ea61b7973e5dc269191f16b03c1c4cdfbcba66a..590425d670859ee07aab24761a30d00f5c780eb2 100644 (file)
@@ -5,12 +5,9 @@
 ActiveRecord::Schema.define() do
 
   create_table "candidates", :force => true do |t|
-    t.column "election_id",      :integer,                                :null => false
-    t.column "name",             :string,  :limit => 100, :default => "", :null => false
-    t.column "description",      :text
-    t.column "picture_filename", :string,  :limit => 200
-    t.column "picture_data",     :binary
-    t.column "picture_type",     :string,  :limit => 100
+    t.column "election_id", :integer,                                :null => false
+    t.column "name",        :string,  :limit => 100, :default => "", :null => false
+    t.column "description", :text
   end
 
   create_table "elections", :force => true do |t|
@@ -30,12 +27,31 @@ ActiveRecord::Schema.define() do
 
   add_index "elections", ["user_id"], :name => "fk_user_election"
 
+  create_table "pictures", :force => true do |t|
+    t.column "filename",     :string,  :limit => 200
+    t.column "data",         :binary
+    t.column "filetype",     :string,  :limit => 100
+    t.column "candidate_id", :integer
+  end
+
+  add_index "pictures", ["candidate_id"], :name => "fk_candidate_picture"
+
   create_table "rankings", :force => true do |t|
     t.column "vote_id",      :integer
     t.column "candidate_id", :integer
     t.column "rank",         :integer
   end
 
+  create_table "sitealizer", :force => true do |t|
+    t.column "path",       :string
+    t.column "ip",         :string
+    t.column "referer",    :string
+    t.column "language",   :string
+    t.column "user_agent", :string
+    t.column "created_at", :datetime
+    t.column "created_on", :date
+  end
+
   create_table "tokens", :force => true do |t|
     t.column "token",   :string,  :limit => 100, :default => "", :null => false
     t.column "vote_id", :integer,                                :null => false
index e5c279008339815d1aa9835a3fdcb2f57a33025b..f9d4392242d22ab736f0d74e63ea90bb18b94145 100644 (file)
@@ -102,7 +102,7 @@ class GraphControllerTest < Test::Unit::TestCase
 
   private
   def make_election
-    e=ElectionStruct.new( :name => "test", :description => "This is a test",
+    e=QuickVoteStruct.new( :name => "test", :description => "This is a test",
                           :candidate_names => ['choice1', 'choice2', 'choice3'])
     @SS.create_quickvote e
     @election = @SS.list_quickvotes[0]
index 1c28cf1b5277a4125f99953444bd80dcb1aabdc0..cdc2b4239b12348e010759ad4412ce063e49201f 100644 (file)
@@ -15,7 +15,7 @@ class SelectricityServiceTest < Test::Unit::TestCase
   end
 
   def test_create_quickvote
-    election = ElectionStruct.new(
+    election = QuickVoteStruct.new(
       { :name => "TestVote",
         :description => "Test Vote",
         :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"] })
@@ -88,7 +88,7 @@ class SelectricityServiceTest < Test::Unit::TestCase
 
   def test_create_mass_quickvote
     10.times do |t|
-      assert_create_quickvote_succeeds ElectionStruct.new({
+      assert_create_quickvote_succeeds QuickVoteStruct.new({
         :name => "test#{t}",
         :description => "Test Vote",
         :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
@@ -96,7 +96,7 @@ class SelectricityServiceTest < Test::Unit::TestCase
   end
 
   def test_create_quickvote_bad_name
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "invalid space",
       :description => "Test Vote",
       :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
@@ -104,58 +104,58 @@ class SelectricityServiceTest < Test::Unit::TestCase
   end
 
   def test_create_quickvote_nil
-    assert_create_quickvote_fails ElectionStruct.new()
+    assert_create_quickvote_fails QuickVoteStruct.new()
   end
 
   def test_create_quickvote_name_nil
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "",
       :description => "Test Vote",
       :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
   end
 
   def test_create_quickvote_description_nil
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => nil,
       :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
   end
   
   def test_create_quickvote_description_whitespace
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "       ",
       :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
 
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "\t\t",
       :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
   end
   
   def test_create_quickvote_candidates_nil
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "valid",
       :candidate_names => nil })
   end
 
   def test_create_quickvote_insufficient_candidates
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "valid",
       :candidate_names => ["Apple"] })
   end
 
   def test_create_quickvote_candidates_whitespace
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "valid",
       :candidate_names => [" ", "   ", "       ", "         "]})
   end
 
   def test_create_quickvote_dupe_candidates
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "valid",
       :candidate_names => ["Apple", "Apple", "Apple", "Apple"]})
@@ -166,7 +166,7 @@ class SelectricityServiceTest < Test::Unit::TestCase
     # We don't want this to happen. Dupe canidates should fail
     # regardless of how many are left.
 
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "valid",
       :candidate_names => ["Apple", "Apple", "Orange",
@@ -174,7 +174,7 @@ class SelectricityServiceTest < Test::Unit::TestCase
   end
 
   def test_create_quickvote_candidates_nil_mixed
-    assert_create_quickvote_fails ElectionStruct.new({
+    assert_create_quickvote_fails QuickVoteStruct.new({
       :name => "foobar",
       :description => "valid",
       :candidate_names => ["Apple", nil ]})
@@ -183,21 +183,21 @@ class SelectricityServiceTest < Test::Unit::TestCase
 
   def test_create_quickvote_description_xmlescape
     # Will an embedded XML element bork the table?
-    assert_create_quickvote_succeeds ElectionStruct.new({
+    assert_create_quickvote_succeeds QuickVoteStruct.new({
       :name => "foobar",
       :description => "test </string>",
       :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
   end
 
   def test_create_quickvote_unprintable_description
-    assert_create_quickvote_succeeds ElectionStruct.new ({
+    assert_create_quickvote_succeeds QuickVoteStruct.new ({
       :name => "foobar",
       :description => "test \x01\x02\x03\x04\x05\x06\x07\x08",
       :candidate_names => ["Apple", "Orange", "Banana", "Pineapple"]})
   end
 
   def test_quickvote_proper_results
-    assert_create_quickvote_succeeds ElectionStruct.new({
+    assert_create_quickvote_succeeds QuickVoteStruct.new({
       :name => "favdev",
       :description => "Who is your favorite developer?",
       :candidate_names => ["mako", "jdong", "justin"]})

Benjamin Mako Hill || Want to submit a patch?