Description:
started cleaning up tests, fixed fixtures loading error, removed error when contest time limit is uninitialized
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r275:3720a1af46c5 - - 19 files changed: 76 inserted, 211 deleted

@@ -138,203 +138,203
138 138 def load_output
139 139 if !Configuration.show_grading_result or params[:num]==nil
140 140 redirect_to :action => 'list' and return
141 141 end
142 142 @user = User.find(session[:user_id])
143 143 @submission = Submission.find(params[:id])
144 144 if @submission.user!=@user
145 145 flash[:notice] = 'You are not allowed to view result of other users.'
146 146 redirect_to :action => 'list' and return
147 147 end
148 148 case_num = params[:num].to_i
149 149 out_filename = output_filename(@user.login,
150 150 @submission.problem.name,
151 151 @submission.id,
152 152 case_num)
153 153 if !FileTest.exists?(out_filename)
154 154 flash[:notice] = 'Output not found.'
155 155 redirect_to :action => 'list' and return
156 156 end
157 157
158 158 response.headers['Content-Type'] = "application/force-download"
159 159 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
160 160 response.headers["X-Sendfile"] = out_filename
161 161 response.headers['Content-length'] = File.size(out_filename)
162 162 render :nothing => true
163 163 end
164 164
165 165 def error
166 166 @user = User.find(session[:user_id])
167 167 end
168 168
169 169 # announcement refreshing and hiding methods
170 170
171 171 def announcements
172 172 if params.has_key? 'recent'
173 173 prepare_announcements(params[:recent])
174 174 else
175 175 prepare_announcements
176 176 end
177 177 render(:partial => 'announcement',
178 178 :collection => @announcements,
179 179 :locals => {:announcement_effect => true})
180 180 end
181 181
182 182 protected
183 183
184 184 def prepare_announcements(recent=nil)
185 185 if Configuration.show_tasks_to?(@user)
186 186 @announcements = Announcement.find_published(true)
187 187 else
188 188 @announcements = Announcement.find_published
189 189 end
190 190 if recent!=nil
191 191 recent_id = recent.to_i
192 192 @announcements = @announcements.find_all { |a| a.id > recent_id }
193 193 end
194 194 end
195 195
196 196 def prepare_list_information
197 197 @problems = Problem.find_available_problems
198 198 @prob_submissions = Array.new
199 199 @user = User.find(session[:user_id])
200 200 @problems.each do |p|
201 201 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
202 202 if sub!=nil
203 203 @prob_submissions << { :count => sub.number, :submission => sub }
204 204 else
205 205 @prob_submissions << { :count => 0, :submission => nil }
206 206 end
207 207 end
208 208 prepare_announcements
209 209 end
210 210
211 211 def check_viewability
212 212 @user = User.find(session[:user_id])
213 213 if (!Configuration.show_tasks_to?(@user)) and
214 214 ((action_name=='submission') or (action_name=='submit'))
215 215 redirect_to :action => 'list' and return
216 216 end
217 217 end
218 218
219 219 def prepare_grading_result(submission)
220 220 if Configuration.task_grading_info.has_key? submission.problem.name
221 221 grading_info = Configuration.task_grading_info[submission.problem.name]
222 222 else
223 223 # guess task info from problem.full_score
224 224 cases = submission.problem.full_score / 10
225 225 grading_info = {
226 226 'testruns' => cases,
227 227 'testcases' => cases
228 228 }
229 229 end
230 230 @test_runs = []
231 231 if grading_info['testruns'].is_a? Integer
232 232 trun_count = grading_info['testruns']
233 233 trun_count.times do |i|
234 234 @test_runs << [ read_grading_result(@user.login,
235 235 submission.problem.name,
236 236 submission.id,
237 237 i+1) ]
238 238 end
239 239 else
240 240 grading_info['testruns'].keys.sort.each do |num|
241 241 run = []
242 242 testrun = grading_info['testruns'][num]
243 243 testrun.each do |c|
244 244 run << read_grading_result(@user.login,
245 245 submission.problem.name,
246 246 submission.id,
247 247 c)
248 248 end
249 249 @test_runs << run
250 250 end
251 251 end
252 252 end
253 253
254 254 def grading_result_dir(user_name, problem_name, submission_id, case_num)
255 255 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
256 256 end
257 257
258 258 def output_filename(user_name, problem_name, submission_id, case_num)
259 259 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
260 260 return "#{dir}/output.txt"
261 261 end
262 262
263 263 def read_grading_result(user_name, problem_name, submission_id, case_num)
264 264 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
265 265 result_file_name = "#{dir}/result"
266 266 if !FileTest.exists?(result_file_name)
267 267 return {:num => case_num, :msg => 'program did not run'}
268 268 else
269 269 results = File.open(result_file_name).readlines
270 270 run_stat = extract_running_stat(results)
271 271 output_filename = "#{dir}/output.txt"
272 272 if FileTest.exists?(output_filename)
273 273 output_file = true
274 274 output_size = File.size(output_filename)
275 275 else
276 276 output_file = false
277 277 output_size = 0
278 278 end
279 279
280 280 return {
281 281 :num => case_num,
282 282 :msg => results[0],
283 283 :run_stat => run_stat,
284 284 :output => output_file,
285 285 :output_size => output_size
286 286 }
287 287 end
288 288 end
289 289
290 290 # copied from grader/script/lib/test_request_helper.rb
291 291 def extract_running_stat(results)
292 292 running_stat_line = results[-1]
293 293
294 294 # extract exit status line
295 295 run_stat = ""
296 296 if !(/[Cc]orrect/.match(results[0]))
297 297 run_stat = results[0].chomp
298 298 else
299 299 run_stat = 'Program exited normally'
300 300 end
301 301
302 302 logger.info "Stat line: #{running_stat_line}"
303 303
304 304 # extract running time
305 305 if res = /r(.*)u(.*)s/.match(running_stat_line)
306 306 seconds = (res[1].to_f + res[2].to_f)
307 307 time_stat = "Time used: #{seconds} sec."
308 308 else
309 309 seconds = nil
310 310 time_stat = "Time used: n/a sec."
311 311 end
312 312
313 313 # extract memory usage
314 314 if res = /s(.*)m/.match(running_stat_line)
315 315 memory_used = res[1].to_i
316 316 else
317 317 memory_used = -1
318 318 end
319 319
320 320 return {
321 321 :msg => "#{run_stat}\n#{time_stat}",
322 322 :running_time => seconds,
323 323 :exit_status => run_stat,
324 324 :memory_usage => memory_used
325 325 }
326 326 end
327 327
328 328 def update_user_start_time
329 329 user = User.find(session[:user_id])
330 - UserContestStat.update_user_start_time(user)
330 + user.update_start_time
331 331 end
332 332
333 333 def reject_announcement_refresh_when_logged_out
334 334 if not session[:user_id]
335 335 render :text => 'Access forbidden', :status => 403
336 336 end
337 337 end
338 338
339 339 end
340 340
@@ -1,172 +1,178
1 1 require 'yaml'
2 2
3 3 #
4 4 # This class also contains various login of the system.
5 5 #
6 6 class Configuration < ActiveRecord::Base
7 7
8 8 SYSTEM_MODE_CONF_KEY = 'system.mode'
9 9 TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
10 10
11 - # set @@cache = true to only reload once.
12 - @@cache = false
11 + cattr_accessor :cache
12 + cattr_accessor :config_cache
13 + cattr_accessor :task_grading_info
14 + cattr_accessor :contest_time_str
15 + cattr_accessor :contest_time
13 16
14 - @@configurations = nil
15 - @@task_grading_info = nil
17 + # set @@cache = true to only reload once.
18 + Configuration.cache = false
19 +
20 + Configuration.config_cache = nil
21 + Configuration.task_grading_info = nil
16 22
17 23 def self.get(key)
18 - if @@cache
19 - if @@configurations == nil
24 + if Configuration.cache
25 + if Configuration.config_cache == nil
20 26 self.read_config
21 27 end
22 - return @@configurations[key]
28 + return Configuration.config_cache[key]
23 29 else
24 30 return Configuration.read_one_key(key)
25 31 end
26 32 end
27 33
28 34 def self.[](key)
29 35 self.get(key)
30 36 end
31 37
32 38 def self.reload
33 39 self.read_config
34 40 end
35 41
36 42 def self.clear
37 - @@configurations = nil
43 + Configuration.config_cache = nil
38 44 end
39 45
40 46 def self.cache?
41 - @@cache
47 + Configuration.cache
42 48 end
43 49
44 50 def self.enable_caching
45 - @@cache = true
51 + Configuration.cache = true
46 52 end
47 53
48 54 #
49 55 # View decision
50 56 #
51 57 def self.show_submitbox_to?(user)
52 58 mode = get(SYSTEM_MODE_CONF_KEY)
53 59 return false if mode=='analysis'
54 60 if (mode=='contest')
55 61 return false if (user.site!=nil) and
56 62 ((user.site.started!=true) or (user.site.finished?))
57 63 end
58 64 return true
59 65 end
60 66
61 67 def self.show_tasks_to?(user)
62 68 if time_limit_mode?
63 69 return false if not user.contest_started?
64 70 end
65 71 return true
66 72 end
67 73
68 74 def self.show_grading_result
69 75 return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
70 76 end
71 77
72 78 def self.allow_test_request(user)
73 79 mode = get(SYSTEM_MODE_CONF_KEY)
74 80 early_timeout = get(TEST_REQUEST_EARLY_TIMEOUT_KEY)
75 81 if (mode=='contest')
76 82 return false if ((user.site!=nil) and
77 83 ((user.site.started!=true) or
78 84 (early_timeout and (user.site.time_left < 30.minutes))))
79 85 end
80 86 return false if mode=='analysis'
81 87 return true
82 88 end
83 89
84 90 def self.task_grading_info
85 - if @@task_grading_info==nil
91 + if Configuration.task_grading_info==nil
86 92 read_grading_info
87 93 end
88 - return @@task_grading_info
94 + return Configuration.task_grading_info
89 95 end
90 96
91 97 def self.standard_mode?
92 98 return get(SYSTEM_MODE_CONF_KEY) == 'standard'
93 99 end
94 100
95 101 def self.contest_mode?
96 102 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
97 103 end
98 104
99 105 def self.indv_contest_mode?
100 106 return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
101 107 end
102 108
103 109 def self.time_limit_mode?
104 110 mode = get(SYSTEM_MODE_CONF_KEY)
105 111 return ((mode == 'contest') or (mode == 'indv-contest'))
106 112 end
107 113
108 114 def self.analysis_mode?
109 115 return get(SYSTEM_MODE_CONF_KEY) == 'analysis'
110 116 end
111 117
112 118 def self.contest_time_limit
113 119 contest_time_str = Configuration['contest.time_limit']
114 120
115 - if not defined? @@contest_time_str
116 - @@contest_time_str = nil
121 + if not defined? Configuration.contest_time_str
122 + Configuration.contest_time_str = nil
117 123 end
118 124
119 - if @@contest_time_str != contest_time_str
120 - @@contest_time_str = contest_time_str
125 + if Configuration.contest_time_str != contest_time_str
126 + Configuration.contest_time_str = contest_time_str
121 127 if tmatch = /(\d+):(\d+)/.match(contest_time_str)
122 128 h = tmatch[1].to_i
123 129 m = tmatch[2].to_i
124 130
125 - @@contest_time = h.hour + m.minute
131 + Configuration.contest_time = h.hour + m.minute
126 132 else
127 - @@contest_time = nil
133 + Configuration.contest_time = nil
128 134 end
129 135 end
130 - return @@contest_time
136 + return Configuration.contest_time
131 137 end
132 138
133 139 protected
134 140
135 141 def self.convert_type(val,type)
136 142 case type
137 143 when 'string'
138 144 return val
139 145
140 146 when 'integer'
141 147 return val.to_i
142 148
143 149 when 'boolean'
144 150 return (val=='true')
145 151 end
146 152 end
147 153
148 154 def self.read_config
149 - @@configurations = {}
155 + Configuration.config_cache = {}
150 156 Configuration.find(:all).each do |conf|
151 157 key = conf.key
152 158 val = conf.value
153 - @@configurations[key] = Configuration.convert_type(val,conf.value_type)
159 + Configuration.config_cache[key] = Configuration.convert_type(val,conf.value_type)
154 160 end
155 161 end
156 162
157 163 def self.read_one_key(key)
158 164 conf = Configuration.find_by_key(key)
159 165 if conf
160 166 return Configuration.convert_type(conf.value,conf.value_type)
161 167 else
162 168 return nil
163 169 end
164 170 end
165 171
166 172 def self.read_grading_info
167 173 f = File.open(TASK_GRADING_INFO_FILENAME)
168 - @@task_grading_info = YAML.load(f)
174 + Configuration.task_grading_info = YAML.load(f)
169 175 f.close
170 176 end
171 177
172 178 end
@@ -1,226 +1,238
1 1 require 'digest/sha1'
2 2
3 3 class User < ActiveRecord::Base
4 4
5 5 has_and_belongs_to_many :roles
6 6
7 7 has_many :test_requests, :order => "submitted_at DESC"
8 8
9 9 has_many :messages,
10 10 :class_name => "Message",
11 11 :foreign_key => "sender_id",
12 12 :order => 'created_at DESC'
13 13
14 14 has_many :replied_messages,
15 15 :class_name => "Message",
16 16 :foreign_key => "receiver_id",
17 17 :order => 'created_at DESC'
18 18
19 19 has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy
20 20
21 21 belongs_to :site
22 22 belongs_to :country
23 23
24 24 has_and_belongs_to_many :contests
25 25
26 26 named_scope :activated_users, :conditions => {:activated => true}
27 27
28 28 validates_presence_of :login
29 29 validates_uniqueness_of :login
30 30 validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/
31 31 validates_length_of :login, :within => 3..30
32 32
33 33 validates_presence_of :full_name
34 34 validates_length_of :full_name, :minimum => 1
35 35
36 36 validates_presence_of :password, :if => :password_required?
37 37 validates_length_of :password, :within => 4..20, :if => :password_required?
38 38 validates_confirmation_of :password, :if => :password_required?
39 39
40 40 validates_format_of :email,
41 41 :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
42 42 :if => :email_validation?
43 43 validate :uniqueness_of_email_from_activated_users,
44 44 :if => :email_validation?
45 45 validate :enough_time_interval_between_same_email_registrations,
46 46 :if => :email_validation?
47 47
48 48 # these are for ytopc
49 49 # disable for now
50 50 #validates_presence_of :province
51 51
52 52 attr_accessor :password
53 53
54 54 before_save :encrypt_new_password
55 55 before_save :assign_default_site
56 56
57 57 def self.authenticate(login, password)
58 58 user = find_by_login(login)
59 59 return user if user && user.authenticated?(password)
60 60 end
61 61
62 62 def authenticated?(password)
63 63 if self.activated
64 64 hashed_password == User.encrypt(password,self.salt)
65 65 else
66 66 false
67 67 end
68 68 end
69 69
70 70 def admin?
71 71 self.roles.detect {|r| r.name == 'admin' }
72 72 end
73 73
74 74 def email_for_editing
75 75 if self.email==nil
76 76 "(unknown)"
77 77 elsif self.email==''
78 78 "(blank)"
79 79 else
80 80 self.email
81 81 end
82 82 end
83 83
84 84 def email_for_editing=(e)
85 85 self.email=e
86 86 end
87 87
88 88 def alias_for_editing
89 89 if self.alias==nil
90 90 "(unknown)"
91 91 elsif self.alias==''
92 92 "(blank)"
93 93 else
94 94 self.alias
95 95 end
96 96 end
97 97
98 98 def alias_for_editing=(e)
99 99 self.alias=e
100 100 end
101 101
102 102 def activation_key
103 103 if self.hashed_password==nil
104 104 encrypt_new_password
105 105 end
106 106 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
107 107 end
108 108
109 109 def verify_activation_key(key)
110 110 key == activation_key
111 111 end
112 112
113 113 def self.random_password(length=5)
114 114 chars = 'abcdefghjkmnopqrstuvwxyz'
115 115 password = ''
116 116 length.times { password << chars[rand(chars.length - 1)] }
117 117 password
118 118 end
119 119
120 120 def self.find_non_admin_with_prefix(prefix='')
121 121 users = User.find(:all)
122 122 return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
123 123 end
124 124
125 125 # Contest information
126 126
127 127 def contest_time_left
128 128 if Configuration.contest_mode?
129 129 return nil if site==nil
130 130 return site.time_left
131 131 elsif Configuration.indv_contest_mode?
132 132 time_limit = Configuration.contest_time_limit
133 + if time_limit == nil
134 + return nil
135 + end
133 136 if contest_stat==nil
134 137 return (Time.now.gmtime + time_limit) - Time.now.gmtime
135 138 else
136 139 finish_time = contest_stat.started_at + time_limit
137 140 current_time = Time.now.gmtime
138 141 if current_time > finish_time
139 142 return 0
140 143 else
141 144 return finish_time - current_time
142 145 end
143 146 end
144 147 else
145 148 return nil
146 149 end
147 150 end
148 151
149 152 def contest_finished?
150 153 if Configuration.contest_mode?
151 154 return false if site==nil
152 155 return site.finished?
153 156 elsif Configuration.indv_contest_mode?
154 157 time_limit = Configuration.contest_time_limit
155 158
156 159 return false if contest_stat==nil
157 160
158 161 return contest_time_left == 0
159 162 else
160 163 return false
161 164 end
162 165 end
163 166
164 167 def contest_started?
165 168 if Configuration.contest_mode?
166 169 return true if site==nil
167 170 return site.started
168 171 else
169 172 return true
170 173 end
171 174 end
172 175
176 + def update_start_time
177 + stat = self.contest_stat
178 + if stat == nil
179 + stat = UserContestStat.new(:user => self,
180 + :started_at => Time.now.gmtime)
181 + stat.save
182 + end
183 + end
184 +
173 185 protected
174 186 def encrypt_new_password
175 187 return if password.blank?
176 188 self.salt = (10+rand(90)).to_s
177 189 self.hashed_password = User.encrypt(self.password,self.salt)
178 190 end
179 191
180 192 def assign_default_site
181 193 # have to catch error when migrating (because self.site is not available).
182 194 begin
183 195 if self.site==nil
184 196 self.site = Site.find_by_name('default')
185 197 if self.site==nil
186 198 self.site = Site.find(1) # when 'default has be renamed'
187 199 end
188 200 end
189 201 rescue
190 202 end
191 203 end
192 204
193 205 def password_required?
194 206 self.hashed_password.blank? || !self.password.blank?
195 207 end
196 208
197 209 def self.encrypt(string,salt)
198 210 Digest::SHA1.hexdigest(salt + string)
199 211 end
200 212
201 213 def uniqueness_of_email_from_activated_users
202 214 user = User.activated_users.find_by_email(self.email)
203 215 if user and (user.login != self.login)
204 216 self.errors.add_to_base("Email has already been taken")
205 217 end
206 218 end
207 219
208 220 def enough_time_interval_between_same_email_registrations
209 221 return if !self.new_record?
210 222 return if self.activated
211 223 open_user = User.find_by_email(self.email,
212 224 :order => 'created_at DESC')
213 225 if open_user and open_user.created_at and
214 226 (open_user.created_at > Time.now.gmtime - 5.minutes)
215 227 self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
216 228 end
217 229 end
218 230
219 231 def email_validation?
220 232 begin
221 233 return VALIDATE_USER_EMAILS
222 234 rescue
223 235 return false
224 236 end
225 237 end
226 238 end
@@ -1,14 +1,5
1 1 class UserContestStat < ActiveRecord::Base
2 2
3 3 belongs_to :user
4 4
5 - def self.update_user_start_time(user)
6 - stat = user.contest_stat
7 - if stat == nil
8 - stat = UserContestStat.new(:user => user,
9 - :started_at => Time.now.gmtime)
10 - stat.save
11 - end
12 - end
13 -
14 5 end
@@ -1,17 +1,17
1 1 class AddGradersRightToAdminRole < ActiveRecord::Migration
2 2 def self.up
3 3 admin_role = Role.find_by_name('admin')
4 4
5 5 graders_right = Right.create(:name => 'graders_admin',
6 6 :controller => 'graders',
7 7 :action => 'all')
8 8
9 9 admin_role.rights << graders_right;
10 10 admin_role.save
11 11 end
12 12
13 13 def self.down
14 14 graders_right = Right.find_by_name('graders_admin')
15 - graders_right.destroy
15 + graders_right.destroy if graders_right
16 16 end
17 17 end
@@ -1,29 +1,29
1 1 class AddSiteToUserAndAddDefaultSite < ActiveRecord::Migration
2 2 def self.up
3 3 default_site = Site.new({:name => 'default',
4 4 :started => false})
5 5 default_site.save!
6 6
7 7 add_column :users, :site_id, :integer
8 8 User.reset_column_information
9 9
10 10 User.find(:all).each do |user|
11 11
12 12 class << user
13 13 def valid?
14 14 true
15 15 end
16 16 end
17 17
18 18 user.site_id = default_site.id
19 19 user.save
20 20 end
21 21 end
22 22
23 23 def self.down
24 24 remove_column :users, :site_id
25 25
26 26 default_site = Site.find_by_name('default')
27 - default_site.destroy
27 + default_site.destroy if default_site
28 28 end
29 29 end
@@ -1,271 +1,258
1 1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 2 # please use the migrations feature of Active Record to incrementally modify your database, and
3 3 # then regenerate this schema definition.
4 4 #
5 5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 6 # to create the application database on another system, you should be using db:schema:load, not running
7 7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12 12 ActiveRecord::Schema.define(:version => 20100219014840) do
13 13
14 14 create_table "announcements", :force => true do |t|
15 15 t.string "author"
16 16 t.text "body"
17 17 t.boolean "published"
18 18 t.datetime "created_at"
19 19 t.datetime "updated_at"
20 20 t.boolean "frontpage", :default => false
21 21 t.boolean "contest_only", :default => false
22 22 t.string "title"
23 23 end
24 24
25 25 create_table "codejom_statuses", :force => true do |t|
26 26 t.integer "user_id"
27 27 t.boolean "alive"
28 28 t.integer "num_problems_passed"
29 29 t.datetime "created_at"
30 30 t.datetime "updated_at"
31 31 end
32 32
33 33 create_table "configurations", :force => true do |t|
34 34 t.string "key"
35 35 t.string "value_type"
36 36 t.string "value"
37 37 t.datetime "created_at"
38 38 t.datetime "updated_at"
39 39 t.text "description"
40 40 end
41 41
42 42 create_table "contests", :force => true do |t|
43 43 t.string "title"
44 44 t.boolean "enabled"
45 45 t.datetime "created_at"
46 46 t.datetime "updated_at"
47 47 end
48 48
49 49 create_table "contests_problems", :id => false, :force => true do |t|
50 50 t.integer "contest_id"
51 51 t.integer "problem_id"
52 52 end
53 53
54 54 create_table "contests_users", :id => false, :force => true do |t|
55 55 t.integer "contest_id"
56 56 t.integer "user_id"
57 57 end
58 58
59 59 create_table "countries", :force => true do |t|
60 60 t.string "name"
61 61 t.datetime "created_at"
62 62 t.datetime "updated_at"
63 63 end
64 64
65 65 create_table "descriptions", :force => true do |t|
66 66 t.text "body"
67 67 t.boolean "markdowned"
68 68 t.datetime "created_at"
69 69 t.datetime "updated_at"
70 70 end
71 71
72 72 create_table "grader_processes", :force => true do |t|
73 73 t.string "host", :limit => 20
74 74 t.integer "pid"
75 75 t.string "mode"
76 76 t.boolean "active"
77 77 t.datetime "created_at"
78 78 t.datetime "updated_at"
79 79 t.integer "task_id"
80 80 t.string "task_type"
81 81 t.boolean "terminated"
82 82 end
83 83
84 84 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
85 85
86 86 create_table "languages", :force => true do |t|
87 87 t.string "name", :limit => 10
88 88 t.string "pretty_name"
89 89 t.string "ext", :limit => 10
90 90 t.string "common_ext"
91 91 end
92 92
93 93 create_table "messages", :force => true do |t|
94 94 t.integer "sender_id"
95 95 t.integer "receiver_id"
96 96 t.integer "replying_message_id"
97 97 t.text "body"
98 98 t.boolean "replied"
99 99 t.datetime "created_at"
100 100 t.datetime "updated_at"
101 101 end
102 102
103 103 create_table "problems", :force => true do |t|
104 - t.string "name", :limit => 30
105 - t.string "full_name"
106 - t.integer "full_score"
107 - t.date "date_added"
108 - t.boolean "available"
109 - t.string "url"
110 - t.integer "description_id"
111 - t.boolean "test_allowed"
112 - t.boolean "output_only"
113 - t.integer "level", :default => 0
114 - t.datetime "updated_at"
115 - t.string "description_filename"
104 + t.string "name", :limit => 30
105 + t.string "full_name"
106 + t.integer "full_score"
107 + t.date "date_added"
108 + t.boolean "available"
109 + t.string "url"
110 + t.integer "description_id"
111 + t.boolean "test_allowed"
112 + t.boolean "output_only"
113 + t.string "description_filename"
116 114 end
117 115
118 116 create_table "rights", :force => true do |t|
119 117 t.string "name"
120 118 t.string "controller"
121 119 t.string "action"
122 120 end
123 121
124 122 create_table "rights_roles", :id => false, :force => true do |t|
125 123 t.integer "right_id"
126 124 t.integer "role_id"
127 125 end
128 126
129 127 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
130 128
131 129 create_table "roles", :force => true do |t|
132 130 t.string "name"
133 131 end
134 132
135 133 create_table "roles_users", :id => false, :force => true do |t|
136 134 t.integer "role_id"
137 135 t.integer "user_id"
138 136 end
139 137
140 138 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
141 139
142 140 create_table "sessions", :force => true do |t|
143 141 t.string "session_id"
144 142 t.text "data"
145 143 t.datetime "updated_at"
146 144 end
147 145
148 146 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
149 147 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
150 148
151 149 create_table "sites", :force => true do |t|
152 150 t.string "name"
153 151 t.boolean "started"
154 152 t.datetime "start_time"
155 153 t.datetime "created_at"
156 154 t.datetime "updated_at"
157 155 t.integer "country_id"
158 156 t.string "password"
159 157 end
160 158
161 159 create_table "submission_statuses", :force => true do |t|
162 160 t.integer "user_id"
163 161 t.integer "problem_id"
164 162 t.boolean "passed"
165 163 t.integer "submission_count"
166 164 t.datetime "created_at"
167 165 t.datetime "updated_at"
168 166 end
169 167
170 168 create_table "submissions", :force => true do |t|
171 169 t.integer "user_id"
172 170 t.integer "problem_id"
173 171 t.integer "language_id"
174 172 t.text "source"
175 173 t.binary "binary"
176 174 t.datetime "submitted_at"
177 175 t.datetime "compiled_at"
178 176 t.text "compiler_message"
179 177 t.datetime "graded_at"
180 178 t.integer "points"
181 179 t.text "grader_comment"
182 180 t.integer "number"
183 181 t.string "source_filename"
184 182 end
185 183
186 184 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
187 185 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
188 186
189 187 create_table "tasks", :force => true do |t|
190 188 t.integer "submission_id"
191 189 t.datetime "created_at"
192 190 t.integer "status"
193 191 t.datetime "updated_at"
194 192 end
195 193
196 194 create_table "test_pair_assignments", :force => true do |t|
197 195 t.integer "user_id"
198 196 t.integer "problem_id"
199 197 t.integer "test_pair_id"
200 198 t.integer "test_pair_number"
201 199 t.integer "request_number"
202 200 t.datetime "created_at"
203 201 t.datetime "updated_at"
204 202 t.boolean "submitted"
205 203 end
206 204
207 205 create_table "test_pairs", :force => true do |t|
208 206 t.integer "problem_id"
209 207 t.text "input", :limit => 16777215
210 208 t.text "solution", :limit => 16777215
211 209 t.datetime "created_at"
212 210 t.datetime "updated_at"
213 - t.integer "number"
214 211 end
215 212
216 213 create_table "test_requests", :force => true do |t|
217 214 t.integer "user_id"
218 215 t.integer "problem_id"
219 216 t.integer "submission_id"
220 217 t.string "input_file_name"
221 218 t.string "output_file_name"
222 219 t.string "running_stat"
223 220 t.integer "status"
224 221 t.datetime "updated_at"
225 222 t.datetime "submitted_at"
226 223 t.datetime "compiled_at"
227 224 t.text "compiler_message"
228 225 t.datetime "graded_at"
229 226 t.string "grader_comment"
230 227 t.datetime "created_at"
231 228 t.float "running_time"
232 229 t.string "exit_status"
233 230 t.integer "memory_usage"
234 231 end
235 232
236 233 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
237 234
238 235 create_table "user_contest_stats", :force => true do |t|
239 236 t.integer "user_id"
240 237 t.datetime "started_at"
241 238 t.datetime "created_at"
242 239 t.datetime "updated_at"
243 240 end
244 241
245 242 create_table "users", :force => true do |t|
246 - t.string "login", :limit => 50
243 + t.string "login", :limit => 50
247 244 t.string "full_name"
248 245 t.string "hashed_password"
249 - t.string "salt", :limit => 5
246 + t.string "salt", :limit => 5
250 247 t.string "alias"
251 248 t.string "email"
252 249 t.integer "site_id"
253 250 t.integer "country_id"
254 - t.boolean "activated", :default => false
251 + t.boolean "activated", :default => false
255 252 t.datetime "created_at"
256 253 t.datetime "updated_at"
257 - t.string "member1_full_name"
258 - t.string "member2_full_name"
259 - t.string "member3_full_name"
260 - t.boolean "high_school"
261 - t.string "member1_school_name"
262 - t.string "member2_school_name"
263 - t.string "member3_school_name"
264 - t.string "school_name"
265 - t.string "province"
266 - t.integer "year"
267 254 end
268 255
269 256 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
270 257
271 258 end
@@ -1,55 +1,56
1 1
2 2 require File.dirname(__FILE__) + '/../spec_helper'
3 3
4 4 describe MainController do
5 5
6 6 before(:each) do
7 7 @problem = mock(Problem, :name => 'test', :output_only => false)
8 8 @language = mock(Language, :name => 'cpp', :ext => 'cpp')
9 9 @submission = mock(Submission,
10 10 :id => 1,
11 11 :user_id => 1,
12 12 :problem => @problem,
13 13 :language => @language,
14 14 :source => 'sample source',
15 15 :compiler_message => 'none')
16 16 @user = mock(User, :id => 1, :login => 'john')
17 17 @another_user = mock(User, :id => 2, :login => 'mary')
18 18 end
19 19
20 20 it "should redirect user to login page when unlogged-in user try to access main/list" do
21 21 get 'list'
22 22 response.should redirect_to(:action => 'login')
23 23 end
24 24
25 25 it "should let user sees her own source" do
26 26 Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission)
27 27 User.should_receive(:find).with(1).and_return(@user)
28 + @user.should_receive(:update_start_time)
28 29 get 'source', {:id => @submission.id}, {:user_id => 1}
29 30 response.should be_success
30 31 end
31 32
32 33 it "should let user sees her own compiler message" do
33 34 Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission)
34 35 User.should_receive(:find).with(1).and_return(@user)
35 36 get 'compiler_msg', {:id => @submission.id}, {:user_id => 1}
36 37 response.should be_success
37 38 end
38 39
39 40 it "should not let user sees other user's source" do
40 41 Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission)
41 42 User.should_receive(:find).with(2).and_return(@another_user)
42 43 get 'source', {:id => @submission.id}, {:user_id => 2}
43 44 flash[:notice].should =~ /[Ee]rror/
44 45 response.should redirect_to(:action => 'list')
45 46 end
46 47
47 48 it "should not let user sees other user's compiler message" do
48 49 Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission)
49 50 User.should_receive(:find).with(2).and_return(@another_user)
50 51 get 'compiler_msg', {:id => @submission.id}, {:user_id => 2}
51 52 flash[:notice].should =~ /[Ee]rror/
52 53 response.should redirect_to(:action => 'list')
53 54 end
54 55
55 56 end
@@ -1,54 +1,54
1 1 # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2 2 # from the project root directory.
3 3 ENV["RAILS_ENV"] ||= 'test'
4 4 require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
5 5 require 'spec/autorun'
6 6 require 'spec/rails'
7 7
8 8 # Uncomment the next line to use webrat's matchers
9 9 #require 'webrat/integrations/rspec-rails'
10 10
11 11 # Requires supporting files with custom matchers and macros, etc,
12 12 # in ./support/ and its subdirectories.
13 13 Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
14 14
15 15 Spec::Runner.configure do |config|
16 16 # If you're not using ActiveRecord you should remove these
17 17 # lines, delete config/database.yml and disable :active_record
18 18 # in your config/boot.rb
19 19 config.use_transactional_fixtures = true
20 20 config.use_instantiated_fixtures = false
21 - config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
21 + config.fixture_path = RAILS_ROOT + '/test/fixtures/'
22 22
23 23 # == Fixtures
24 24 #
25 25 # You can declare fixtures for each example_group like this:
26 26 # describe "...." do
27 27 # fixtures :table_a, :table_b
28 28 #
29 29 # Alternatively, if you prefer to declare them only once, you can
30 30 # do so right here. Just uncomment the next line and replace the fixture
31 31 # names with your fixtures.
32 32 #
33 33 # config.global_fixtures = :table_a, :table_b
34 34 #
35 35 # If you declare global fixtures, be aware that they will be declared
36 36 # for all of your examples, even those that don't use them.
37 37 #
38 38 # You can also declare which fixtures to use (for example fixtures for test/fixtures):
39 39 #
40 40 # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
41 41 #
42 42 # == Mock Framework
43 43 #
44 44 # RSpec uses it's own mocking framework by default. If you prefer to
45 45 # use mocha, flexmock or RR, uncomment the appropriate line:
46 46 #
47 47 # config.mock_with :mocha
48 48 # config.mock_with :flexmock
49 49 # config.mock_with :rr
50 50 #
51 51 # == Notes
52 52 #
53 53 # For more information take a look at Spec::Runner::Configuration and Spec::Runner
54 54 end
@@ -1,18 +1,20
1 1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 2
3 3 <%
4 4 User.public_class_method :encrypt
5 5
6 - SALT = "abc"
6 + salt = "abc"
7 7 %>
8 8
9 9 john:
10 10 login: john
11 - hashed_password: <%= User.encrypt("hello",SALT) %>
12 - salt: <%= SALT %>
11 + full_name: john
12 + hashed_password: <%= User.encrypt("hello",salt) %>
13 + salt: <%= salt %>
13 14 mary:
14 15 login: mary
15 - hashed_password: <%= User.encrypt("goodbye",SALT) %>
16 - salt: <%= SALT %>
16 + full_name: mary
17 + hashed_password: <%= User.encrypt("goodbye",salt) %>
18 + salt: <%= salt %>
17 19 roles: admin
18 20
@@ -1,45 +1,4
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 3 class AnnouncementsControllerTest < ActionController::TestCase
4 - def test_should_get_index
5 - get :index
6 - assert_response :success
7 - assert_not_nil assigns(:announcements)
8 - end
9 -
10 - def test_should_get_new
11 - get :new
12 - assert_response :success
13 - end
14 -
15 - def test_should_create_announcement
16 - assert_difference('Announcement.count') do
17 - post :create, :announcement => { }
18 - end
19 -
20 - assert_redirected_to announcement_path(assigns(:announcement))
21 - end
22 -
23 - def test_should_show_announcement
24 - get :show, :id => announcements(:one).id
25 - assert_response :success
26 - end
27 -
28 - def test_should_get_edit
29 - get :edit, :id => announcements(:one).id
30 - assert_response :success
31 - end
32 -
33 - def test_should_update_announcement
34 - put :update, :id => announcements(:one).id, :announcement => { }
35 - assert_redirected_to announcement_path(assigns(:announcement))
36 - end
37 -
38 - def test_should_destroy_announcement
39 - assert_difference('Announcement.count', -1) do
40 - delete :destroy, :id => announcements(:one).id
41 - end
42 -
43 - assert_redirected_to announcements_path
44 - end
45 4 end
@@ -1,45 +1,4
1 1 require 'test_helper'
2 2
3 3 class ContestsControllerTest < ActionController::TestCase
4 - test "should get index" do
5 - get :index
6 - assert_response :success
7 - assert_not_nil assigns(:contests)
8 - end
9 -
10 - test "should get new" do
11 - get :new
12 - assert_response :success
13 - end
14 -
15 - test "should create contest" do
16 - assert_difference('Contest.count') do
17 - post :create, :contest => { }
18 - end
19 -
20 - assert_redirected_to contest_path(assigns(:contest))
21 - end
22 -
23 - test "should show contest" do
24 - get :show, :id => contests(:one).to_param
25 - assert_response :success
26 - end
27 -
28 - test "should get edit" do
29 - get :edit, :id => contests(:one).to_param
30 - assert_response :success
31 - end
32 -
33 - test "should update contest" do
34 - put :update, :id => contests(:one).to_param, :contest => { }
35 - assert_redirected_to contest_path(assigns(:contest))
36 - end
37 -
38 - test "should destroy contest" do
39 - assert_difference('Contest.count', -1) do
40 - delete :destroy, :id => contests(:one).to_param
41 - end
42 -
43 - assert_redirected_to contests_path
44 - end
45 4 end
@@ -1,37 +1,37
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2 require 'login_controller'
3 3
4 4 # Re-raise errors caught by the controller.
5 5 class LoginController; def rescue_action(e) raise e end; end
6 6
7 - class LoginControllerTest < Test::Unit::TestCase
7 + class LoginControllerTest < ActionController::TestCase
8 8
9 9 fixtures :users
10 10
11 11 def setup
12 12 @controller = LoginController.new
13 13 @request = ActionController::TestRequest.new
14 14 @response = ActionController::TestResponse.new
15 15 end
16 16
17 17 # Replace this with your real tests.
18 18 def test_should_hide_index
19 19 get :index
20 20 assert_redirected_to :controller => 'main', :action => 'login'
21 21 end
22 22
23 23 def test_should_login_user_and_set_session
24 24 john = users(:john)
25 25
26 26 post :login, :login => 'john', :password => "hello"
27 27 assert_redirected_to :controller => 'main', :action => 'list'
28 28 assert_equal john.id, session[:user_id]
29 29 end
30 30
31 31 def test_should_reject_user_with_wrong_password
32 32 john = users(:john)
33 33
34 34 post :login, :login => 'john', :password => "wrong"
35 35 assert_redirected_to :controller => 'main', :action => 'login'
36 36 end
37 37 end
@@ -1,32 +1,20
1 - require File.dirname(__FILE__) + '/../test_helper'
2 - require 'main_controller'
1 + require File.dirname(__FILE__) + '/../test_helper'
3 2
4 - # Re-raise errors caught by the controller.
5 - class MainController; def rescue_action(e) raise e end; end
6 -
7 - class MainControllerTest < Test::Unit::TestCase
8 -
3 + class MainControllerTest < ActionController::TestCase
4 + fixtures :users
9 5 fixtures :problems
10 - fixtures :users
11 6
12 - def setup
13 - @controller = MainController.new
14 - @request = ActionController::TestRequest.new
15 - @response = ActionController::TestResponse.new
16 - end
17 -
18 - # Replace this with your real tests.
19 7 def test_should_redirect_new_user_to_login
20 8 get :list
21 - assert_redirected_to :action => 'login'
9 + assert_redirected_to :controller => 'main', :action => 'login'
22 10 end
23 11
24 12 def test_should_list_available_problems_if_logged_in
25 13 john = users(:john)
26 14 get :list, {}, {:user_id => john.id}
27 15
28 16 assert_template 'main/list'
29 17 assert_select "table tr:nth-child(2)", :text => /\(add\)/
30 18 end
31 19
32 20 end
@@ -1,92 +1,92
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2 require 'problems_controller'
3 3
4 4 # Re-raise errors caught by the controller.
5 5 class ProblemsController; def rescue_action(e) raise e end; end
6 6
7 - class ProblemsControllerTest < Test::Unit::TestCase
7 + class ProblemsControllerTest < ActionController::TestCase
8 8 fixtures :problems
9 9
10 10 def setup
11 11 @controller = ProblemsController.new
12 12 @request = ActionController::TestRequest.new
13 13 @response = ActionController::TestResponse.new
14 14
15 15 @first_id = problems(:first).id
16 16 end
17 17
18 18 def test_index
19 19 get :index
20 20 assert_response :success
21 21 assert_template 'list'
22 22 end
23 23
24 24 def test_list
25 25 get :list
26 26
27 27 assert_response :success
28 28 assert_template 'list'
29 29
30 30 assert_not_nil assigns(:problems)
31 31 end
32 32
33 33 def test_show
34 34 get :show, :id => @first_id
35 35
36 36 assert_response :success
37 37 assert_template 'show'
38 38
39 39 assert_not_nil assigns(:problem)
40 40 assert assigns(:problem).valid?
41 41 end
42 42
43 43 def test_new
44 44 get :new
45 45
46 46 assert_response :success
47 47 assert_template 'new'
48 48
49 49 assert_not_nil assigns(:problem)
50 50 end
51 51
52 52 def test_create
53 53 num_problems = Problem.count
54 54
55 55 post :create, :problem => {}
56 56
57 57 assert_response :redirect
58 58 assert_redirected_to :action => 'list'
59 59
60 60 assert_equal num_problems + 1, Problem.count
61 61 end
62 62
63 63 def test_edit
64 64 get :edit, :id => @first_id
65 65
66 66 assert_response :success
67 67 assert_template 'edit'
68 68
69 69 assert_not_nil assigns(:problem)
70 70 assert assigns(:problem).valid?
71 71 end
72 72
73 73 def test_update
74 74 post :update, :id => @first_id
75 75 assert_response :redirect
76 76 assert_redirected_to :action => 'show', :id => @first_id
77 77 end
78 78
79 79 def test_destroy
80 80 assert_nothing_raised {
81 81 Problem.find(@first_id)
82 82 }
83 83
84 84 post :destroy, :id => @first_id
85 85 assert_response :redirect
86 86 assert_redirected_to :action => 'list'
87 87
88 88 assert_raise(ActiveRecord::RecordNotFound) {
89 89 Problem.find(@first_id)
90 90 }
91 91 end
92 92 end
@@ -1,45 +1,4
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 3 class SitesControllerTest < ActionController::TestCase
4 - def test_should_get_index
5 - get :index
6 - assert_response :success
7 - assert_not_nil assigns(:sites)
8 - end
9 -
10 - def test_should_get_new
11 - get :new
12 - assert_response :success
13 - end
14 -
15 - def test_should_create_site
16 - assert_difference('Site.count') do
17 - post :create, :site => { }
18 - end
19 -
20 - assert_redirected_to site_path(assigns(:site))
21 - end
22 -
23 - def test_should_show_site
24 - get :show, :id => sites(:one).id
25 - assert_response :success
26 - end
27 -
28 - def test_should_get_edit
29 - get :edit, :id => sites(:one).id
30 - assert_response :success
31 - end
32 -
33 - def test_should_update_site
34 - put :update, :id => sites(:one).id, :site => { }
35 - assert_redirected_to site_path(assigns(:site))
36 - end
37 -
38 - def test_should_destroy_site
39 - assert_difference('Site.count', -1) do
40 - delete :destroy, :id => sites(:one).id
41 - end
42 -
43 - assert_redirected_to sites_path
44 - end
45 4 end
@@ -1,142 +1,142
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2 require 'user_admin_controller'
3 3
4 4 # Re-raise errors caught by the controller.
5 5 class UserAdminController; def rescue_action(e) raise e end; end
6 6
7 - class UserAdminControllerTest < Test::Unit::TestCase
7 + class UserAdminControllerTest < ActionController::TestCase
8 8 fixtures :users
9 9 fixtures :roles
10 10 fixtures :rights
11 11
12 12 def setup
13 13 @controller = UserAdminController.new
14 14 @request = ActionController::TestRequest.new
15 15 @response = ActionController::TestResponse.new
16 16
17 17 @first_id = users(:john).id
18 18 @admin_id = users(:mary).id
19 19 end
20 20
21 21 def test_should_not_allow_new_user_to_see
22 22 get :list
23 23 assert_redirected_to :controller => 'main', :action => 'login'
24 24 end
25 25
26 26 def test_should_not_allow_normal_user_to_see
27 27 john = users(:john)
28 28
29 29 get :list, {}, {:user_id => john.id}
30 30 assert_redirected_to :controller => 'main', :action => 'login'
31 31 end
32 32
33 33 def test_should_allow_admin_to_see
34 34 mary = users(:mary)
35 35
36 36 get :list, {}, {:user_id => mary.id}
37 37 assert_template 'user_admin/list'
38 38 end
39 39
40 40
41 41 def test_index
42 42 get :index, {}, {:user_id => @admin_id}
43 43 assert_response :success
44 44 assert_template 'list'
45 45 end
46 46
47 47 def test_list
48 48 get :list, {}, {:user_id => @admin_id}
49 49
50 50 assert_response :success
51 51 assert_template 'list'
52 52
53 53 assert_not_nil assigns(:users)
54 54 end
55 55
56 56 def test_show
57 57 get :show, {:id => @first_id}, {:user_id => @admin_id}
58 58
59 59 assert_response :success
60 60 assert_template 'show'
61 61
62 62 assert_not_nil assigns(:user)
63 63 end
64 64
65 65 def test_new
66 66 get :new, {}, {:user_id => @admin_id}
67 67
68 68 assert_response :success
69 69 assert_template 'new'
70 70
71 71 assert_not_nil assigns(:user)
72 72 end
73 73
74 74 def test_create_with_correct_confirmation_password
75 75 num_users = User.count
76 76
77 77 post :create, {:user => {
78 78 :login => 'test',
79 79 :full_name => 'hello',
80 80 :password => 'abcde',
81 81 :password_confirmation => 'abcde'
82 82 }}, {:user_id => @admin_id}
83 83
84 84 assert_response :redirect
85 85 assert_redirected_to :action => 'list'
86 86
87 87 assert_equal num_users + 1, User.count
88 88 end
89 89
90 90 def test_create_with_wrong_confirmation_password
91 91 num_users = User.count
92 92
93 93 post :create, {:user => {
94 94 :login => 'test',
95 95 :full_name => 'hello',
96 96 :password => 'abcde',
97 97 :password_confirmation => 'abcdef'
98 98 }}, {:user_id => @admin_id}
99 99
100 100 assert_response :success
101 101 assert_template 'new'
102 102
103 103 assert_equal num_users, User.count
104 104 end
105 105
106 106 def test_edit
107 107 get :edit, {:id => @first_id}, {:user_id => @admin_id}
108 108
109 109 assert_response :success
110 110 assert_template 'edit'
111 111
112 112 assert_not_nil assigns(:user)
113 113 end
114 114
115 115 def test_update
116 116 post :update, {
117 117 :id => @first_id,
118 118 :user => {
119 119 :login => 'test',
120 120 :full_name => 'hello',
121 121 :password => 'abcde',
122 122 :password_confirmation => 'abcde'
123 123 }
124 124 }, {:user_id => @admin_id}
125 125 assert_response :redirect
126 126 assert_redirected_to :action => 'show', :id => @first_id
127 127 end
128 128
129 129 def test_destroy
130 130 assert_nothing_raised {
131 131 User.find(@first_id)
132 132 }
133 133
134 134 post :destroy, {:id => @first_id}, {:user_id => @admin_id}
135 135 assert_response :redirect
136 136 assert_redirected_to :action => 'list'
137 137
138 138 assert_raise(ActiveRecord::RecordNotFound) {
139 139 User.find(@first_id)
140 140 }
141 141 end
142 142 end
@@ -1,18 +1,18
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 2 require 'users_controller'
3 3
4 4 # Re-raise errors caught by the controller.
5 5 class UsersController; def rescue_action(e) raise e end; end
6 6
7 - class UsersControllerTest < Test::Unit::TestCase
7 + class UsersControllerTest < ActionController::TestCase
8 8 def setup
9 9 @controller = UsersController.new
10 10 @request = ActionController::TestRequest.new
11 11 @response = ActionController::TestResponse.new
12 12 end
13 13
14 14 # Replace this with your real tests.
15 15 def test_truth
16 16 assert true
17 17 end
18 18 end
@@ -1,28 +1,29
1 1 ENV["RAILS_ENV"] = "test"
2 2 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3 3 require 'test_help'
4 4
5 - class Test::Unit::TestCase
5 + class ActiveSupport::TestCase
6 6 # Transactional fixtures accelerate your tests by wrapping each test method
7 7 # in a transaction that's rolled back on completion. This ensures that the
8 8 # test database remains unchanged so your fixtures don't have to be reloaded
9 9 # between every test method. Fewer database queries means faster tests.
10 10 #
11 11 # Read Mike Clark's excellent walkthrough at
12 12 # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13 13 #
14 14 # Every Active Record database supports transactions except MyISAM tables
15 15 # in MySQL. Turn off transactional fixtures in this case; however, if you
16 16 # don't care one way or the other, switching from MyISAM to InnoDB tables
17 17 # is recommended.
18 - self.use_transactional_fixtures = true
18 +
19 + self.use_transactional_fixtures = false
19 20
20 21 # Instantiated fixtures are slow, but give you @david where otherwise you
21 22 # would need people(:david). If you don't want to migrate your existing
22 23 # test cases which use the @david style and don't mind the speed hit (each
23 24 # instantiated fixtures translates to a database query per test method),
24 25 # then set this back to true.
25 26 self.use_instantiated_fixtures = false
26 27
27 28 # Add more helper methods to be used by all tests here...
28 29 end
You need to be logged in to leave comments. Login now