From fca6ac8b5d698fda6e4232993c285cd771814eb4 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Thu, 2 Oct 2014 15:03:10 -0300 Subject: [PATCH] correcoes_aderencia: Correct complete registration percentage --- lib/mpog_software_plugin.rb | 2 +- public/mpog-incomplete-registration.js | 46 ++++++++++++++++++++++++---------------------- test/unit/mpog_software_plugin_test.rb | 21 ++++++++++----------- test/unit/plugin_test_helper.rb | 27 +++++++++++++++++---------- views/incomplete_registration.html.erb | 18 ++++++++++-------- 5 files changed, 62 insertions(+), 52 deletions(-) diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 054ce76..b1edfc7 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -268,7 +268,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin end def profile_required_list - required_list = ["cell_phone","contact_phone","institutions","comercial_phone","country","city","state","organization_website","image"] + ["cell_phone","contact_phone","comercial_phone","country","city","state","organization_website","image"] end def profile_required_empty_list person diff --git a/public/mpog-incomplete-registration.js b/public/mpog-incomplete-registration.js index 87ec324..79ff15b 100644 --- a/public/mpog-incomplete-registration.js +++ b/public/mpog-incomplete-registration.js @@ -1,30 +1,32 @@ -function hide_incomplete_percentage(evt) { - evt.preventDefault(); +(function() { + function hide_incomplete_percentage(evt) { + evt.preventDefault(); - jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ - if( response == true ) - jQuery("#complete_registration").fadeOut(); - }); -} + jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ + if( response == true ) + jQuery("#complete_registration").fadeOut(); + }); + } -function show_complete_progressbar() { - var percentage = jQuery("#complete_registration_message span").html(); - var canvas_tag = document.getElementById("complete_registration_percentage"); + function show_complete_progressbar() { + var percentage = jQuery("#complete_registration_message span").html(); + var canvas_tag = document.getElementById("complete_registration_percentage"); - if( canvas_tag != null ) { - var context = canvas_tag.getContext("2d"); + if( canvas_tag != null ) { + var context = canvas_tag.getContext("2d"); - percentage = canvas_tag.width*(percentage/100.0); + percentage = canvas_tag.width*(percentage/100.0); - context.beginPath(); - context.rect(0, 0, percentage, canvas_tag.height); - context.fillStyle = '#00FF00'; - context.fill(); + context.beginPath(); + context.rect(0, 0, percentage, canvas_tag.height); + context.fillStyle = '#00FF00'; + context.fill(); + } } -} -jQuery(document).ready(function(){ - jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); + jQuery(document).ready(function(){ + jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); - show_complete_progressbar(); -}); + show_complete_progressbar(); + }); +})(); \ No newline at end of file diff --git a/test/unit/mpog_software_plugin_test.rb b/test/unit/mpog_software_plugin_test.rb index d54d497..9223042 100644 --- a/test/unit/mpog_software_plugin_test.rb +++ b/test/unit/mpog_software_plugin_test.rb @@ -6,13 +6,11 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase def setup @plugin = MpogSoftwarePlugin.new - @user = create_user("login", "user@email.com", "123456", "123456", "user@secondary_email.com") - @person = @user.person + @person = create_person("My Name", "user@email.com", "123456", "123456", "user@secondary_email.com", "Any State", "Some City") end def teardown - @user.person.destroy - @user.destroy + @person.destroy end @@ -21,16 +19,17 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase end should 'calculate the percentege of person incomplete fields' do - @person.name = "Person Name" @person.cell_phone = "76888919" + @person.contact_phone = "987654321" - required_list = ["cell_phone","contact_phone","institution","comercial_phone","country","city","state","organization_website","image"] + assert_equal(50, @plugin.calc_percentage_registration(@person)) - empty_fields = required_list.count - 1 - test_percentege = 100 - ((empty_fields * 100) / required_list.count) + @person.comercial_phone = "11223344" + @person.country = "I dont know" + @person.organization_website = "www.whatever.com" + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') + @person.save - plugin_percentege = @plugin.calc_percentage_registration(@person) - - assert_equal(test_percentege, plugin_percentege) + assert_equal(100, @plugin.calc_percentage_registration(@person)) end end diff --git a/test/unit/plugin_test_helper.rb b/test/unit/plugin_test_helper.rb index 23c2186..29663e2 100644 --- a/test/unit/plugin_test_helper.rb +++ b/test/unit/plugin_test_helper.rb @@ -35,25 +35,32 @@ module PluginTestHelper community end + def create_person name, email, password, password_confirmation, secondary_email, state, city + user = create_user(name.to_slug, email, password, password_confirmation, secondary_email) + person = Person::new + + person.name = name + person.state = state + person.city = city + person.user = user + person.save + + person + end + + private + def create_user login, email, password, password_confirmation, secondary_email user = User.new + user.login = login user.email = email user.password = password user.password_confirmation = password_confirmation user.secondary_email = secondary_email + user.save - user.person.save user end - def create_person name, email, password, password_confirmation, secondary_email, state, city - user = create_user(name.downcase, email, password, password_confirmation, secondary_email) - user.person.name = name - user.person.state = state - user.person.city = city - user.person.save - user.person - end - end diff --git a/views/incomplete_registration.html.erb b/views/incomplete_registration.html.erb index d42c4d9..ae2acb8 100644 --- a/views/incomplete_registration.html.erb +++ b/views/incomplete_registration.html.erb @@ -1,10 +1,12 @@ -
-
-
<%= _("Complete Profile")+": #{@percentege}%" %>
- -
- <%= @profile_edit_link %> | - <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %> +<% if @percentege < 100 then %> +
+
+
<%= _("Complete Profile")+": #{@percentege}%" %>
+ +
+ <%= @profile_edit_link %> | + <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %> +
-
\ No newline at end of file +<% end %> \ No newline at end of file -- libgit2 0.21.2