forked from bryanlarsen/agility-gitorial-patches
-
Notifications
You must be signed in to change notification settings - Fork 1
/
04-interface-first-hobo-style.patch
428 lines (410 loc) · 12.4 KB
/
04-interface-first-hobo-style.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
interface-first-hobo-style
From: Ignacio Huerta <[email protected]>
## Interface first Hobo style
The next thing we're going to do is sketch out our models. If you're a fully signed up devotee of the Rails Way, that should ring a few alarm bells. What happened to [interface first](http://gettingreal.37signals.com/ch09_Interface_First.php)? We do believe in Interface First. Absolutely. But for Hobos, interface first means first priority, not first task.
The reason is, we think we've rewritten this rule:
> Design is relatively light. A paper sketch is cheap and easy to change. html designs are still relatively simple to modify (or throw out). That's not true of programming. Designing first keeps you flexible. Programming first fences you in and sets you up for additional costs.
In our experience, experimenting with an app by actually building a prototype with Hobo, is actually quicker than creating html designs. How's that for getting real? We could waffle for a good while on this point, but that's probably best saved for a blog post. For now let's dive in and get this app running.
# The models
Let's review what we want this app to do:
* Track multiple projects
* Each having a collection of stories
* Stories are just a brief chunk of text
* A story can be assigned a current status and a set of outstanding tasks
* Tasks can be assigned to users
* Users can get an easy heads up of the tasks they are assigned to
Sounds to me like we just sketched a first-cut of our models. We'll start with:
* `Project` (with a name)
has many stories
* `Story` (with a title, description and status)
belongs to a project
has many tasks
* `Task` (with a description)
belongs to a story
has many users (through task-assignments)
* `User` (we'll stick with the standard fields provided by Hobo)
has many tasks (through task-assignments)
Hopefully the connection between the goal and those models is clear. If not, you'll probably find it gets easier once you've done it a few times. Before long you'll be throwing models into your app without even stopping to write the names down. Of course -- chances are you've got something wrong, made a bad decision. So? Just throw them away and create some new ones when the time comes. We're sketching here!
Here's how we create these with a Hobo generator:
$ hobo generate resource project name:string
$ hobo generate resource story title:string body:text status:string
$ hobo generate resource task description:string
Task assignments are just a back-end model. They don't need a controller, so:
$ hobo generate model task_assignment
---
app/controllers/projects_controller.rb | 7 ++++++
app/controllers/stories_controller.rb | 7 ++++++
app/controllers/tasks_controller.rb | 7 ++++++
app/models/project.rb | 29 +++++++++++++++++++++++++
app/models/story.rb | 31 +++++++++++++++++++++++++++
app/models/task.rb | 29 +++++++++++++++++++++++++
app/models/task_assignment.rb | 28 ++++++++++++++++++++++++
test/fixtures/projects.yml | 11 ++++++++++
test/fixtures/stories.yml | 11 ++++++++++
test/fixtures/task_assignments.yml | 11 ++++++++++
test/fixtures/tasks.yml | 11 ++++++++++
test/functional/projects_controller_test.rb | 7 ++++++
test/functional/stories_controller_test.rb | 7 ++++++
test/functional/tasks_controller_test.rb | 7 ++++++
test/unit/project_test.rb | 7 ++++++
test/unit/story_test.rb | 7 ++++++
test/unit/task_assignment_test.rb | 7 ++++++
test/unit/task_test.rb | 7 ++++++
18 files changed, 231 insertions(+)
create mode 100644 app/controllers/projects_controller.rb
create mode 100644 app/controllers/stories_controller.rb
create mode 100644 app/controllers/tasks_controller.rb
create mode 100644 app/models/project.rb
create mode 100644 app/models/story.rb
create mode 100644 app/models/task.rb
create mode 100644 app/models/task_assignment.rb
create mode 100644 test/fixtures/projects.yml
create mode 100644 test/fixtures/stories.yml
create mode 100644 test/fixtures/task_assignments.yml
create mode 100644 test/fixtures/tasks.yml
create mode 100644 test/functional/projects_controller_test.rb
create mode 100644 test/functional/stories_controller_test.rb
create mode 100644 test/functional/tasks_controller_test.rb
create mode 100644 test/unit/project_test.rb
create mode 100644 test/unit/story_test.rb
create mode 100644 test/unit/task_assignment_test.rb
create mode 100644 test/unit/task_test.rb
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
new file mode 100644
index 0000000..210b07d
--- /dev/null
+++ b/app/controllers/projects_controller.rb
@@ -0,0 +1,7 @@
+class ProjectsController < ApplicationController
+
+ hobo_model_controller
+
+ auto_actions :all
+
+end
diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb
new file mode 100644
index 0000000..f0dd368
--- /dev/null
+++ b/app/controllers/stories_controller.rb
@@ -0,0 +1,7 @@
+class StoriesController < ApplicationController
+
+ hobo_model_controller
+
+ auto_actions :all
+
+end
diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb
new file mode 100644
index 0000000..f5a4f00
--- /dev/null
+++ b/app/controllers/tasks_controller.rb
@@ -0,0 +1,7 @@
+class TasksController < ApplicationController
+
+ hobo_model_controller
+
+ auto_actions :all
+
+end
diff --git a/app/models/project.rb b/app/models/project.rb
new file mode 100644
index 0000000..a05a01f
--- /dev/null
+++ b/app/models/project.rb
@@ -0,0 +1,29 @@
+class Project < ActiveRecord::Base
+
+ hobo_model # Don't put anything above this
+
+ fields do
+ name :string
+ timestamps
+ end
+ attr_accessible :name
+
+ # --- Permissions --- #
+
+ def create_permitted?
+ acting_user.administrator?
+ end
+
+ def update_permitted?
+ acting_user.administrator?
+ end
+
+ def destroy_permitted?
+ acting_user.administrator?
+ end
+
+ def view_permitted?(field)
+ true
+ end
+
+end
diff --git a/app/models/story.rb b/app/models/story.rb
new file mode 100644
index 0000000..ab1e10c
--- /dev/null
+++ b/app/models/story.rb
@@ -0,0 +1,31 @@
+class Story < ActiveRecord::Base
+
+ hobo_model # Don't put anything above this
+
+ fields do
+ title :string
+ body :text
+ status :string
+ timestamps
+ end
+ attr_accessible :title, :body, :status
+
+ # --- Permissions --- #
+
+ def create_permitted?
+ acting_user.administrator?
+ end
+
+ def update_permitted?
+ acting_user.administrator?
+ end
+
+ def destroy_permitted?
+ acting_user.administrator?
+ end
+
+ def view_permitted?(field)
+ true
+ end
+
+end
diff --git a/app/models/task.rb b/app/models/task.rb
new file mode 100644
index 0000000..4e9376e
--- /dev/null
+++ b/app/models/task.rb
@@ -0,0 +1,29 @@
+class Task < ActiveRecord::Base
+
+ hobo_model # Don't put anything above this
+
+ fields do
+ description :string
+ timestamps
+ end
+ attr_accessible :description
+
+ # --- Permissions --- #
+
+ def create_permitted?
+ acting_user.administrator?
+ end
+
+ def update_permitted?
+ acting_user.administrator?
+ end
+
+ def destroy_permitted?
+ acting_user.administrator?
+ end
+
+ def view_permitted?(field)
+ true
+ end
+
+end
diff --git a/app/models/task_assignment.rb b/app/models/task_assignment.rb
new file mode 100644
index 0000000..8536a45
--- /dev/null
+++ b/app/models/task_assignment.rb
@@ -0,0 +1,28 @@
+class TaskAssignment < ActiveRecord::Base
+
+ hobo_model # Don't put anything above this
+
+ fields do
+ timestamps
+ end
+ attr_accessible
+
+ # --- Permissions --- #
+
+ def create_permitted?
+ acting_user.administrator?
+ end
+
+ def update_permitted?
+ acting_user.administrator?
+ end
+
+ def destroy_permitted?
+ acting_user.administrator?
+ end
+
+ def view_permitted?(field)
+ true
+ end
+
+end
diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml
new file mode 100644
index 0000000..c63aac0
--- /dev/null
+++ b/test/fixtures/projects.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
diff --git a/test/fixtures/stories.yml b/test/fixtures/stories.yml
new file mode 100644
index 0000000..c63aac0
--- /dev/null
+++ b/test/fixtures/stories.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
diff --git a/test/fixtures/task_assignments.yml b/test/fixtures/task_assignments.yml
new file mode 100644
index 0000000..c63aac0
--- /dev/null
+++ b/test/fixtures/task_assignments.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
diff --git a/test/fixtures/tasks.yml b/test/fixtures/tasks.yml
new file mode 100644
index 0000000..c63aac0
--- /dev/null
+++ b/test/fixtures/tasks.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
new file mode 100644
index 0000000..c098166
--- /dev/null
+++ b/test/functional/projects_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ProjectsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/functional/stories_controller_test.rb b/test/functional/stories_controller_test.rb
new file mode 100644
index 0000000..8974eb3
--- /dev/null
+++ b/test/functional/stories_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class StoriesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb
new file mode 100644
index 0000000..ab48b11
--- /dev/null
+++ b/test/functional/tasks_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class TasksControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
new file mode 100644
index 0000000..0821e1f
--- /dev/null
+++ b/test/unit/project_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ProjectTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/story_test.rb b/test/unit/story_test.rb
new file mode 100644
index 0000000..30d14dd
--- /dev/null
+++ b/test/unit/story_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class StoryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/task_assignment_test.rb b/test/unit/task_assignment_test.rb
new file mode 100644
index 0000000..19da271
--- /dev/null
+++ b/test/unit/task_assignment_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class TaskAssignmentTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb
new file mode 100644
index 0000000..3ca2159
--- /dev/null
+++ b/test/unit/task_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class TaskTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end