Commit 24b37d9a0ae70245ee84f738a0d816157433fabf
1 parent
d2035875
Exists in
staging
and in
42 other branches
[stoa] Filtering leading zeroes from usp_id and cpf
(ActionItem2293)
Showing
2 changed files
with
8 additions
and
3 deletions
Show diff stats
plugins/stoa/lib/stoa_plugin/usp_user.rb
| ... | ... | @@ -9,15 +9,15 @@ class StoaPlugin::UspUser < ActiveRecord::Base |
| 9 | 9 | alias_attribute :birth_date, :dtanas |
| 10 | 10 | |
| 11 | 11 | def self.exists?(usp_id) |
| 12 | - !StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id}).nil? | |
| 12 | + !StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id.to_i}).nil? | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def self.matches?(usp_id, field, value) |
| 16 | - user = StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id}) | |
| 16 | + user = StoaPlugin::UspUser.find(:first, :conditions => {:codpes => usp_id.to_i}) | |
| 17 | 17 | return false if user.nil? || !user.respond_to?(field) || value.blank? |
| 18 | 18 | case field.to_sym |
| 19 | 19 | when :cpf |
| 20 | - user.cpf == Digest::MD5.hexdigest(SALT+value.to_s) | |
| 20 | + user.cpf == Digest::MD5.hexdigest(SALT+value.to_i.to_s) | |
| 21 | 21 | when :birth_date |
| 22 | 22 | user.birth_date.to_s == value |
| 23 | 23 | end | ... | ... |
plugins/stoa/test/unit/usp_user.rb
| ... | ... | @@ -37,5 +37,10 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase |
| 37 | 37 | assert !StoaPlugin::UspUser.matches?(123456, :birth_date, '1999-01-30') |
| 38 | 38 | assert !StoaPlugin::UspUser.matches?(654321, :birth_date, '1970-01-30') |
| 39 | 39 | end |
| 40 | + | |
| 41 | + should 'filter leading zeroes of id codes on exists and matches' do | |
| 42 | + assert StoaPlugin::UspUser.exists?('0000123456') | |
| 43 | + assert StoaPlugin::UspUser.matches?(123456, :cpf, '00012345678') | |
| 44 | + end | |
| 40 | 45 | end |
| 41 | 46 | ... | ... |