(Guillermo) ticketnumber stage 1 [skip ci]

This commit is contained in:
AntonyAntonio 2016-08-20 21:16:07 -03:00
parent 54eb3e89e8
commit 2f157fe2c6
4 changed files with 40 additions and 7 deletions

View File

@ -50,7 +50,6 @@ class CreateController extends Controller {
$ticket = new Ticket();
$ticket->setProperties(array(
'ticketNumber' => $ticket->generateUniqueTicketNumber(),
'title' => $this->title,
'content' => $this->content,
'language' => $this->language,

View File

@ -17,7 +17,7 @@ abstract class DataStore {
return ($bean) ? new static($bean) : new NullDataStore();
}
public static function count() {
RedBean::count(static::TABLE);
return RedBean::count(static::TABLE);
}
private static function validateProp($propToValidate) {

View File

@ -52,7 +52,7 @@ class Ticket extends DataStore {
$firstTicketNumber = Ticket::getTicket(1)->ticketNumber;
$gap = 176611;
$ticketNumber = ($firstTicketNumber - $minValue + $ticketQuantity * $gap) % $maxValue + $minValue;
$ticketNumber = ($firstTicketNumber - $minValue + $ticketQuantity * $gap) % ($maxValue - $minValue + 1) + $minValue;
}
return $ticketNumber;

View File

@ -108,8 +108,42 @@ describe '/ticket/create' do
(ticket['closed']).should.equal('0')
(ticket['department_id']).should.equal('1')
(ticket['author_id']).should.equal($csrf_userid)
(ticket['ticket_number'].size).should.equal(6)
ticket_user_relation = $database.getRow('ticket_user','1','ticket_id')
(ticket_user_relation['user_id']).should.equal($csrf_userid)
end
it 'should set correct ticket number' do
result = request('/ticket/create',{
title: 'Winter is coming1',
content: 'The north remembers',
departmentId: 1,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
result = request('/ticket/create',{
title: 'Winter is coming2',
content: 'The north remembers',
departmentId: 1,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
result = request('/ticket/create',{
title: 'Winter is coming3',
content: 'The north remembers',
departmentId: 1,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
ticket0 = $database.getRow('ticket','Winter is coming','title')['ticket_number'].to_i
ticket1 = $database.getRow('ticket','Winter is coming1','title')['ticket_number'].to_i
ticket2 = $database.getRow('ticket','Winter is coming2','title')['ticket_number'].to_i
ticket3 = $database.getRow('ticket','Winter is coming3','title')['ticket_number'].to_i
(ticket1).should.equal((ticket0 - 100000 + 1 * 176611) % 900000 + 100000)
(ticket2).should.equal((ticket0 - 100000 + 2 * 176611) % 900000 + 100000)
(ticket3).should.equal((ticket0 - 100000 + 3 * 176611) % 900000 + 100000)
end
end