Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 194 lines (159 sloc) 6.193 kb
af933350 »
2011-11-23 Fixed bug when assignments YAML file is missing.
1 require "test_helper"
2
3 class AssignmentsGivenNonExistentYamlFile < Test::Unit::TestCase
4 def setup
5 FileUtils.rm(store_path) if File.exist?(store_path)
6 @assignments = Harmonia::Assignments.new(store_path)
7 end
8
9 def test_should_return_an_empty_list_of_people
10 assert_equal [], @assignments.people
11 end
12
13 def test_should_return_an_empty_list_of_tasks
14 assert_equal [], @assignments.tasks
15 end
16 end
17
18 class AssignmentsGivenEmptyYamlFile < Test::Unit::TestCase
19 def setup
20 File.open(store_path, "w") { |file| file.write("") }
21 @assignments = Harmonia::Assignments.new(store_path)
22 end
23
24 def test_should_return_an_empty_list_of_people
25 assert_equal [], @assignments.people
26 end
27
28 def test_should_return_an_empty_list_of_tasks
29 assert_equal [], @assignments.tasks
30 end
31 end
32
33 class AssignmentsWithNoneExistingTest < Test::Unit::TestCase
34 def setup
35 File.open(store_path, "w") { |file| file.puts({}.to_yaml) }
36 @assignments = Harmonia::Assignments.new(store_path)
37 end
38
39 def test_should_return_an_empty_list_of_people
40 assert_equal [], @assignments.people
41 end
42
43 def test_should_return_an_empty_list_of_tasks
44 assert_equal [], @assignments.tasks
45 end
46
47 def test_should_allow_assigning_a_new_person_to_a_new_task
48 @assignments.assign(:payroll, "James M")
49 assert_equal "James M", @assignments.assigned_to(:payroll)
50 end
51
52 def test_should_ignore_removal_of_non_existent_assignment
53 @assignments.unassign(:not_existing_task)
54 assert_equal [], @assignments.people
55 assert_equal [], @assignments.tasks
56 end
57
58 def test_should_return_an_empty_set_when_asking_for_the_tasks_assigned_to_a_person
59 assert_equal [], @assignments.tasks_assigned_to("James A")
60 end
61 end
62
63 class AssignmentsGivenExistingYamlFile < Test::Unit::TestCase
64 def setup
65 task_assignments = {
66 invoices: "Chris",
67 weeknotes: "Tom"
68 }
69 File.open(store_path, "w") { |file| file.puts(task_assignments.to_yaml) }
70 @assignments = Harmonia::Assignments.new(store_path)
71 end
72
73 def test_should_return_the_list_of_people
74 assert_equal ["Chris", "Tom"], @assignments.people
75 end
76
77 def test_should_return_the_list_of_tasks
78 assert_equal [:invoices, :weeknotes], @assignments.tasks
79 end
80
81 def test_should_return_the_current_person_assigned_to_a_task
82 assert_equal "Chris", @assignments.assigned_to(:invoices)
83 assert_equal "Tom", @assignments.assigned_to(:weeknotes)
84 end
85
86 def test_should_return_the_set_of_tasks_when_asking_for_the_tasks_assigned_to_a_person
87 assert_equal [:invoices], @assignments.tasks_assigned_to("Chris")
88 assert_equal [:weeknotes], @assignments.tasks_assigned_to("Tom")
89 end
90 end
91
92 class AssignmentsPreservingState < Test::Unit::TestCase
93 def setup
94 task_assignments = {
95 weeknotes: "Tom"
96 }
97 File.open(store_path, "w") { |file| file.puts(task_assignments.to_yaml) }
98 @assignments = Harmonia::Assignments.new(store_path)
99 end
100
101 def test_should_preserve_assignments
102 @assignments.assign(:payroll, "James A")
103 reloaded_assignments = Harmonia::Assignments.new(store_path)
104 assert_equal "James A", reloaded_assignments.assigned_to(:payroll)
105 end
106
107 def test_should_preserve_unassignments
108 @assignments.unassign(:weeknotes)
109 reloaded_assignments = Harmonia::Assignments.new(store_path)
110 assert_equal [], reloaded_assignments.tasks_assigned_to("Tom")
111 end
112
113 def test_should_preserve_unassigning_all_assignments
114 @assignments.unassign_all
115 reloaded_assignments = Harmonia::Assignments.new(store_path)
116 assert_equal [], reloaded_assignments.people
117 assert_equal [], reloaded_assignments.tasks
118 end
119 end
120
121 class AssignmentsTest < Test::Unit::TestCase
122 def setup
123 File.open(store_path, "w") { |file| file.puts({}.to_yaml) }
124 @assignments = Harmonia::Assignments.new(store_path)
125 @assignments.assign(:invoices, "Chris")
126 @assignments.assign(:weeknotes, "Tom")
127 end
128
129 def test_should_return_the_list_of_people
130 assert_equal ["Chris", "Tom"], @assignments.people
131 end
132
133 def test_should_return_the_list_of_tasks
134 assert_equal [:invoices, :weeknotes], @assignments.tasks
135 end
136
137 def test_should_return_the_current_person_assigned_to_a_task
138 assert_equal "Chris", @assignments.assigned_to(:invoices)
139 end
140
141 def test_should_return_the_set_of_tasks_when_asking_for_the_tasks_assigned_to_a_person
142 assert_equal [:invoices], @assignments.tasks_assigned_to("Chris")
143 end
144
145 def test_should_allow_a_new_person_to_be_assigned_to_an_existing_task
146 @assignments.assign(:invoices, "James A")
147 assert_equal "James A", @assignments.assigned_to(:invoices)
148 assert_equal [:invoices], @assignments.tasks_assigned_to("James A")
149 end
150
151 def test_should_allow_a_new_person_to_be_assigned_to_a_new_task
152 @assignments.assign(:vat_return, "Jase")
153 assert_equal "Jase", @assignments.assigned_to(:vat_return)
154 assert_equal [:vat_return], @assignments.tasks_assigned_to("Jase")
155 end
156
157 def test_should_allow_the_removal_of_an_assignment
158 @assignments.unassign(:invoices)
159 assert_equal ["Tom"], @assignments.people
160 assert_equal [:weeknotes], @assignments.tasks
161 end
162
163 def test_should_allow_all_assignments_to_be_cleared
164 @assignments.unassign_all
165 assert_equal [], @assignments.people
166 assert_equal [], @assignments.tasks
167 end
168 end
169
170 class AssignmentsWithOnePersonAssignedToManyTasks < Test::Unit::TestCase
171 def setup
172 File.open(store_path, "w") { |file| file.puts({}.to_yaml) }
173 @assignments = Harmonia::Assignments.new(store_path)
174 @assignments.assign(:cleaning, "Chris")
175 @assignments.assign(:recycling, "Chris")
176 end
177
178 def test_should_return_the_list_of_people
179 assert_equal ["Chris"], @assignments.people
180 end
181
182 def test_should_return_the_list_of_tasks
183 assert_equal [:cleaning, :recycling], @assignments.tasks
184 end
185
186 def test_should_return_the_current_person_assigned_to_a_task
187 assert_equal "Chris", @assignments.assigned_to(:cleaning)
188 assert_equal "Chris", @assignments.assigned_to(:recycling)
189 end
190
191 def test_should_return_the_set_of_tasks_when_asking_for_the_tasks_assigned_to_a_person
192 assert_equal [:cleaning, :recycling], @assignments.tasks_assigned_to("Chris")
193 end
194 end
Something went wrong with that request. Please try again.