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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
require 'spec_helper'
require 'support/http_stub.rb'
describe AgendaItem do
it 'should allow all registered users to create' do
a = AgendaItem.new
for u in users_factory(:user, :council, :admin, :council_admin)
a.user = u
a.should be_creatable_by(u)
end
end
it 'should allow only administrators to destroy' do
a = Factory(:agenda_item)
for u in users_factory(:guest, :user, :council)
a.should_not be_destroyable_by(u)
end
for u in users_factory(:admin, :council_admin)
a.user = u
a.should be_destroyable_by(u)
end
end
it 'should allow owner, council members and administrators to edit and update unassigned items' do
owner = Factory(:user)
a = Factory(:agenda_item, :user => owner)
for u in users_factory(:guest, :user)
a.should_not be_editable_by(u)
a.should_not be_updatable_by(u)
end
for u in users_factory(:council, :admin, :council_admin) + [owner]
a.should be_editable_by(u)
a.should be_updatable_by(u)
end
end
it 'should allow only council members and administrators to edit and update assigned items' do
owner = Factory(:user)
agenda = Agenda.last || Factory(:agenda)
a = Factory(:agenda_item, :user => owner, :agenda => agenda)
for u in users_factory(:guest, :user) + [owner]
a.should_not be_editable_by(u)
a.should_not be_updatable_by(u)
end
for u in users_factory(:council, :admin, :council_admin)
a.should be_editable_by(u)
a.should be_updatable_by(u)
end
end
it 'should allow no one edit and update items assigned to archived agenda' do
owner = Factory(:user)
agenda = Factory(:agenda, :state => 'old')
a = Factory(:agenda_item, :user => owner, :agenda => agenda)
for u in users_factory(AllRoles) + [owner]
a.should_not be_editable_by(u)
a.should_not be_updatable_by(u)
end
end
it 'should allow owner, council memebers and administrators to edit some fields' do
owner = Factory(:user)
a = Factory(:agenda_item, :user => owner)
for u in users_factory(:council, :admin, :council_admin) + [owner]
a.should be_editable_by(u, :title)
a.should be_editable_by(u, :discussion)
a.should be_editable_by(u, :body)
end
end
it 'should allow only council memebers and administrators to edit some fields' do
owner = Factory(:user)
a = Factory(:agenda_item, :user => owner)
for u in users_factory(:council, :admin, :council_admin)
a.should be_editable_by(u, :agenda)
a.should be_editable_by(u, :rejected)
end
a.should_not be_editable_by(owner, :agenda)
a.should_not be_editable_by(owner, :rejected)
end
it 'should allow no one to edit some fields' do
owner = Factory(:user)
a = Factory(:agenda_item, :user => owner)
for u in users_factory(:guest, :user, :council, :admin, :council_admin) + [owner]
a.should_not be_editable_by(u, :user)
end
end
it 'should not allow to edit agenda if rejected' do
agenda = Agenda.last || Factory(:agenda)
a = Factory(:agenda_item, :agenda => agenda)
for u in users_factory(:guest, :user, :council, :admin, :council_admin)
a.should_not be_editable_by(u, :rejected)
end
end
it 'should not allow to reject if assigned to agenda' do
a = Factory(:agenda_item, :rejected => true)
for u in users_factory(:guest, :user, :council, :admin, :council_admin)
a.should_not be_editable_by(u, :agenda)
end
end
it 'should make sure timelimits are valid' do
valid_timelimits = ["", "0:0", "1:1 message", "1:2 longer message",
"30:40 a few messages\n5:60 as separate lines"]
invalid_timelimits = ["a:0", "1:", "2:a", ":0", " 1:1 message",
"30:40 a few messages\n\n5:60 and an empty line",
"30:40 a few messages\n5:60 and an wrong line\na:"]
valid_timelimits.each do |limit|
Factory(:agenda_item, :timelimits => limit).should be_valid
end
invalid_timelimits.each do |limit|
item = AgendaItem.new :title => 'title', :timelimits => limit
item.should_not be_valid
item.errors.length.should be_equal(1)
item.errors[:timelimits].should_not be_nil
end
end
describe '.update_discussion_time' do
it 'should do nothing if discussion is not url to discussion on gentoo archives' do
items = [Factory(:agenda_item),
Factory(:agenda_item, :discussion_time => 'something'),
Factory(:agenda_item, :discussion => 'http://archives.gentoo.org/gentoo-bsd/'),
Factory(:agenda_item, :discussion_time => 'something',
:discussion => 'http://archives.gentoo.org/gentoo-bsd/')]
items.each do |item|
lambda {
item.send(:update_discussion_time)
}.should_not change(item, :discussion_time)
end
end
it 'should set discussion_time properly if discussion is url to discussion on gentoo archives' do
item = Factory(:agenda_item,
:discussion =>
'http://archives.gentoo.org/gentoo-soc/msg_e490369a0c7e6c279af9baef63897629.xml')
lambda {
item.send(:update_discussion_time)
}.should change(item, :discussion_time).from('').to('From 2011.05.30 to 2011.06.28, 28 full days')
end
end
end
|