Class: ODDB::TestDownloadInvoicer

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_plugin/download_invoicer.rb

Defined Under Namespace

Classes: FlexMock

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



16
17
18
19
# File 'test/test_plugin/download_invoicer.rb', line 16

def setup
  @app = FlexMock.new
  @plugin = DownloadInvoicer.new(@app)
end

- (Object) test_group_by_user



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'test/test_plugin/download_invoicer.rb', line 53

def test_group_by_user
  item1 = AbstractInvoiceItem.new
  item1.yus_name = 'name1' 
  item2 = AbstractInvoiceItem.new
  item2.yus_name = 'name1' 
  item3 = AbstractInvoiceItem.new
  item3.yus_name = 'name1' 
  item4 = AbstractInvoiceItem.new
  item4.yus_name = 'name2' 
  items = [item1, item2, item3, item4]
  groups = @plugin.group_by_user(items)
  group1 = groups['name1']
  group2 = groups['name2']
  assert_equal(3, group1.size)
  assert_equal([item1, item2, item3], group1)
  assert_equal([item4], group2)
end

- (Object) test_recent_items



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'test/test_plugin/download_invoicer.rb', line 20

def test_recent_items
  tmon = Date.today
  lmon = tmon << 1
  # last day of last month
  item1 = AbstractInvoiceItem.new
  item1.time = Time.local(tmon.year, tmon.month, 1) - (24*60*60)
  # first day of last month
  item2 = AbstractInvoiceItem.new
  item2.time = Time.local(lmon.year, lmon.month, 1)
  # last day of month before last
  item3 = AbstractInvoiceItem.new
  item3.time = Time.local(lmon.year, lmon.month, 1) - (24*60*60)
  # first day of this month
  item4 = AbstractInvoiceItem.new
  item4.time = Time.local(tmon.year, tmon.month, 1)
  items = {
    1 =>  item1,
    2 =>  item2,
    3 =>  item3,
    4 =>  item4,
  }
  slate = FlexMock.new
  slate.should_receive(:items).and_return {
    items
  }
  @app.should_receive(:slate).and_return { |name| 
    assert_equal(:download, name)
    slate
  }
  month = Date.today << 1
  day = Date.new(month.year, month.month, 1)
  assert_equal([item1, item2], @plugin.recent_items(day))
end