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: 62 inserted, 197 deleted

@@ -327,7 +327,7
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
@@ -8,18 +8,24
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
@@ -34,15 +40,15
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 #
@@ -82,10 +88,10
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?
@@ -112,22 +118,22
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
@@ -146,11 +152,11
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
@@ -165,7 +171,7
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
@@ -130,6 +130,9
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
@@ -170,6 +173,15
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?
@@ -2,13 +2,4
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 5 end
12 - end
13 -
14 - end
@@ -12,6 +12,6
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
@@ -24,6 +24,6
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
@@ -110,8 +110,6
110 110 t.integer "description_id"
111 111 t.boolean "test_allowed"
112 112 t.boolean "output_only"
113 - t.integer "level", :default => 0
114 - t.datetime "updated_at"
115 113 t.string "description_filename"
116 114 end
117 115
@@ -210,7 +208,6
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|
@@ -254,16 +251,6
254 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
@@ -25,6 +25,7
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
@@ -18,7 +18,7
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 #
@@ -3,16 +3,18
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 4 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 - 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 4 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 - end
@@ -4,7 +4,7
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
@@ -1,24 +1,12
1 1 require File.dirname(__FILE__) + '/../test_helper'
2 - require 'main_controller'
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
@@ -4,7 +4,7
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
@@ -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 4 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 - end
@@ -4,7 +4,7
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
@@ -4,7 +4,7
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
@@ -2,7 +2,7
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
@@ -15,7 +15,8
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
You need to be logged in to leave comments. Login now