Description:
added spec for user problem access control
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r283:105cc0f11b68 - - 1 file changed: 65 inserted, 0 deleted
@@ -102,3 +102,68 | |||
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | end |
|
105 | + | |
|
106 | + describe User, "when requesting problem description," do | |
|
107 | + | |
|
108 | + fixtures :users | |
|
109 | + fixtures :problems | |
|
110 | + | |
|
111 | + before(:each) do | |
|
112 | + @james = users(:james) | |
|
113 | + @john = users(:john) | |
|
114 | + @jack = users(:jack) | |
|
115 | + @add = problems(:one) | |
|
116 | + @easy = problems(:easy) | |
|
117 | + @hard = problems(:hard) | |
|
118 | + end | |
|
119 | + | |
|
120 | + it "should check if a problem is in user's contests" do | |
|
121 | + @james.problem_in_user_contests?(@easy).should be_true | |
|
122 | + @james.problem_in_user_contests?(@hard).should be_false | |
|
123 | + | |
|
124 | + @john.problem_in_user_contests?(@easy).should be_false | |
|
125 | + @john.problem_in_user_contests?(@hard).should be_false | |
|
126 | + end | |
|
127 | + | |
|
128 | + it "should be able to view problem in user's contests, when multicontests is on" do | |
|
129 | + enable_multicontest | |
|
130 | + @james.can_view_problem?(@easy).should be_true | |
|
131 | + @jack.can_view_problem?(@easy).should be_true | |
|
132 | + @jack.can_view_problem?(@hard).should be_true | |
|
133 | + end | |
|
134 | + | |
|
135 | + it "should not be able to view problem not in user's contests, when multicontests is on" do | |
|
136 | + enable_multicontest | |
|
137 | + @john.can_view_problem?(@easy).should be_false | |
|
138 | + @john.can_view_problem?(@hard).should be_false | |
|
139 | + @james.can_view_problem?(@hard).should be_false | |
|
140 | + end | |
|
141 | + | |
|
142 | + it "should be able to view all available problems, when multicontests is off" do | |
|
143 | + disable_multicontest | |
|
144 | + @john.can_view_problem?(@easy).should be_true | |
|
145 | + @john.can_view_problem?(@hard).should be_true | |
|
146 | + @james.can_view_problem?(@easy).should be_true | |
|
147 | + @james.can_view_problem?(@hard).should be_true | |
|
148 | + end | |
|
149 | + | |
|
150 | + it "should be able to view public problems, when multicontests is on" do | |
|
151 | + enable_multicontest | |
|
152 | + @john.can_view_problem?(@add).should be_true | |
|
153 | + @james.can_view_problem?(@add).should be_true | |
|
154 | + end | |
|
155 | + | |
|
156 | + def enable_multicontest | |
|
157 | + c = Configuration.new(:key => 'system.multicontests', | |
|
158 | + :value_type => 'boolean', | |
|
159 | + :value => 'true') | |
|
160 | + c.save | |
|
161 | + end | |
|
162 | + | |
|
163 | + def disable_multicontest | |
|
164 | + c = Configuration.new(:key => 'system.multicontests', | |
|
165 | + :value_type => 'boolean', | |
|
166 | + :value => 'false') | |
|
167 | + c.save | |
|
168 | + end | |
|
169 | + end |
You need to be logged in to leave comments.
Login now