From aef865a916bd2dfcf771e1d2d7a7392dc3003c0b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 20 Dec 2017 10:55:54 +0100 Subject: [PATCH] Fixed issue #1723 - Wrong ticket number count in preview. --- .../_settings/area_ticket_number.coffee | 2 +- test/unit/ticket_number_test.rb | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 test/unit/ticket_number_test.rb diff --git a/app/assets/javascripts/app/controllers/_settings/area_ticket_number.coffee b/app/assets/javascripts/app/controllers/_settings/area_ticket_number.coffee index 70ccfb563..dcbd9f6f6 100644 --- a/app/assets/javascripts/app/controllers/_settings/area_ticket_number.coffee +++ b/app/assets/javascripts/app/controllers/_settings/area_ticket_number.coffee @@ -42,7 +42,7 @@ class App.SettingsAreaTicketNumber extends App.Controller number = "#{App.Config.get('ticket_hook')}#{App.Config.get('system_id')}" counter = '1' if paramsItem.min_size - minSize = parseInt(paramsItem.min_size) + minSize = parseInt(paramsItem.min_size) - "#{App.Config.get('system_id')}".length if paramsItem.checksum minSize -= 1 if minSize > 1 diff --git a/test/unit/ticket_number_test.rb b/test/unit/ticket_number_test.rb new file mode 100644 index 000000000..a72019bff --- /dev/null +++ b/test/unit/ticket_number_test.rb @@ -0,0 +1,106 @@ + +require 'test_helper' + +class TicketNumberTest < ActiveSupport::TestCase + test 'number' do + Setting.set('ticket_number_increment', { checksum: false, min_size: 5 }) + Setting.set('system_id', 1) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 5) + + Setting.set('ticket_number_increment', { checksum: false, min_size: 10 }) + Setting.set('system_id', 1) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 10) + + Setting.set('ticket_number_increment', { checksum: true, min_size: 5 }) + Setting.set('system_id', 1) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 5) + + Setting.set('ticket_number_increment', { checksum: true, min_size: 10 }) + Setting.set('system_id', 1) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 10) + + Setting.set('ticket_number_increment', { checksum: false, min_size: 5 }) + Setting.set('system_id', 88) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 5) + + Setting.set('ticket_number_increment', { checksum: false, min_size: 10 }) + Setting.set('system_id', 88) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 10) + + Setting.set('ticket_number_increment', { checksum: true, min_size: 5 }) + Setting.set('system_id', 88) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 5) + + Setting.set('ticket_number_increment', { checksum: true, min_size: 10 }) + Setting.set('system_id', 88) + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 10) + + 150.times do + number = Ticket::Number.generate + assert_equal(number.to_s.length, 10) + end + + end + + test 'date' do + Setting.set('ticket_number', 'Ticket::Number::Date') + Setting.set('ticket_number_date', { checksum: false }) + Setting.set('system_id', 1) + system_id = Setting.get('system_id') + number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}" + + number = Ticket::Number.generate + assert_equal(number.to_s.length, 13) + assert_match(/#{number_prefix}/, number.to_s) + + Setting.set('ticket_number_date', { checksum: false }) + Setting.set('system_id', 88) + + number = Ticket::Number.generate + system_id = Setting.get('system_id') + number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}" + assert_equal(number.to_s.length, 14) + assert_match(/#{number_prefix}/, number.to_s) + + Setting.set('ticket_number_date', { checksum: true }) + Setting.set('system_id', 1) + + number = Ticket::Number.generate + system_id = Setting.get('system_id') + number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}" + assert_equal(number.to_s.length, 14) + assert_match(/#{number_prefix}/, number.to_s) + + Setting.set('ticket_number_date', { checksum: true }) + Setting.set('system_id', 88) + + number = Ticket::Number.generate + system_id = Setting.get('system_id') + number_prefix = "#{Time.zone.now.strftime('%Y%m%d')}#{system_id}" + assert_equal(number.to_s.length, 15) + assert_match(/#{number_prefix}/, number.to_s) + + 150.times do + number = Ticket::Number.generate + assert_equal(number.to_s.length, 15) + end + + end + +end