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,8 +258,8 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
| 258 | def calc_percentage_registration person | 258 | def calc_percentage_registration person |
| 259 | required_list = profile_required_list | 259 | required_list = profile_required_list |
| 260 | empty_fields = profile_required_empty_list person | 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 | person.percentage_incomplete = percentege | 263 | person.percentage_incomplete = percentege |
| 264 | person.save(validate: false) | 264 | person.save(validate: false) |
| 265 | percentege | 265 | percentege |
| @@ -275,18 +275,26 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -275,18 +275,26 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
| 275 | end | 275 | end |
| 276 | 276 | ||
| 277 | def profile_required_list | 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 | end | 282 | end |
| 280 | 283 | ||
| 281 | def profile_required_empty_list person | 284 | def profile_required_empty_list person |
| 282 | empty_fields = [] | 285 | empty_fields = [] |
| 283 | required_list = profile_required_list | 286 | required_list = profile_required_list |
| 284 | 287 | ||
| 285 | - required_list.each do |field| | 288 | + required_list[:person_fields].each do |field| |
| 286 | if person.send(field).blank? | 289 | if person.send(field).blank? |
| 287 | empty_fields << field.sub("_"," ") | 290 | empty_fields << field.sub("_"," ") |
| 288 | end | 291 | end |
| 289 | end | 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 | empty_fields | 298 | empty_fields |
| 291 | end | 299 | end |
| 292 | 300 |
test/unit/mpog_software_plugin_test.rb
| @@ -22,10 +22,12 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase | @@ -22,10 +22,12 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase | ||
| 22 | @person.cell_phone = "76888919" | 22 | @person.cell_phone = "76888919" |
| 23 | @person.contact_phone = "987654321" | 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 | @person.comercial_phone = "11223344" | 27 | @person.comercial_phone = "11223344" |
| 28 | @person.country = "I dont know" | 28 | @person.country = "I dont know" |
| 29 | + @person.state = "I dont know" | ||
| 30 | + @person.city = "I dont know" | ||
| 29 | @person.organization_website = "www.whatever.com" | 31 | @person.organization_website = "www.whatever.com" |
| 30 | @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') | 32 | @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') |
| 31 | @person.save | 33 | @person.save |