Description:
update models to satisfy rails 4
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r618:45e8321629ae - - 7 files changed: 12 inserted, 16 deleted
@@ -1,8 +1,8 | |||
|
1 | 1 | class Contest < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | has_and_belongs_to_many :users |
|
4 | 4 | has_and_belongs_to_many :problems |
|
5 | 5 | |
|
6 |
- scope :enabled, |
|
|
6 | + scope :enabled, -> { where(enabled: true) } | |
|
7 | 7 | |
|
8 | 8 | end |
@@ -1,5 +1,4 | |||
|
1 | 1 | class Login < ActiveRecord::Base |
|
2 | 2 | belongs_to :user |
|
3 | 3 | |
|
4 | - attr_accessible :ip_address, :logged_in_at, :user_id | |
|
5 | 4 | end |
@@ -1,21 +1,21 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | has_and_belongs_to_many :contests, :uniq => true |
|
5 | 5 | has_many :test_pairs, :dependent => :delete_all |
|
6 | 6 | has_many :testcases, :dependent => :destroy |
|
7 | 7 | |
|
8 | 8 | validates_presence_of :name |
|
9 |
- validates_format_of :name, :with => / |
|
|
9 | + validates_format_of :name, :with => /\A\w+\z/ | |
|
10 | 10 | validates_presence_of :full_name |
|
11 | 11 | |
|
12 | 12 | scope :available, :conditions => {:available => true} |
|
13 | 13 | |
|
14 | 14 | DEFAULT_TIME_LIMIT = 1 |
|
15 | 15 | DEFAULT_MEMORY_LIMIT = 32 |
|
16 | 16 | |
|
17 | 17 | def self.find_available_problems |
|
18 | 18 | Problem.available.all(:order => "date_added DESC, name ASC") |
|
19 | 19 | end |
|
20 | 20 | |
|
21 | 21 | def self.create_from_import_form_params(params, old_problem=nil) |
@@ -1,3 +1,3 | |||
|
1 | 1 | class SubmissionViewLog < ActiveRecord::Base |
|
2 | - attr_accessible :submission_id, :user_id | |
|
2 | + #attr_accessible :submission_id, :user_id | |
|
3 | 3 | end |
@@ -7,26 +7,25 | |||
|
7 | 7 | # it works as well with problem=nil. In this case, we shall provide |
|
8 | 8 | # a "default" execution environment for it. This can be done |
|
9 | 9 | # seamlessly by using TestRequest#problem_name or |
|
10 | 10 | # TestRequest#name_of(problem) when retrieving the name of the |
|
11 | 11 | # problem: #name_of would return problem.name when problem!=nil and |
|
12 | 12 | # it would return "default" when problem=nil, #problem_name just |
|
13 | 13 | # call #name_of. |
|
14 | 14 | # |
|
15 | 15 | |
|
16 | 16 | require 'fileutils' |
|
17 | 17 | |
|
18 | 18 | class TestRequest < Task |
|
19 | - | |
|
20 | - set_table_name "test_requests" | |
|
19 | + self.table_name = "test_requests" | |
|
21 | 20 | |
|
22 | 21 | belongs_to :user |
|
23 | 22 | belongs_to :problem |
|
24 | 23 | belongs_to :submission |
|
25 | 24 | |
|
26 | 25 | validates_presence_of :submission |
|
27 | 26 | validate :must_have_valid_problem |
|
28 | 27 | |
|
29 | 28 | def problem_name |
|
30 | 29 | TestRequest.name_of(self.problem) |
|
31 | 30 | end |
|
32 | 31 |
@@ -1,4 +1,4 | |||
|
1 | 1 | class Testcase < ActiveRecord::Base |
|
2 | 2 | belongs_to :problem |
|
3 | - attr_accessible :group, :input, :num, :score, :sol | |
|
3 | + #attr_accessible :group, :input, :num, :score, :sol | |
|
4 | 4 | end |
@@ -1,42 +1,40 | |||
|
1 | 1 | require 'digest/sha1' |
|
2 | 2 | require 'net/pop' |
|
3 | 3 | require 'net/https' |
|
4 | 4 | require 'net/http' |
|
5 | 5 | require 'json' |
|
6 | 6 | |
|
7 | 7 | class User < ActiveRecord::Base |
|
8 | 8 | |
|
9 | 9 | has_and_belongs_to_many :roles |
|
10 | 10 | |
|
11 |
- has_many :test_requests, |
|
|
11 | + has_many :test_requests, -> {order(submitted_at: DESC)} | |
|
12 | 12 | |
|
13 | - has_many :messages, | |
|
13 | + has_many :messages, -> { order(created_at: DESC) }, | |
|
14 | 14 | :class_name => "Message", |
|
15 |
- :foreign_key => "sender_id" |
|
|
16 | - :order => 'created_at DESC' | |
|
15 | + :foreign_key => "sender_id" | |
|
17 | 16 | |
|
18 | - has_many :replied_messages, | |
|
17 | + has_many :replied_messages, -> { order(created_at: DESC) }, | |
|
19 | 18 | :class_name => "Message", |
|
20 |
- :foreign_key => "receiver_id" |
|
|
21 | - :order => 'created_at DESC' | |
|
19 | + :foreign_key => "receiver_id" | |
|
22 | 20 | |
|
23 | 21 | has_one :contest_stat, :class_name => "UserContestStat", :dependent => :destroy |
|
24 | 22 | |
|
25 | 23 | belongs_to :site |
|
26 | 24 | belongs_to :country |
|
27 | 25 | |
|
28 |
- has_and_belongs_to_many :contests, |
|
|
26 | + has_and_belongs_to_many :contests, -> { order(:name); uniq} | |
|
29 | 27 | |
|
30 |
- scope :activated_users, |
|
|
28 | + scope :activated_users, -> {where activated: true} | |
|
31 | 29 | |
|
32 | 30 | validates_presence_of :login |
|
33 | 31 | validates_uniqueness_of :login |
|
34 | 32 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
35 | 33 | validates_length_of :login, :within => 3..30 |
|
36 | 34 | |
|
37 | 35 | validates_presence_of :full_name |
|
38 | 36 | validates_length_of :full_name, :minimum => 1 |
|
39 | 37 | |
|
40 | 38 | validates_presence_of :password, :if => :password_required? |
|
41 | 39 | validates_length_of :password, :within => 4..20, :if => :password_required? |
|
42 | 40 | validates_confirmation_of :password, :if => :password_required? |
You need to be logged in to leave comments.
Login now