Skip to content

Commit

Permalink
generate-initial-models
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
bryanlarsen committed Dec 1, 2009
1 parent d15ee01 commit 67831c7
Show file tree
Hide file tree
Showing 25 changed files with 252 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/projects_controller.rb
@@ -0,0 +1,7 @@
class ProjectsController < ApplicationController

hobo_model_controller

auto_actions :all

end
7 changes: 7 additions & 0 deletions app/controllers/stories_controller.rb
@@ -0,0 +1,7 @@
class StoriesController < ApplicationController

hobo_model_controller

auto_actions :all

end
7 changes: 7 additions & 0 deletions app/controllers/tasks_controller.rb
@@ -0,0 +1,7 @@
class TasksController < ApplicationController

hobo_model_controller

auto_actions :all

end
2 changes: 2 additions & 0 deletions app/helpers/projects_helper.rb
@@ -0,0 +1,2 @@
module ProjectsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/stories_helper.rb
@@ -0,0 +1,2 @@
module StoriesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/tasks_helper.rb
@@ -0,0 +1,2 @@
module TasksHelper
end
29 changes: 29 additions & 0 deletions 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
31 changes: 31 additions & 0 deletions 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
29 changes: 29 additions & 0 deletions 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
28 changes: 28 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
6 changes: 6 additions & 0 deletions 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
6 changes: 6 additions & 0 deletions 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
6 changes: 6 additions & 0 deletions 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
6 changes: 6 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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

0 comments on commit 67831c7

Please sign in to comment.