Class: ODDB::TestLog

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

Defined Under Namespace

Classes: StubSmtp

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'test/test_util/zlog.rb', line 42

def setup
  @log = ODDB::Log.new(Date.new(1975,8,21))
  $stub_log_smtp = StubSmtp.new

  flexstub(ODDB) do |oddb|
    oddb.should_receive(:config).and_return(flexmock('config') do |conf|
      conf.should_receive(:smtp_server).and_return('smtp_server')
      conf.should_receive(:smtp_port).and_return('smtp_port')
      conf.should_receive(:smtp_domain).and_return('smtp_domain')
      conf.should_receive(:smtp_user).and_return('admin@ywesee.com')
      conf.should_receive(:smtp_pass).and_return('smtp_pass')
      conf.should_receive(:smtp_authtype).and_return('smtp_authtype')
    end)
  end
  flexstub(LogFile) do |logfile|
    logfile.should_receive(:append)
  end
end

- (Object) test_notify



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'test/test_util/zlog.rb', line 60

def test_notify
  hash = {
    :recipients =>  ['hwyss@ywesee.com'],
    :pointers => ['aPointer'],
    :report =>  ["a lengthy report.\n"]
  }
  @log.update_values(hash)
  @log.notify

  report = "From: update@oddb.org\\r\nTo: hwyss@ywesee.com\\r\nSubject: ch.ODDB.org Report - 08/1975\\r\nContent-Type: text/plain; charset=UTF-8\\r\nUser-Agent: ODDB Updater\\r\n\\r\na lengthy report.\\r\n"
  expected = [
    report.strip,
    'admin@ywesee.com',
    'hwyss@ywesee.com',
  ]
  result = $stub_log_smtp.sent
  result[0][0] = result[0][0].split("\n")[1..-1].join("\n")
  assert_equal([expected], result)
end

- (Object) test_notify_date_str



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'test/test_util/zlog.rb', line 88

def test_notify_date_str
  hash = {
    :recipients =>  ['hwyss@ywesee.com'],
    :pointers => ['aPointer'],
    :report =>  ["a lengthy report.\n"],
    :date_str =>  'Today',
  }
  @log.update_values(hash)
  @log.notify('Subject')

  report = "From: update@oddb.org\\r\nTo: hwyss@ywesee.com\\r\nSubject: ch.ODDB.org Report - Subject - Today\\r\nContent-Type: text/plain; charset=UTF-8\\r\nUser-Agent: ODDB Updater\\r\n\\r\na lengthy report.\\r\n"
  expected = [
    report.strip,
    'admin@ywesee.com',
    'hwyss@ywesee.com',
  ]
  result = $stub_log_smtp.sent
  result[0][0] = result[0][0].split("\n")[1..-1].join("\n")
  assert_equal([expected], result)
end

- (Object) test_notify_file



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'test/test_util/zlog.rb', line 117

def test_notify_file
  file = File.expand_path('data/txt/log.txt', File.dirname(__FILE__))
  hash = {
    :recipients =>  ['hwyss@ywesee.com'],
    :pointers => ['aPointer'],
    :report =>  ["a lengthy report.\n"],
    :files => { file => 'application/vnd.ms-excel' },
  }
  @log.update_values(hash)
  assert_nothing_raised {
    @log.notify
  }
end