1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
require 'spec_helper'
describe VotingOption do
it 'should allow only council members to create' do
v = Factory(:voting_option)
for u in users_factory(:guest, :user, :admin)
v.should_not be_creatable_by(u)
end
for u in users_factory(:council, :council_admin)
v.should be_creatable_by(u)
end
end
it 'should allow only council members to update and destroy if it belongs to open agenda' do
v = Factory(:voting_option)
for u in users_factory(:guest, :user, :admin)
v.should_not be_updatable_by(u)
v.should_not be_destroyable_by(u)
end
for u in users_factory(:council, :council_admin)
v.should be_updatable_by(u)
v.should be_destroyable_by(u)
end
end
it 'should allow no one to update and destroy if it belongs to closed or archived agenda' do
a1 = Factory(:agenda, :state => 'closed')
i1 = Factory(:agenda_item, :agenda => a1)
v1 = Factory(:voting_option, :agenda_item => i1)
a2 = Factory(:agenda, :state => 'old')
i2 = Factory(:agenda_item, :agenda => a2)
v2 = Factory(:voting_option, :agenda_item => i2)
for u in users_factory(:all_roles)
v1.should_not be_updatable_by(u)
v1.should_not be_destroyable_by(u)
v2.should_not be_updatable_by(u)
v2.should_not be_destroyable_by(u)
end
end
it 'should allow everyone to view' do
v = Factory(:voting_option)
for u in users_factory(:all_roles)
v.should be_viewable_by(u)
end
end
it 'should return proper community votes count' do
item = Factory(:agenda_item)
option_a = Factory(:voting_option, :agenda_item => item, :description => 'a')
option_b = Factory(:voting_option, :agenda_item => item, :description => 'b')
(1..3).each { |i| Factory(:vote, :council_vote => false, :voting_option => option_a) }
(1..7).each { |i| Factory(:vote, :council_vote => false, :voting_option => option_b) }
option_a.community_votes.should == '3 of 10 (30%) votes.'
option_b.community_votes.should == '7 of 10 (70%) votes.'
end
end
|