Description:
fixed seed.db for mock valid?
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r333:6abae4dc17ba - - 1 file changed: 1 inserted, 1 deleted

@@ -83,116 +83,116
83 83
84 84 {
85 85 :key => 'system.user_setting_enabled',
86 86 :value_type => 'boolean',
87 87 :default_value => 'true',
88 88 :description => 'If this option is true, users can change their settings'
89 89 },
90 90
91 91 # If Configuration['contest.test_request.early_timeout'] is true
92 92 # the user will not be able to use test request at 30 minutes
93 93 # before the contest ends.
94 94 {
95 95 :key => 'contest.test_request.early_timeout',
96 96 :value_type => 'boolean',
97 97 :default_value => 'false'
98 98 },
99 99
100 100 {
101 101 :key => 'system.multicontests',
102 102 :value_type => 'boolean',
103 103 :default_value => 'false'
104 104 },
105 105
106 106 {
107 107 :key => 'contest.confirm_indv_contest_start',
108 108 :value_type => 'boolean',
109 109 :default_value => 'false'
110 110 },
111 111
112 112 {
113 113 :key => 'contest.default_contest_name',
114 114 :value_type => 'string',
115 115 :default_value => 'none',
116 116 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
117 117 }
118 118
119 119 ]
120 120
121 121
122 122 def create_configuration_key(key,
123 123 value_type,
124 124 default_value,
125 125 description='')
126 126 conf = (GraderConfiguration.find_by_key(key) ||
127 127 GraderConfiguration.new(:key => key,
128 128 :value_type => value_type,
129 129 :value => default_value))
130 130 conf.description = description
131 131 conf.save
132 132 end
133 133
134 134 def seed_config
135 135 CONFIGURATIONS.each do |conf|
136 136 if conf.has_key? :description
137 137 desc = conf[:description]
138 138 else
139 139 desc = ''
140 140 end
141 141 create_configuration_key(conf[:key],
142 142 conf[:value_type],
143 143 conf[:default_value],
144 144 desc)
145 145 end
146 146 end
147 147
148 148 def seed_roles
149 149 return if Role.find_by_name('admin')
150 150
151 151 role = Role.create(:name => 'admin')
152 152 user_admin_right = Right.create(:name => 'user_admin',
153 153 :controller => 'user_admin',
154 154 :action => 'all')
155 155 problem_admin_right = Right.create(:name=> 'problem_admin',
156 156 :controller => 'problems',
157 157 :action => 'all')
158 158
159 159 graders_right = Right.create(:name => 'graders_admin',
160 160 :controller => 'graders',
161 161 :action => 'all')
162 162
163 163 role.rights << user_admin_right;
164 164 role.rights << problem_admin_right;
165 165 role.rights << graders_right;
166 166 role.save
167 167 end
168 168
169 169 def seed_root
170 170 return if User.find_by_login('root')
171 171
172 172 root = User.new(:login => 'root',
173 173 :full_name => 'Administrator',
174 174 :alias => 'root')
175 175 root.password = 'ioionrails';
176 176
177 177 class << root
178 178 public :encrypt_new_password
179 - def valid?
179 + def valid?(context=nil)
180 180 true
181 181 end
182 182 end
183 183
184 184 root.encrypt_new_password
185 185
186 186 root.roles << Role.find_by_name('admin')
187 187
188 188 root.activated = true
189 189 root.save
190 190 end
191 191
192 192 def seed_users_and_roles
193 193 seed_roles
194 194 seed_root
195 195 end
196 196
197 197 seed_config
198 198 seed_users_and_roles
You need to be logged in to leave comments. Login now