Commit 4e6065c448a3461e55141c1d6ec4f1603fd4efa9
1 parent
208311e8
Exists in
master
and in
28 other branches
[stoa] Avoiding crash if no field is passed to matches
Showing
2 changed files
with
5 additions
and
1 deletions
Show diff stats
plugins/stoa/lib/stoa_plugin/usp_user.rb
@@ -15,7 +15,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base | @@ -15,7 +15,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base | ||
15 | def self.matches?(usp_id, field, value) | 15 | def self.matches?(usp_id, field, value) |
16 | usp_id.to_s.gsub!(/[.-]/,'') | 16 | usp_id.to_s.gsub!(/[.-]/,'') |
17 | user = StoaPlugin::UspUser.find_by_codpes(usp_id.to_i) | 17 | user = StoaPlugin::UspUser.find_by_codpes(usp_id.to_i) |
18 | - return false if user.nil? || !user.respond_to?(field) || value.blank? | 18 | + return false if user.nil? || field.blank? || !user.respond_to?(field) || value.blank? |
19 | case field.to_sym | 19 | case field.to_sym |
20 | when :cpf | 20 | when :cpf |
21 | value.to_s.gsub!(/[.-]/,'') | 21 | value.to_s.gsub!(/[.-]/,'') |
plugins/stoa/test/unit/usp_user_test.rb
@@ -43,5 +43,9 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | @@ -43,5 +43,9 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase | ||
43 | assert StoaPlugin::UspUser.exists?('0000123456') | 43 | assert StoaPlugin::UspUser.exists?('0000123456') |
44 | assert StoaPlugin::UspUser.matches?(123456, :cpf, '00012345678') | 44 | assert StoaPlugin::UspUser.matches?(123456, :cpf, '00012345678') |
45 | end | 45 | end |
46 | + | ||
47 | + should 'return false if field is nil' do | ||
48 | + assert !StoaPlugin::UspUser.matches?(123456, nil, '00012345678') | ||
49 | + end | ||
46 | end | 50 | end |
47 | 51 |