diff --git a/lib/ruote/dm/ticket.rb b/lib/ruote/dm/ticket.rb index 959266c..1256303 100644 --- a/lib/ruote/dm/ticket.rb +++ b/lib/ruote/dm/ticket.rb @@ -48,6 +48,11 @@ def self.draw (holder, target) ticket.save ? ticket : nil end + + def self.discard (target) + + Ticket.all(:target => target).destroy! + end end end end diff --git a/test/ut_2_ticket.rb b/test/ut_2_ticket.rb index 3c87078..406a284 100644 --- a/test/ut_2_ticket.rb +++ b/test/ut_2_ticket.rb @@ -43,6 +43,23 @@ def test_two_tickets assert_equal true, l1.consumable? end + def test_discard + + Ruote::Dm::Ticket.draw('a', 't0') + Ruote::Dm::Ticket.draw('b', 't0') + Ruote::Dm::Ticket.draw('b', 't1') + + assert_equal 3, Ruote::Dm::Ticket.all.size + + Ruote::Dm::Ticket.discard('t1') + + assert_equal 2, Ruote::Dm::Ticket.all.size + + Ruote::Dm::Ticket.discard('t0') + + assert_equal 0, Ruote::Dm::Ticket.all.size + end + def test_same_same Ruote::Dm::Ticket.draw('ticketer1', 'target')