Class: ODDB::TestInvoice

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
FlexMock::TestCase
Defined in:
test/test_model/invoice.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



15
16
17
# File 'test/test_model/invoice.rb', line 15

def setup
  @invoice = ODDB::Invoice.new
end

- (Object) test_create_item



18
19
20
21
22
# File 'test/test_model/invoice.rb', line 18

def test_create_item
  item = @invoice.create_item
  assert_equal(1, @invoice.items.size)
  assert_equal(item, @invoice.item(item.oid))
end

- (Object) test_deletable



67
68
69
# File 'test/test_model/invoice.rb', line 67

def test_deletable
  assert_equal(true, @invoice.deletable?)
end

- (Object) test_deletable_keep_if_unpaid



74
75
76
77
# File 'test/test_model/invoice.rb', line 74

def test_deletable_keep_if_unpaid
  @invoice.keep_if_unpaid = true
  assert_equal(false, @invoice.deletable?)
end

- (Object) test_deletable_not_expired



78
79
80
81
82
83
# File 'test/test_model/invoice.rb', line 78

def test_deletable_not_expired
  item = @invoice.create_item
  item.time = Time.now
  item.expiry_time = (Time.now + 1)
  assert_equal(false, @invoice.deletable?)
end

- (Object) test_deletable_payment_received



70
71
72
73
# File 'test/test_model/invoice.rb', line 70

def test_deletable_payment_received
  @invoice.payment_received!
  assert_equal(false, @invoice.deletable?)
end

- (Object) test_expired



47
48
49
50
51
52
53
54
55
56
57
# File 'test/test_model/invoice.rb', line 47

def test_expired
  assert_equal(true, @invoice.expired?)
  item = @invoice.create_item
  assert_equal(true, @invoice.expired?)
  item.time = Time.now
  assert_equal(true, @invoice.expired?)
  item.expiry_time = @@today - 1
  assert_equal(true, @invoice.expired?)
  item.expiry_time = @@today
  assert_equal(false, @invoice.expired?)
end

- (Object) test_expired_2_items



58
59
60
61
62
63
64
65
66
# File 'test/test_model/invoice.rb', line 58

def test_expired_2_items
  item = @invoice.create_item
  item2 = @invoice.create_item
  item.time = Time.now
  item.expiry_time = (Time.now + 1)
  assert_equal(false, item.expired?)
  assert_equal(true, item2.expired?)
  assert_equal(false, @invoice.expired?)
end

- (Object) test_init



84
85
86
87
88
89
# File 'test/test_model/invoice.rb', line 84

def test_init
  @invoice.pointer = Persistence::Pointer.new :invoice
  @invoice.init nil
  assert_equal Persistence::Pointer.new([:invoice, @invoice.oid]),
               @invoice.pointer
end

- (Object) test_item_by_text



40
41
42
43
44
45
46
# File 'test/test_model/invoice.rb', line 40

def test_item_by_text
  assert_equal(nil, @invoice.item_by_text('foo'))
  item = @invoice.create_item
  item.text = 'foo'
  assert_equal(item, @invoice.item_by_text('foo'))
  assert_equal(nil, @invoice.item_by_text('bar'))
end

- (Object) test_max_duration



90
91
92
93
94
95
96
97
98
# File 'test/test_model/invoice.rb', line 90

def test_max_duration
  @invoice.items.update 1 => flexmock(:duration => 2),
                        2 => flexmock(:duration => 4)
  assert_equal 4, @invoice.max_duration
  @invoice.items.update 3 => flexmock(:duration => 6)
  assert_equal 6, @invoice.max_duration
  @invoice.items.update 4 => flexmock(:duration => 5)
  assert_equal 6, @invoice.max_duration
end

- (Object) test_payment_received



35
36
37
38
39
# File 'test/test_model/invoice.rb', line 35

def test_payment_received
  assert_equal(false, @invoice.payment_received?)
  @invoice.payment_received!
  assert_equal(true, @invoice.payment_received?)
end

- (Object) test_total



23
24
25
26
27
28
29
30
31
32
33
34
# File 'test/test_model/invoice.rb', line 23

def test_total
  item1 = @invoice.create_item
  item1.price = 14
  item2 = @invoice.create_item
  item2.price = 12
  assert_equal(26, @invoice.total_netto)
  assert_equal(26, @invoice.total_brutto)
  item1.vat_rate = 10
  item2.vat_rate = 10
  assert_equal(26, @invoice.total_netto)
  assert_equal(28.6, @invoice.total_brutto)
end

- (Object) test_types



99
100
101
102
103
104
105
106
107
# File 'test/test_model/invoice.rb', line 99

def test_types
  @invoice.items.update 1 => flexmock(:type => :annual),
                        2 => flexmock(:type => :activation)
  assert_equal [:annual, :activation], @invoice.types
  @invoice.items.update 3 => flexmock(:type => :download)
  assert_equal [:annual, :activation, :download], @invoice.types
  @invoice.items.update 4 => flexmock(:type => :annual)
  assert_equal [:annual, :activation, :download], @invoice.types
end

- (Object) test_vat



108
109
110
111
112
113
114
# File 'test/test_model/invoice.rb', line 108

def test_vat
  @invoice.items.update 1 => flexmock(:vat => 3),
                        2 => flexmock(:vat => 5)
  assert_equal 8, @invoice.vat
  @invoice.items.update 3 => flexmock(:vat => 7)
  assert_equal 15, @invoice.vat
end