Commit 9aa9bc85ac1a342539baaa0b892dddc04ec154b8
1 parent
8482deba
Exists in
master
and in
5 other branches
Add fields to percentage calculation
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
2 changed files
with
15 additions
and
5 deletions
Show diff stats
lib/mpog_software_plugin.rb
... | ... | @@ -258,8 +258,8 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
258 | 258 | def calc_percentage_registration person |
259 | 259 | required_list = profile_required_list |
260 | 260 | empty_fields = profile_required_empty_list person |
261 | - | |
262 | - percentege = 100 - ((empty_fields.count*100)/required_list.count) | |
261 | + count = required_list[:person_fields].count + required_list[:user_fields].count | |
262 | + percentege = 100 - ((empty_fields.count*100)/count) | |
263 | 263 | person.percentage_incomplete = percentege |
264 | 264 | person.save(validate: false) |
265 | 265 | percentege |
... | ... | @@ -275,18 +275,26 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
275 | 275 | end |
276 | 276 | |
277 | 277 | def profile_required_list |
278 | - ["cell_phone","contact_phone","comercial_phone","country","city","state","organization_website","image"] | |
278 | + fields = Hash.new | |
279 | + fields[:person_fields] = ["cell_phone","contact_phone","comercial_phone","country","city","state","organization_website", "image", "identifier", "name"] | |
280 | + fields[:user_fields] = ["secondary_email", "email"] | |
281 | + fields | |
279 | 282 | end |
280 | 283 | |
281 | 284 | def profile_required_empty_list person |
282 | 285 | empty_fields = [] |
283 | 286 | required_list = profile_required_list |
284 | 287 | |
285 | - required_list.each do |field| | |
288 | + required_list[:person_fields].each do |field| | |
286 | 289 | if person.send(field).blank? |
287 | 290 | empty_fields << field.sub("_"," ") |
288 | 291 | end |
289 | 292 | end |
293 | + required_list[:user_fields].each do |field| | |
294 | + if person.user.send(field).blank? | |
295 | + empty_fields << field.sub("_"," ") | |
296 | + end | |
297 | + end | |
290 | 298 | empty_fields |
291 | 299 | end |
292 | 300 | ... | ... |
test/unit/mpog_software_plugin_test.rb
... | ... | @@ -22,10 +22,12 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase |
22 | 22 | @person.cell_phone = "76888919" |
23 | 23 | @person.contact_phone = "987654321" |
24 | 24 | |
25 | - assert_equal(50, @plugin.calc_percentage_registration(@person)) | |
25 | + assert_equal(67, @plugin.calc_percentage_registration(@person)) | |
26 | 26 | |
27 | 27 | @person.comercial_phone = "11223344" |
28 | 28 | @person.country = "I dont know" |
29 | + @person.state = "I dont know" | |
30 | + @person.city = "I dont know" | |
29 | 31 | @person.organization_website = "www.whatever.com" |
30 | 32 | @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') |
31 | 33 | @person.save | ... | ... |