usp_user_test.rb
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require File.dirname(__FILE__) + '/../../../../test/test_helper'
class StoaPlugin::UspUserTest < ActiveSupport::TestCase
SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt']
@db = Tempfile.new('stoa-test')
configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
ActiveRecord::Base.establish_connection(:stoa)
ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.create_table "pessoa" do |t|
t.integer "codpes"
t.text "numcpf"
t.date "dtanas"
end
ActiveRecord::Base.establish_connection(:test)
def setup
StoaPlugin::UspUser.create({:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true)
end
should 'check existence of usp_id' do
assert StoaPlugin::UspUser.exists?(123456)
assert !StoaPlugin::UspUser.exists?(654321)
end
should 'check if usp_id matches with a cpf' do
assert StoaPlugin::UspUser.matches?(123456, :cpf, 12345678)
assert !StoaPlugin::UspUser.matches?(123456, :cpf, 87654321)
assert !StoaPlugin::UspUser.matches?(654321, :cpf, 12345678)
end
should 'check if usp_id matches with a birth_date' do
assert StoaPlugin::UspUser.matches?(123456, :birth_date, '1970-01-30')
assert !StoaPlugin::UspUser.matches?(123456, :birth_date, '1999-01-30')
assert !StoaPlugin::UspUser.matches?(654321, :birth_date, '1970-01-30')
end
should 'filter leading zeroes of id codes on exists and matches' do
assert StoaPlugin::UspUser.exists?('0000123456')
assert StoaPlugin::UspUser.matches?(123456, :cpf, '00012345678')
end
should 'return false if field is nil' do
assert !StoaPlugin::UspUser.matches?(123456, nil, '00012345678')
end
end