Description:
uses empty? instead of length to check model validation errors when importing problems
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r338:0d4a8ccf5805 - - 2 files changed: 3 inserted, 3 deleted
@@ -151,25 +151,25 | |||
|
151 | 151 | def import |
|
152 | 152 | @allow_test_pair_import = allow_test_pair_import? |
|
153 | 153 | end |
|
154 | 154 | |
|
155 | 155 | def do_import |
|
156 | 156 | old_problem = Problem.find_by_name(params[:name]) |
|
157 | 157 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
158 | 158 | params.delete :import_to_db |
|
159 | 159 | end |
|
160 | 160 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
161 | 161 | old_problem) |
|
162 | 162 | |
|
163 |
- if @problem.errors. |
|
|
163 | + if !@problem.errors.empty? | |
|
164 | 164 | render :action => 'import' and return |
|
165 | 165 | end |
|
166 | 166 | |
|
167 | 167 | if old_problem!=nil |
|
168 | 168 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
169 | 169 | end |
|
170 | 170 | @log = import_log |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | def remove_contest |
|
174 | 174 | problem = Problem.find(params[:id]) |
|
175 | 175 | contest = Contest.find(params[:contest_id]) |
@@ -13,25 +13,25 | |||
|
13 | 13 | DEFAULT_TIME_LIMIT = 1 |
|
14 | 14 | DEFAULT_MEMORY_LIMIT = 32 |
|
15 | 15 | |
|
16 | 16 | def self.find_available_problems |
|
17 | 17 | Problem.available.all(:order => "date_added DESC") |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | def self.create_from_import_form_params(params, old_problem=nil) |
|
21 | 21 | org_problem = old_problem || Problem.new |
|
22 | 22 | import_params, problem = Problem.extract_params_and_check(params, |
|
23 | 23 | org_problem) |
|
24 | 24 | |
|
25 |
- if problem.errors. |
|
|
25 | + if !problem.errors.empty? | |
|
26 | 26 | return problem, 'Error importing' |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | problem.full_score = 100 |
|
30 | 30 | problem.date_added = Time.new |
|
31 | 31 | problem.test_allowed = true |
|
32 | 32 | problem.output_only = false |
|
33 | 33 | problem.available = false |
|
34 | 34 | |
|
35 | 35 | if not problem.save |
|
36 | 36 | return problem, 'Error importing' |
|
37 | 37 | end |
@@ -83,25 +83,25 | |||
|
83 | 83 | if memory_limit==0 and params[:memory_limit]!='0' |
|
84 | 84 | problem.errors.add_to_base('Memory limit format errors.') |
|
85 | 85 | elsif memory_limit<=0 or memory_limit >512 |
|
86 | 86 | problem.errors.add_to_base('Memory limit out of range.') |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | if params[:file]==nil or params[:file]=='' |
|
90 | 90 | problem.errors.add_to_base('No testdata file.') |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | file = params[:file] |
|
94 | 94 | |
|
95 |
- if problem.errors. |
|
|
95 | + if !problem.errors.empty? | |
|
96 | 96 | return nil, problem |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | problem.name = params[:name] |
|
100 | 100 | if params[:full_name]!='' |
|
101 | 101 | problem.full_name = params[:full_name] |
|
102 | 102 | else |
|
103 | 103 | problem.full_name = params[:name] |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | return [{ |
|
107 | 107 | :time_limit => time_limit, |
You need to be logged in to leave comments.
Login now