From a8006b0bf9687f8882c3073eca2e8b4ebc7cde4a Mon Sep 17 00:00:00 2001 From: Date: Wed, 22 Aug 2007 18:27:50 -0400 Subject: [PATCH] Started Creation of "advanced" quickvote tab. Also started to create a quickvote model testing class, but it has no tests yet. --- app/controllers/quickvote_controller.rb | 3 +++ app/models/election.rb | 11 ++++++----- app/models/quick_vote.rb | 21 +++++++++++++-------- app/views/quickvote/_advanced.rhtml | 11 +++++++++++ app/views/quickvote/create.rhtml | 12 ++++++++++++ test/unit/quickvote_test.rb | 11 +++++++++++ 6 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 app/views/quickvote/_advanced.rhtml create mode 100644 test/unit/quickvote_test.rb diff --git a/app/controllers/quickvote_controller.rb b/app/controllers/quickvote_controller.rb index 54784ef..0d165cb 100644 --- a/app/controllers/quickvote_controller.rb +++ b/app/controllers/quickvote_controller.rb @@ -29,6 +29,7 @@ class QuickvoteController < ApplicationController # here has not been hitting this page and we can clear any # candlist in the flash flash.delete(:candlist) if flash.has_key?(:candlist) + @quickvote = QuickVote.new end end @@ -166,3 +167,5 @@ class QuickvoteController < ApplicationController @election.candidates.each {|c| @candidates[c.id] = c} end end + + diff --git a/app/models/election.rb b/app/models/election.rb index 59a10bf..7343d72 100644 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -15,6 +15,12 @@ class Election < ActiveRecord::Base require 'date' + def initialize(params={}) + super + self.enddate = read_attribute( :enddate ) || \ + Time.now + 14.days - 1.second + end + def other_methods if election_method @other_methods = ELECTION_TYPES.reject {|i| i == election_method} @@ -27,11 +33,6 @@ class Election < ActiveRecord::Base def startdate read_attribute( :startdate ) || Time.now end - - def enddate - date = read_attribute( :enddate ) || Time.now + 14 - date - 1.second - end def enddate=(date) date += 1.day diff --git a/app/models/quick_vote.rb b/app/models/quick_vote.rb index c0367d6..c04b0d7 100644 --- a/app/models/quick_vote.rb +++ b/app/models/quick_vote.rb @@ -5,6 +5,19 @@ class QuickVote < Election attr_accessor :raw_candidates attr_accessor :reviewed + def initialize(params={}) + super + self.startdate = Time.now + self.active = 1 + self.anonymous = 1 unless self.anonymous + self.enddate = read_attribute( :enddate ) || \ + Time.now + 30.days - 1.second + end + + def enddate + super(30) + end + def validate if not @raw_candidates or @raw_candidates.length < 2 errors.add(nil, "You must list at least two candidates.") @@ -35,14 +48,6 @@ class QuickVote < Election errors.add(:name, " is a reserved word.") end end - - def initialize(params={}) - super - self.startdate = Time.now - self.enddate = Time.now + 30.days - self.active = 1 - self.anonymous = 1 - end def candidatelist=(candlist) @raw_candidates = candlist diff --git a/app/views/quickvote/_advanced.rhtml b/app/views/quickvote/_advanced.rhtml new file mode 100644 index 0000000..5699fd0 --- /dev/null +++ b/app/views/quickvote/_advanced.rhtml @@ -0,0 +1,11 @@ + +<% fields_for 'quickvote', quickvote do |quickform| %> + +
+<%= quickform.select ('election_method', + %w(ssd condorcet plurality approval borda) ) %>
+ +
+<%= quickform.date_select(:enddate) %>
+ +<% end %> diff --git a/app/views/quickvote/create.rhtml b/app/views/quickvote/create.rhtml index cf91e19..a7ccd63 100644 --- a/app/views/quickvote/create.rhtml +++ b/app/views/quickvote/create.rhtml @@ -24,7 +24,19 @@ <%= text_area 'quickvote', 'description', :cols => 50, :rows => 4 %>

+<%= check_box('options', 'advanced', + :onclick => 'Element.toggle($("advanced")); false;' )%>Advanced + + +
+ <%= submit_tag "Create Quickvote" -%> <% end %> + + + + diff --git a/test/unit/quickvote_test.rb b/test/unit/quickvote_test.rb new file mode 100644 index 0000000..4282a70 --- /dev/null +++ b/test/unit/quickvote_test.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class QuickVoteTest < Test::Unit::TestCase + + def correct_enddate + + end + + + +end \ No newline at end of file -- 2.30.2