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
|
require 'spec_helper.rb'
describe QuestionGroup do
include Permissions::TestPermissions
it "should allow admin to create, edit, update and remove" do
cud_allowed([Factory(:administrator)], Factory(:question_group))
end
it "should prohibit nonadmins to creating, editing, updating and removing" do
cud_denied([Factory(:recruit), Factory(:mentor), Guest.new,
Factory(:recruiter)], Factory(:question_group))
end
it "should be allowed for everybody to view" do
view_allowed([Factory(:recruit), Factory(:mentor), Factory(:recruiter),
Factory(:administrator), Guest.new], Factory(:question_group))
end
it "should return proper in_category results" do
category = Factory(:question_category)
groups_in_cat = []
for n in 1..5
groups_in_cat.push Factory(:question_group)
for i in 1..n
Factory(:question, :question_category => category, :question_group => groups_in_cat.last)
end
end
for n in 1..5
Factory(:question, :question_group => Factory(:question_group))
end
groups = QuestionGroup.in_category(category.id).all
(groups - groups_in_cat).should be_empty
(groups_in_cat - groups).should be_empty
groups.count.should == groups.uniq.count
end
it "should return proper unassociated_in_category results" do
recruit = Factory(:recruit)
category = Factory(:question_category)
groups_in_cat = []
for n in 1..5
groups_in_cat.push Factory(:question_group)
for i in 1..n
Factory(:question, :question_category => category, :question_group => groups_in_cat.last)
end
end
for n in 1..5
Factory(:question, :question_group => Factory(:question_group))
end
Factory(:user_question_group, :user => recruit, :question => groups_in_cat.last.questions.first)
groups_in_cat -= [groups_in_cat.last]
groups = QuestionGroup.unassociated_in_category(recruit.id, category.id).all
(groups - groups_in_cat).should be_empty
(groups_in_cat - groups).should be_empty
groups.count.should == groups.uniq.count
end
end
|