Class: ODDB::TestSponsor

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

Defined Under Namespace

Classes: StubApp, StubLogo

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



30
31
32
33
34
35
36
37
# File 'test/test_model/sponsor.rb', line 30

def setup
  @sponsor = ODDB::.new
  @app = StubApp.new
  @file = File.expand_path('../data/sponsor/foo.gif', 
    File.dirname(__FILE__))
  @file2 = File.expand_path('../data/sponsor/bar.jpg', 
    File.dirname(__FILE__))
end

- (Object) teardown



38
39
40
41
# File 'test/test_model/sponsor.rb', line 38

def teardown
  File.delete(@file) if File.exists?(@file)
  File.delete(@file2) if File.exists?(@file2)
end

- (Object) test_adjust_types



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'test/test_model/sponsor.rb', line 42

def test_adjust_types
  values = {
    :company        =>  'ywesee',
    :sponsor_until  => Date.new(2200, 12, 31),
  }
  expected = {
    :company        =>  'company_by_name',
    :sponsor_until  => Date.new(2200, 12, 31),
  }
  assert_equal(expected, @sponsor.adjust_types(values, @app))
  values = {
    :company        =>  1,
    :sponsor_until  => '2200-1-0',
  }
  expected = {
    :company        =>  'company_by_oid',
    :sponsor_until  => nil,
  }
  assert_equal(expected, @sponsor.adjust_types(values, @app))
  values = {
    :company        =>  ODDB::Persistence::Pointer.new([:company, 1]),
    :sponsor_until  => nil,
  }
  expected = {
    :company        =>  'company_by_oid',
    :sponsor_until  => nil,
  }
  assert_equal(expected, @sponsor.adjust_types(values, @app))
  values = {
    :company        =>  nil,
    :sponsor_until  => nil,
  }
  assert_nothing_raised { @sponsor.adjust_types(values, @app) }
end

- (Object) test_company_name_robust



76
77
78
79
# File 'test/test_model/sponsor.rb', line 76

def test_company_name_robust
  assert_nil(@sponsor.company)
  assert_nothing_raised { @sponsor.company_name }
end

- (Object) test_represents



80
81
82
83
84
85
86
87
88
# File 'test/test_model/sponsor.rb', line 80

def test_represents
  comp = flexmock 'company'
  other = flexmock 'other'
  pac1 = flexmock :company => comp
  pac2 = flexmock :company => other
  @sponsor.company = comp
  assert_equal true, @sponsor.represents?(pac1)
  assert_equal false, @sponsor.represents?(pac2)
end

- (Object) test_url



89
90
91
92
93
94
95
# File 'test/test_model/sponsor.rb', line 89

def test_url
  assert_nil @sponsor.url
  @sponsor.urls = { 'fr' => 'french url', 'de' => 'german url' }
  assert_equal 'german url', @sponsor.url
  assert_equal 'french url', @sponsor.url('fr')
  assert_equal 'german url', @sponsor.url('en')
end