tighten up Hub and add comments
[god.git] / test / test_contact.rb
blob1d4427f22bdb62d31c188b3c342273540f97a0dc
1 require File.dirname(__FILE__) + '/helper'
3 class TestContact < Test::Unit::TestCase
4   def test_exists
5     God::Contact
6   end
7   
8   # generate
9   
10   def test_generate_should_raise_on_invalid_kind
11     assert_raise(NoSuchContactError) do
12       Contact.generate(:invalid)
13     end
14   end
15   
16   def test_generate_should_abort_on_invalid_contact
17     assert_abort do
18       Contact.generate(:invalid_contact)
19     end
20   end
21   
22   # normalize
23   
24   def test_normalize_should_accept_a_string
25     input = 'tom'
26     output = {:contacts => ['tom']}
27     assert_equal(output, Contact.normalize(input))
28   end
29   
30   def test_normalize_should_accept_an_array_of_strings
31     input = ['tom', 'kevin']
32     output = {:contacts => ['tom', 'kevin']}
33     assert_equal(output, Contact.normalize(input))
34   end
35   
36   def test_normalize_should_accept_a_hash_with_contacts_string
37     input = {:contacts => 'tom'}
38     output = {:contacts => ['tom']}
39     assert_equal(output, Contact.normalize(input))
40   end
41   
42   def test_normalize_should_accept_a_hash_with_contacts_array_of_strings
43     input = {:contacts => ['tom', 'kevin']}
44     output = {:contacts => ['tom', 'kevin']}
45     assert_equal(output, Contact.normalize(input))
46   end
47   
48   def test_normalize_should_stringify_priority
49     input = {:contacts => 'tom', :priority => 1}
50     output = {:contacts => ['tom'], :priority => '1'}
51     assert_equal(output, Contact.normalize(input))
52   end
53   
54   def test_normalize_should_stringify_category
55     input = {:contacts => 'tom', :category => :product}
56     output = {:contacts => ['tom'], :category => 'product'}
57     assert_equal(output, Contact.normalize(input))
58   end
59   
60   def test_normalize_should_raise_on_non_string_array_hash
61     input = 1
62     assert_raise ArgumentError do
63       Contact.normalize(input)
64     end
65   end
66   
67   def test_normalize_should_raise_on_non_string_array_contacts_key
68     input = {:contacts => 1}
69     assert_raise ArgumentError do
70       Contact.normalize(input)
71     end
72   end
73   
74   def test_normalize_should_raise_on_non_string_containing_array
75     input = [1]
76     assert_raise ArgumentError do
77       Contact.normalize(input)
78     end
79   end
80   
81   def test_normalize_should_raise_on_non_string_containing_array_contacts_key
82     input = {:contacts => [1]}
83     assert_raise ArgumentError do
84       Contact.normalize(input)
85     end
86   end
87   
88   def test_normalize_should_raise_on_absent_contacts_key
89     input = {}
90     assert_raise ArgumentError do
91       Contact.normalize(input)
92     end
93   end
94   
95   def test_normalize_should_raise_on_extra_keys
96     input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'}
97     assert_raise ArgumentError do
98       Contact.normalize(input)
99     end
100   end
101   
102   # notify
103   
104   def test_notify_should_be_abstract
105     assert_raise(AbstractMethodNotOverriddenError) do
106       Contact.new.notify(:a, :b, :c, :d, :e)
107     end
108   end