Commit e1df99fbd9232b4d22de4fa9a55ae7b7269fd176
1 parent
1f4a8040
Exists in
master
and in
5 other branches
correcoes_aderencia: Fix full name regex bug
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
3 changed files
with
22 additions
and
3 deletions
Show diff stats
lib/ext/person.rb
| @@ -60,8 +60,17 @@ class Person | @@ -60,8 +60,17 @@ class Person | ||
| 60 | def validate_full_name | 60 | def validate_full_name |
| 61 | reg_firsts_char = /(^|\s)([a-z]|[0-9])/ | 61 | reg_firsts_char = /(^|\s)([a-z]|[0-9])/ |
| 62 | reg_special_char = /[^\w\*\s]/ | 62 | reg_special_char = /[^\w\*\s]/ |
| 63 | + invalid = false | ||
| 63 | 64 | ||
| 64 | - invalid = reg_firsts_char.match(self.name) || reg_special_char.match(self.name) | 65 | + return false if self.name.blank? |
| 66 | + | ||
| 67 | + self.name.split(" ").each do |value| | ||
| 68 | + invalid = if value.length > 3 | ||
| 69 | + reg_firsts_char.match(value) || reg_special_char.match(value) | ||
| 70 | + else | ||
| 71 | + reg_special_char.match(value) | ||
| 72 | + end | ||
| 73 | + end | ||
| 65 | 74 | ||
| 66 | if invalid | 75 | if invalid |
| 67 | self.errors.add(:name, _("Should begin with a capital letter and no special characters")) | 76 | self.errors.add(:name, _("Should begin with a capital letter and no special characters")) |
public/mpog-user-validations.js
| @@ -92,8 +92,18 @@ | @@ -92,8 +92,18 @@ | ||
| 92 | function is_invalid_formated(text) { | 92 | function is_invalid_formated(text) { |
| 93 | var reg_firsts_char = /(^|\s)([a-z]|[0-9])/g; | 93 | var reg_firsts_char = /(^|\s)([a-z]|[0-9])/g; |
| 94 | var reg_special_char = /[^\w\*\s*]/g; | 94 | var reg_special_char = /[^\w\*\s*]/g; |
| 95 | + var invalid = false; | ||
| 96 | + var slices = text.split(" "); | ||
| 97 | + | ||
| 98 | + for(var i = 0; i < slices.length; i++) { | ||
| 99 | + if( slices[i].length > 3 ) { | ||
| 100 | + invalid = reg_firsts_char.test(slices[i]) || reg_special_char.test(slices[i]); | ||
| 101 | + } else { | ||
| 102 | + invalid = reg_special_char.test(slices[i]); | ||
| 103 | + } | ||
| 104 | + } | ||
| 95 | 105 | ||
| 96 | - return reg_firsts_char.test(text) || reg_special_char.test(text); | 106 | + return invalid; |
| 97 | } | 107 | } |
| 98 | 108 | ||
| 99 | function show_full_name_error_message() { | 109 | function show_full_name_error_message() { |
test/unit/mpog_person_test.rb
| @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
| 2 | 2 | ||
| 3 | class MpogSoftwarePluginPersonTest < ActiveSupport::TestCase | 3 | class MpogSoftwarePluginPersonTest < ActiveSupport::TestCase |
| 4 | should 'save person with a valid full name' do | 4 | should 'save person with a valid full name' do |
| 5 | - p = Person::new :name=>"S1mpl3 N4m3", :identifier=>"simple-name" | 5 | + p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name" |
| 6 | p.user = fast_create(:user) | 6 | p.user = fast_create(:user) |
| 7 | 7 | ||
| 8 | assert_equal true, p.save | 8 | assert_equal true, p.save |