Commit 24b37d9a0ae70245ee84f738a0d816157433fabf
1 parent
d2035875
Exists in
master
and in
29 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,15 +9,15 @@ class StoaPlugin::UspUser < ActiveRecord::Base | ||
9 | alias_attribute :birth_date, :dtanas | 9 | alias_attribute :birth_date, :dtanas |
10 | 10 | ||
11 | def self.exists?(usp_id) | 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 | end | 13 | end |
14 | 14 | ||
15 | def self.matches?(usp_id, field, value) | 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 | return false if user.nil? || !user.respond_to?(field) || value.blank? | 17 | return false if user.nil? || !user.respond_to?(field) || value.blank? |
18 | case field.to_sym | 18 | case field.to_sym |
19 | when :cpf | 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 | when :birth_date | 21 | when :birth_date |
22 | user.birth_date.to_s == value | 22 | user.birth_date.to_s == value |
23 | end | 23 | end |
plugins/stoa/test/unit/usp_user.rb
@@ -37,5 +37,10 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | @@ -37,5 +37,10 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | ||
37 | assert !StoaPlugin::UspUser.matches?(123456, :birth_date, '1999-01-30') | 37 | assert !StoaPlugin::UspUser.matches?(123456, :birth_date, '1999-01-30') |
38 | assert !StoaPlugin::UspUser.matches?(654321, :birth_date, '1970-01-30') | 38 | assert !StoaPlugin::UspUser.matches?(654321, :birth_date, '1970-01-30') |
39 | end | 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 | end | 45 | end |
41 | 46 |