-
Notifications
You must be signed in to change notification settings - Fork 2
/
08-generate-initial-models.patch
496 lines (482 loc) · 13.9 KB
/
08-generate-initial-models.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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
generate-initial-models
From: Bryan Larsen <[email protected]>
# 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:
$ ./script/generate hobo_model_resource project name:string
$ ./script/generate hobo_model_resource story title:string body:text status:string
$ ./script/generate hobo_model_resource task description:string
Task assignments are just a back-end model. They don't need a controller, so:
$ ./script/generate hobo_model task_assignment
---
app/controllers/projects_controller.rb | 7 ++++++
app/controllers/stories_controller.rb | 7 ++++++
app/controllers/tasks_controller.rb | 7 ++++++
app/helpers/projects_helper.rb | 2 ++
app/helpers/stories_helper.rb | 2 ++
app/helpers/tasks_helper.rb | 2 ++
app/models/project.rb | 29 +++++++++++++++++++++++++
app/models/story.rb | 31 +++++++++++++++++++++++++++
app/models/task.rb | 29 +++++++++++++++++++++++++
app/models/task_assignment.rb | 28 ++++++++++++++++++++++++
app/viewhints/project_hints.rb | 7 ++++++
app/viewhints/story_hints.rb | 7 ++++++
app/viewhints/task_assignment_hints.rb | 7 ++++++
app/viewhints/task_hints.rb | 7 ++++++
test/fixtures/projects.yml | 6 +++++
test/fixtures/stories.yml | 6 +++++
test/fixtures/task_assignments.yml | 6 +++++
test/fixtures/tasks.yml | 6 +++++
test/functional/projects_controller_test.rb | 8 +++++++
test/functional/stories_controller_test.rb | 8 +++++++
test/functional/tasks_controller_test.rb | 8 +++++++
test/unit/project_test.rb | 8 +++++++
test/unit/story_test.rb | 8 +++++++
test/unit/task_assignment_test.rb | 8 +++++++
test/unit/task_test.rb | 8 +++++++
25 files changed, 252 insertions(+), 0 deletions(-)
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/helpers/projects_helper.rb
create mode 100644 app/helpers/stories_helper.rb
create mode 100644 app/helpers/tasks_helper.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 app/viewhints/project_hints.rb
create mode 100644 app/viewhints/story_hints.rb
create mode 100644 app/viewhints/task_assignment_hints.rb
create mode 100644 app/viewhints/task_hints.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/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
new file mode 100644
index 0000000..db5c5ce
--- /dev/null
+++ b/app/helpers/projects_helper.rb
@@ -0,0 +1,2 @@
+module ProjectsHelper
+end
diff --git a/app/helpers/stories_helper.rb b/app/helpers/stories_helper.rb
new file mode 100644
index 0000000..43e5cd8
--- /dev/null
+++ b/app/helpers/stories_helper.rb
@@ -0,0 +1,2 @@
+module StoriesHelper
+end
diff --git a/app/helpers/tasks_helper.rb b/app/helpers/tasks_helper.rb
new file mode 100644
index 0000000..ce894d0
--- /dev/null
+++ b/app/helpers/tasks_helper.rb
@@ -0,0 +1,2 @@
+module TasksHelper
+end
diff --git a/app/models/project.rb b/app/models/project.rb
new file mode 100644
index 0000000..7dc4ebc
--- /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
+
+
+ # --- 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..7f2e550
--- /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
+
+
+ # --- 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..23479ba
--- /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
+
+
+ # --- 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..486f72f
--- /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
+
+
+ # --- 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/viewhints/project_hints.rb b/app/viewhints/project_hints.rb
new file mode 100644
index 0000000..1f0eb6f
--- /dev/null
+++ b/app/viewhints/project_hints.rb
@@ -0,0 +1,7 @@
+class ProjectHints < Hobo::ViewHints
+
+ # model_name "My Model"
+ # field_names :field1 => "First Field", :field2 => "Second Field"
+ # field_help :field1 => "Enter what you want in this field"
+ # children :primary_collection1, :aside_collection1, :aside_collection2
+end
diff --git a/app/viewhints/story_hints.rb b/app/viewhints/story_hints.rb
new file mode 100644
index 0000000..831007f
--- /dev/null
+++ b/app/viewhints/story_hints.rb
@@ -0,0 +1,7 @@
+class StoryHints < Hobo::ViewHints
+
+ # model_name "My Model"
+ # field_names :field1 => "First Field", :field2 => "Second Field"
+ # field_help :field1 => "Enter what you want in this field"
+ # children :primary_collection1, :aside_collection1, :aside_collection2
+end
diff --git a/app/viewhints/task_assignment_hints.rb b/app/viewhints/task_assignment_hints.rb
new file mode 100644
index 0000000..b3bed88
--- /dev/null
+++ b/app/viewhints/task_assignment_hints.rb
@@ -0,0 +1,7 @@
+class TaskAssignmentHints < Hobo::ViewHints
+
+ # model_name "My Model"
+ # field_names :field1 => "First Field", :field2 => "Second Field"
+ # field_help :field1 => "Enter what you want in this field"
+ # children :primary_collection1, :aside_collection1, :aside_collection2
+end
diff --git a/app/viewhints/task_hints.rb b/app/viewhints/task_hints.rb
new file mode 100644
index 0000000..e14fcdb
--- /dev/null
+++ b/app/viewhints/task_hints.rb
@@ -0,0 +1,7 @@
+class TaskHints < Hobo::ViewHints
+
+ # model_name "My Model"
+ # field_names :field1 => "First Field", :field2 => "Second Field"
+ # field_help :field1 => "Enter what you want in this field"
+ # children :primary_collection1, :aside_collection1, :aside_collection2
+end
diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml
new file mode 100644
index 0000000..5f81936
--- /dev/null
+++ b/test/fixtures/projects.yml
@@ -0,0 +1,6 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+
+two:
+ id: 2
diff --git a/test/fixtures/stories.yml b/test/fixtures/stories.yml
new file mode 100644
index 0000000..5f81936
--- /dev/null
+++ b/test/fixtures/stories.yml
@@ -0,0 +1,6 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+
+two:
+ id: 2
diff --git a/test/fixtures/task_assignments.yml b/test/fixtures/task_assignments.yml
new file mode 100644
index 0000000..5f81936
--- /dev/null
+++ b/test/fixtures/task_assignments.yml
@@ -0,0 +1,6 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+
+two:
+ id: 2
diff --git a/test/fixtures/tasks.yml b/test/fixtures/tasks.yml
new file mode 100644
index 0000000..5f81936
--- /dev/null
+++ b/test/fixtures/tasks.yml
@@ -0,0 +1,6 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+
+two:
+ id: 2
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
new file mode 100644
index 0000000..ee86e9b
--- /dev/null
+++ b/test/functional/projects_controller_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ProjectsControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ 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..c7fcf3a
--- /dev/null
+++ b/test/functional/stories_controller_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class StoriesControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ 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..933b816
--- /dev/null
+++ b/test/functional/tasks_controller_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TasksControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
new file mode 100644
index 0000000..069f7c1
--- /dev/null
+++ b/test/unit/project_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ProjectTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/test/unit/story_test.rb b/test/unit/story_test.rb
new file mode 100644
index 0000000..b9b6958
--- /dev/null
+++ b/test/unit/story_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class StoryTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ 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..ece01da
--- /dev/null
+++ b/test/unit/task_assignment_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TaskAssignmentTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb
new file mode 100644
index 0000000..b524127
--- /dev/null
+++ b/test/unit/task_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TaskTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end