usp_user.rb
1.16 KB
require File.dirname(__FILE__) + '/../../../../test/test_helper'
class StoaPlugin::UspUserTest < ActiveSupport::TestCase
SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt']
def setup
@db = Tempfile.new('stoa-test')
configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path}
ActiveRecord::Base.establish_connection(:stoa)
ActiveRecord::Schema.create_table "pessoa" do |t|
t.integer "codpes"
t.text "numcpf"
t.text "numdocidf"
end
ActiveRecord::Base.establish_connection(:test)
StoaPlugin::UspUser.create!(:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :rg => Digest::MD5.hexdigest(SALT+'87654321'))
end
def teardown
@db.unlink
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 field' do
assert StoaPlugin::UspUser.matches?(123456, :cpf, 12345678)
assert !StoaPlugin::UspUser.matches?(123456, :cpf, 87654321)
assert !StoaPlugin::UspUser.matches?(654321, :cpf, 12345678)
end
end