Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/council-webapp:master commit in: site/spec/support/, site/spec/models/
Date: Mon, 01 Aug 2011 14:39:02
Message-Id: 1dbf95ed30e66eec2247d38ed7f79b13f8bc0a1d.betelgeuse@gentoo
1 commit: 1dbf95ed30e66eec2247d38ed7f79b13f8bc0a1d
2 Author: Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
3 AuthorDate: Tue Jul 26 14:15:23 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Tue Jul 26 14:15:23 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=1dbf95ed
7
8 Improve tests
9
10 use :all_roles and :registered to make users in factory
11
12 ---
13 site/spec/models/agenda_item_spec.rb | 2 +-
14 site/spec/models/agenda_spec.rb | 10 +++++-----
15 site/spec/models/approval_spec.rb | 2 +-
16 site/spec/models/participation_spec.rb | 4 ++--
17 site/spec/models/proxy_spec.rb | 6 +++---
18 site/spec/models/user_spec.rb | 6 +++---
19 site/spec/models/vote_spec.rb | 10 +++++-----
20 site/spec/models/voting_option_spec.rb | 4 ++--
21 site/spec/support/users_factory.rb | 15 +++++++++++++--
22 9 files changed, 35 insertions(+), 24 deletions(-)
23
24 diff --git a/site/spec/models/agenda_item_spec.rb b/site/spec/models/agenda_item_spec.rb
25 index 961b663..fe4f906 100644
26 --- a/site/spec/models/agenda_item_spec.rb
27 +++ b/site/spec/models/agenda_item_spec.rb
28 @@ -52,7 +52,7 @@ describe AgendaItem do
29 owner = Factory(:user)
30 agenda = Factory(:agenda, :state => 'old')
31 a = Factory(:agenda_item, :user => owner, :agenda => agenda)
32 - for u in users_factory(AllRoles) + [owner]
33 + for u in users_factory(:all_roles) + [owner]
34 a.should_not be_editable_by(u)
35 a.should_not be_updatable_by(u)
36 end
37
38 diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb
39 index b9e564c..738db63 100644
40 --- a/site/spec/models/agenda_spec.rb
41 +++ b/site/spec/models/agenda_spec.rb
42 @@ -3,7 +3,7 @@ require 'spec_helper'
43 describe Agenda do
44 it 'shouldn not allow anyone to create' do
45 a = Agenda.new
46 - for u in users_factory(AllRoles)
47 + for u in users_factory(:all_roles)
48 a.should_not be_creatable_by(u)
49 a.should_not be_destroyable_by(u)
50 end
51 @@ -11,14 +11,14 @@ describe Agenda do
52
53 it 'shouldn not allow anyone to destory' do
54 a = Factory(:agenda)
55 - for u in users_factory(AllRoles)
56 + for u in users_factory(:all_roles)
57 a.should_not be_destroyable_by(u)
58 end
59 end
60
61 it 'should allow everybody to view' do
62 a = Factory(:agenda)
63 - for u in users_factory(AllRoles)
64 + for u in users_factory(:all_roles)
65 a.should be_viewable_by(u)
66 end
67 end
68 @@ -32,7 +32,7 @@ describe Agenda do
69
70 (1..4).each { |i| Factory(:approval, :agenda => agenda) }
71
72 - for u in users_factory(AllRoles)
73 + for u in users_factory(:all_roles)
74 agenda.should be_viewable_by(u, :summary)
75 end
76 end
77 @@ -49,7 +49,7 @@ describe Agenda do
78 a = Factory(:agenda)
79 a.meeting_log = 'changed'
80
81 - for u in users_factory(AllRoles)
82 + for u in users_factory(:all_roles)
83 a.should_not be_editable_by(u, :meeting_log)
84 a.should_not be_updatable_by(u)
85 end
86
87 diff --git a/site/spec/models/approval_spec.rb b/site/spec/models/approval_spec.rb
88 index 4057a6d..701504e 100644
89 --- a/site/spec/models/approval_spec.rb
90 +++ b/site/spec/models/approval_spec.rb
91 @@ -3,7 +3,7 @@ require 'spec_helper'
92 describe Approval do
93 it 'should be viewable by everybody' do
94 approval = Factory(:approval)
95 - for user in users_factory(AllRoles)
96 + for user in users_factory(:all_roles)
97 approval.should be_viewable_by(user)
98 end
99 end
100
101 diff --git a/site/spec/models/participation_spec.rb b/site/spec/models/participation_spec.rb
102 index 395dc03..75485e6 100644
103 --- a/site/spec/models/participation_spec.rb
104 +++ b/site/spec/models/participation_spec.rb
105 @@ -3,7 +3,7 @@ require 'spec_helper'
106 describe Participation do
107 it 'should not allow anyone to create, edit, update or destroy' do
108 p = Factory(:participation)
109 - for u in users_factory(AllRoles)
110 + for u in users_factory(:all_roles)
111 p.should_not be_creatable_by(u)
112 p.should_not be_editable_by(u)
113 p.should_not be_updatable_by(u)
114 @@ -13,7 +13,7 @@ describe Participation do
115
116 it 'should allow everybody to view' do
117 p = Factory(:participation)
118 - for u in users_factory(AllRoles)
119 + for u in users_factory(:all_roles)
120 p.should be_viewable_by(u)
121 end
122 end
123
124 diff --git a/site/spec/models/proxy_spec.rb b/site/spec/models/proxy_spec.rb
125 index a94aa06..995ebb1 100644
126 --- a/site/spec/models/proxy_spec.rb
127 +++ b/site/spec/models/proxy_spec.rb
128 @@ -63,7 +63,7 @@ describe Proxy do
129
130 it 'should allow no one to update or edit' do
131 p = Factory(:proxy)
132 - for u in users_factory(AllRoles) + [p.council_member, p.proxy]
133 + for u in users_factory(:all_roles) + [p.council_member, p.proxy]
134 p.should_not be_editable_by(u)
135 p.should_not be_updatable_by(u)
136 end
137 @@ -72,7 +72,7 @@ describe Proxy do
138
139 it 'should allow everyone to view' do
140 p = Factory(:proxy)
141 - for u in users_factory(AllRoles) + [p.council_member, p.proxy]
142 + for u in users_factory(:all_roles) + [p.council_member, p.proxy]
143 p.should be_viewable_by(u)
144 end
145 end
146 @@ -92,7 +92,7 @@ describe Proxy do
147 it 'should not allow users to destoy someone else proxy' do
148 a = Factory(:agenda)
149 p = Factory(:proxy, :agenda => a)
150 - for u in users_factory(AllRoles)
151 + for u in users_factory(:all_roles)
152 p.should_not be_destroyable_by(u)
153 end
154 end
155
156 diff --git a/site/spec/models/user_spec.rb b/site/spec/models/user_spec.rb
157 index ad36761..c9f36b9 100644
158 --- a/site/spec/models/user_spec.rb
159 +++ b/site/spec/models/user_spec.rb
160 @@ -90,7 +90,7 @@ describe User do
161 end
162
163 it 'should allow no one to create' do
164 - for u in users_factory(AllRoles)
165 + for u in users_factory(:all_roles)
166 User.new.should_not be_creatable_by(u)
167 end
168 end
169 @@ -106,8 +106,8 @@ describe User do
170 end
171
172 it 'should allow everybody to view' do
173 - for u1 in users_factory(AllRoles)
174 - for u2 in users_factory(AllRoles - [:guest])
175 + for u1 in users_factory(:all_roles)
176 + for u2 in users_factory(:registered)
177 u2.should be_viewable_by(u1)
178 end
179 end
180
181 diff --git a/site/spec/models/vote_spec.rb b/site/spec/models/vote_spec.rb
182 index f2d529e..5f53a69 100644
183 --- a/site/spec/models/vote_spec.rb
184 +++ b/site/spec/models/vote_spec.rb
185 @@ -2,7 +2,7 @@ require 'spec_helper'
186
187 describe Vote do
188 it 'should allow anyone to create, update and destroy their own votes' do
189 - for u in users_factory(AllRoles - [:guest]) do
190 + for u in users_factory(:registered) do
191 vote = Factory(:vote, :user => u)
192 vote.should be_creatable_by(u)
193 vote.should be_updatable_by(u)
194 @@ -12,7 +12,7 @@ describe Vote do
195
196 it 'should not allow anyone to create, update and destroy vote of someone else' do
197 vote = Factory(:vote)
198 - for u in users_factory(AllRoles) do
199 + for u in users_factory(:all_roles) do
200 vote.should_not be_creatable_by(u)
201 vote.should_not be_updatable_by(u)
202 vote.should_not be_destroyable_by(u)
203 @@ -21,13 +21,13 @@ describe Vote do
204
205 it 'should allow anyone to view' do
206 vote = Factory(:vote)
207 - for u in users_factory(AllRoles) do
208 + for u in users_factory(:all_roles) do
209 vote.should be_viewable_by(u)
210 end
211 end
212
213 it 'should allow all users to vote' do
214 - for u in users_factory(AllRoles - [:guest]) do
215 + for u in users_factory(:registered) do
216 Vote.new(:user => u, :voting_option => Factory(:voting_option)).should be_valid
217 end
218 end
219 @@ -39,7 +39,7 @@ describe Vote do
220 end
221
222 it 'should prevent users from setting council_vote to true' do
223 - for u in users_factory(AllRoles - [:guest])
224 + for u in users_factory(:registered)
225 v = Factory(:vote, :user => u, :council_vote => true)
226 v.should_not be_editable_by(u)
227 v.should_not be_updatable_by(u)
228
229 diff --git a/site/spec/models/voting_option_spec.rb b/site/spec/models/voting_option_spec.rb
230 index 87074c6..5054f43 100644
231 --- a/site/spec/models/voting_option_spec.rb
232 +++ b/site/spec/models/voting_option_spec.rb
233 @@ -31,7 +31,7 @@ describe VotingOption do
234 a2 = Factory(:agenda, :state => 'old')
235 i2 = Factory(:agenda_item, :agenda => a2)
236 v2 = Factory(:voting_option, :agenda_item => i2)
237 - for u in users_factory(AllRoles)
238 + for u in users_factory(:all_roles)
239 v1.should_not be_updatable_by(u)
240 v1.should_not be_destroyable_by(u)
241 v2.should_not be_updatable_by(u)
242 @@ -41,7 +41,7 @@ describe VotingOption do
243
244 it 'should allow everyone to view' do
245 v = Factory(:voting_option)
246 - for u in users_factory(AllRoles)
247 + for u in users_factory(:all_roles)
248 v.should be_viewable_by(u)
249 end
250 end
251
252 diff --git a/site/spec/support/users_factory.rb b/site/spec/support/users_factory.rb
253 index 40c715b..126a7b9 100644
254 --- a/site/spec/support/users_factory.rb
255 +++ b/site/spec/support/users_factory.rb
256 @@ -1,6 +1,19 @@
257 def users_factory(*roles)
258 roles.flatten!
259 + roles.collect! do |role|
260 + case role
261 + when :all_roles
262 + [:guest, :user, :council, :admin, :council_admin]
263 + when :registered
264 + [:user, :council, :admin, :council_admin]
265 + else
266 + role
267 + end
268 + end
269 + roles.flatten!
270 +
271 r = []
272 + roles
273 for role in roles
274 case role
275 when :guest
276 @@ -17,5 +30,3 @@ def users_factory(*roles)
277 end
278 (r.count < 2) ? r.first : r
279 end
280 -
281 -AllRoles = [:guest, :user, :council, :admin, :council_admin]