From d207da8dfc3f315f7758d1f5307c700ce4c25156 Mon Sep 17 00:00:00 2001 From: Date: Wed, 11 Oct 2006 01:34:23 -0400 Subject: [PATCH] Added initial support fo QuickVotes. There is support for the creation of quickvotes in the database. There is not yet support for voting in quickvotes. --- app/controllers/election_controller.rb | 2 - app/controllers/site_controller.rb | 11 ++++++ app/models/candidate.rb | 3 +- app/models/quick_vote.rb | 51 ++++++++++++++++++++++++++ app/views/layouts/vb.rhtml | 8 ++-- app/views/site/create_quickvote.rhtml | 46 +++++++++++++++++++++++ app/views/site/index.rhtml | 11 ++++++ app/views/site/success_quickvote.rhtml | 15 ++++++++ db/migrate/001_create_quick_votes.rb | 11 ++++++ test/fixtures/quick_votes.yml | 5 +++ test/unit/quick_vote_test.rb | 10 +++++ 11 files changed, 166 insertions(+), 7 deletions(-) create mode 100644 app/models/quick_vote.rb create mode 100644 app/views/site/create_quickvote.rhtml create mode 100644 app/views/site/success_quickvote.rhtml create mode 100644 db/migrate/001_create_quick_votes.rb create mode 100644 test/fixtures/quick_votes.yml create mode 100644 test/unit/quick_vote_test.rb diff --git a/app/controllers/election_controller.rb b/app/controllers/election_controller.rb index 46da56e..7e8273e 100644 --- a/app/controllers/election_controller.rb +++ b/app/controllers/election_controller.rb @@ -54,8 +54,6 @@ class ElectionController < ApplicationController @election.voters.each do |voter| email = VoterNotify.create_votestart(voter) render(:text => "
" + email.encoded + "
") - breakpoint - break end #@election.activate! diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index f2eb153..f4bae42 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -10,4 +10,15 @@ class SiteController < ApplicationController end end end + + def create_quickvote + if params[:quickvote] + @quickvote = QuickVote.new(params[:quickvote]) + if @quickvote.reviewed? and @quickvote.save + @quickvote = @quickvote.reload + render :action => 'success_quickvote' + end + end + end + end diff --git a/app/models/candidate.rb b/app/models/candidate.rb index 7b6e802..430b6ab 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -1,8 +1,9 @@ class Candidate < ActiveRecord::Base belongs_to :election - validates_uniqueness_of :name validates_presence_of :name + # validate uniqueness of a name *within a given election* + def <=>(other) self.name <=> other.name end diff --git a/app/models/quick_vote.rb b/app/models/quick_vote.rb new file mode 100644 index 0000000..d6ab55b --- /dev/null +++ b/app/models/quick_vote.rb @@ -0,0 +1,51 @@ +class QuickVote < Election + after_validation :create_candidates + validates_uniqueness_of :name + attr_accessor :raw_candidates + attr_accessor :reviewed + + def validate + if @raw_candidates.length < 2 + errors.add("You must list at least two candidates.") + end + + if name =~ /[^A-Za-z0-9]/ + errors.add("The name must only include numbers and letters.") + end + end + + def initialize(params={}) + super + self.enddate = DateTime.now + 30 + self.active = 1 + self.anonymous = 1 + end + + def candidatelist=(candstring='') + @raw_candidates = candstring.split(';').collect {|cand| cand.strip } + end + + def candidatelist + @raw_candidates.join("; ") + end + + def name + read_attribute( :name ).downcase() + end + + def reviewed? + if reviewed.to_i == 1 + return true + else + false + end + end + + def create_candidates + @raw_candidates.each do |name| + candidate = Candidate.new({:name => name}) + candidate.save + self.candidates << candidate + end + end +end diff --git a/app/views/layouts/vb.rhtml b/app/views/layouts/vb.rhtml index a05ae54..3e4f8bd 100644 --- a/app/views/layouts/vb.rhtml +++ b/app/views/layouts/vb.rhtml @@ -1,7 +1,7 @@ <% %> - <%= @page_title || "VotingBooth" %> + <%= @page_title || "HyperChad" %> <%= stylesheet_link_tag "vb", :media => "all" %> <% #engine_stylesheet 'login_engine' %> @@ -12,8 +12,8 @@ <% if @page_title %>

<%= @page_title %>

<% else %> -

Voting Booth
- Preferential Voting on the Web

+

HyperChad
+ Voting Machinery for the Masses

<% end %>
-