1 require File.dirname(__FILE__) + '/../test_helper'
3 class QuickVoteTest < Test::Unit::TestCase
4 fixtures :elections, :candidates
8 @qv = QuickVote.find(1)
11 @candidates = ['mako', 'mika', 'bettamax']
12 @candidates.each do |name|
13 @qv.candidates << Candidate.new({:name => name})
18 def test_add_remove_candidates
19 # make sure the names are right
20 assert_equal 3, @qv.candidates.length
21 assert_equal @candidates.sort,
22 @qv.candidates.collect {|c| c.name}.sort
25 @qv.candidates << Candidate.new({:name => 'erik'})
28 assert_equal 4, @qv.candidates.length
29 assert_equal (@candidates + ['erik']).sort,
30 @qv.candidates.collect {|c| c.name}.sort
32 # drop erik and try again
34 @qv.candidates.select {|c| c.name != 'erik'}
37 assert_equal 3, @qv.candidates.length
38 assert_equal @candidates.sort,
39 @qv.candidates.collect {|c| c.name}.sort
42 def test_create_update_quickvote
43 assert_kind_of QuickVote, @qv
44 assert_equal 1, @qv.id
45 assert_equal 'acetarium', @qv.name
46 assert_equal 'who is the winner?', @qv.description
47 assert_equal 'ssd', @qv.election_method
48 assert_equal '2007-08-22 12:00:00', @qv.startdate_before_type_cast
49 assert_equal '2010-09-21 11:59:59', @qv.enddate_before_type_cast
51 # should be set by default default results
52 assert_equal false, @qv.early_results
53 assert_equal false, @qv.kiosk
54 assert_equal true, @qv.authenticated
55 assert_equal false, @qv.embeddable
56 assert_equal true, @qv.verifiable
61 @qv.errors.full_messages.join("; ")
64 assert_equal 'foobar', @qv.name
67 def test_create_invalid_enddate
68 @qv.enddate = '2003-09-21 11:59:59 '
69 assert_equal @qv.save, false, "created vote with invalid enddate"
75 voter = QuickVoter.new
77 voter.session_id = UniqueTokenGenerator.new(20).token
81 voter.vote.set_defaults!
82 assert_nil voter.vote.confirm!
86 assert_equal 50, @qv.voters.length
87 assert_equal 50, @qv.voters.collect {|v| v.vote}.length
88 assert_equal 50, @qv.voters.select {|v| v.vote.confirmed?}.length
91 def test_build_results
95 assert qvb = QuickVote.find(954)
96 assert_kind_of QuickVote, qvb
97 assert_equal 17, qvb.candidates.length
100 def test_for_reload_errors
101 qvb = QuickVote.find(954)
105 assert_equal (4666..4682).to_a, qvb.candidates.collect {|c| c.id}.sort