mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 10:49:39 +02:00
Ensure generated numbers are always numbers
This commit is contained in:
parent
12e32af524
commit
f838a6506c
5 changed files with 14 additions and 2 deletions
|
@ -10,6 +10,7 @@ class LegalDocument < ActiveRecord::Base
|
||||||
def save_to_filesystem
|
def save_to_filesystem
|
||||||
loop do
|
loop do
|
||||||
rand = SecureRandom.random_number.to_s.last(4)
|
rand = SecureRandom.random_number.to_s.last(4)
|
||||||
|
next if rand.to_i == 0 || rand.length < 4
|
||||||
self.path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
|
self.path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{document_type}"
|
||||||
break unless File.file?(path)
|
break unless File.file?(path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Registrar < ActiveRecord::Base
|
||||||
base = nil
|
base = nil
|
||||||
loop do
|
loop do
|
||||||
base = SecureRandom.random_number.to_s.last(8)
|
base = SecureRandom.random_number.to_s.last(8)
|
||||||
break if base.length == 8
|
break if base.to_i != 0 && base.length == 8
|
||||||
end
|
end
|
||||||
|
|
||||||
control_base = (base + '2715' + '00').to_i
|
control_base = (base + '2715' + '00').to_i
|
||||||
|
|
|
@ -98,7 +98,8 @@ set :shared_paths, [
|
||||||
'log',
|
'log',
|
||||||
'public/system',
|
'public/system',
|
||||||
'export/zonefiles',
|
'export/zonefiles',
|
||||||
'import/bank_statements'
|
'import/bank_statements',
|
||||||
|
'import/legal_documents'
|
||||||
]
|
]
|
||||||
|
|
||||||
# Optional settings:
|
# Optional settings:
|
||||||
|
@ -137,6 +138,9 @@ task setup: :environment do
|
||||||
queue! %(mkdir -p "#{deploy_to}/shared/import/bank_statements")
|
queue! %(mkdir -p "#{deploy_to}/shared/import/bank_statements")
|
||||||
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/import/bank_statements")
|
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/import/bank_statements")
|
||||||
|
|
||||||
|
queue! %(mkdir -p "#{deploy_to}/shared/import/legal_documents")
|
||||||
|
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/import/legal_documents")
|
||||||
|
|
||||||
queue! %(touch "#{deploy_to}/shared/config/database.yml")
|
queue! %(touch "#{deploy_to}/shared/config/database.yml")
|
||||||
deploy do
|
deploy do
|
||||||
invoke :'git:clone'
|
invoke :'git:clone'
|
||||||
|
|
|
@ -5,6 +5,7 @@ class SaveLegalDocsToDisk < ActiveRecord::Migration
|
||||||
path = nil
|
path = nil
|
||||||
loop do
|
loop do
|
||||||
rand = SecureRandom.random_number.to_s.last(4)
|
rand = SecureRandom.random_number.to_s.last(4)
|
||||||
|
next if rand.to_i == 0 || rand.length < 4
|
||||||
path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{x.document_type}"
|
path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{x.document_type}"
|
||||||
break unless File.file?(path)
|
break unless File.file?(path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,6 +32,12 @@ describe Registrar do
|
||||||
it 'should not have valid code' do
|
it 'should not have valid code' do
|
||||||
@registrar.code.should == nil
|
@registrar.code.should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should generate reference number' do
|
||||||
|
@registrar.generate_iso_11649_reference_no
|
||||||
|
@registrar.reference_no.should_not be_blank
|
||||||
|
@registrar.reference_no.last(10).to_i.should_not == 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid attributes' do
|
context 'with valid attributes' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue