Browse Source

Generate person scaffolding, store tasks directory

master
jimi 16 years ago
committed by jimi
parent
commit
3ea3a07c44
  1. 44
      app/controllers/people_controller.rb
  2. 2
      app/helpers/people_helper.rb
  3. 2
      app/models/person.rb
  4. 12
      app/views/people/_form.html.erb
  5. 8
      app/views/people/edit.html.erb
  6. 19
      app/views/people/index.html.erb
  7. 5
      app/views/people/new.html.erb
  8. 16
      app/views/people/show.html.erb
  9. 2
      config/routes.rb
  10. 13
      db/migrate/20090306144503_create_people.rb
  11. 21
      db/schema.rb
  12. 0
      lib/tasks/.gitignore
  13. 7
      test/fixtures/people.yml
  14. 54
      test/functional/people_controller_test.rb
  15. 7
      test/unit/person_test.rb

44
app/controllers/people_controller.rb

@ -0,0 +1,44 @@
class PeopleController < ApplicationController
def index
@people = Person.all
end
def show
@person = Person.find(params[:id])
end
def new
@person = Person.new
end
def create
@person = Person.new(params[:person])
if @person.save
flash[:notice] = "Successfully created person."
redirect_to @person
else
render :action => 'new'
end
end
def edit
@person = Person.find(params[:id])
end
def update
@person = Person.find(params[:id])
if @person.update_attributes(params[:person])
flash[:notice] = "Successfully updated person."
redirect_to @person
else
render :action => 'edit'
end
end
def destroy
@person = Person.find(params[:id])
@person.destroy
flash[:notice] = "Successfully destroyed person."
redirect_to people_url
end
end

2
app/helpers/people_helper.rb

@ -0,0 +1,2 @@
module PeopleHelper
end

2
app/models/person.rb

@ -0,0 +1,2 @@
class Person < ActiveRecord::Base
end

12
app/views/people/_form.html.erb

@ -0,0 +1,12 @@
<% form_for @person do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :firstname %><br />
<%= f.text_field :firstname %>
</p>
<p>
<%= f.label :lastname %><br />
<%= f.text_field :lastname %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>

8
app/views/people/edit.html.erb

@ -0,0 +1,8 @@
<% title "Edit Person" %>
<%= render :partial => 'form' %>
<p>
<%= link_to "Show", @person %> |
<%= link_to "View All", people_path %>
</p>

19
app/views/people/index.html.erb

@ -0,0 +1,19 @@
<% title "People" %>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<% for person in @people %>
<tr>
<td><%=h person.firstname %></td>
<td><%=h person.lastname %></td>
<td><%= link_to "Show", person %></td>
<td><%= link_to "Edit", edit_person_path(person) %></td>
<td><%= link_to "Destroy", person, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<p><%= link_to "New Person", new_person_path %></p>

5
app/views/people/new.html.erb

@ -0,0 +1,5 @@
<% title "New Person" %>
<%= render :partial => 'form' %>
<p><%= link_to "Back to List", people_path %></p>

16
app/views/people/show.html.erb

@ -0,0 +1,16 @@
<% title "Person" %>
<p>
<strong>Firstname:</strong>
<%=h @person.firstname %>
</p>
<p>
<strong>Lastname:</strong>
<%=h @person.lastname %>
</p>
<p>
<%= link_to "Edit", edit_person_path(@person) %> |
<%= link_to "Destroy", @person, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "View All", people_path %>
</p>

2
config/routes.rb

@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.resources :people
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route: # Sample of regular route:

13
db/migrate/20090306144503_create_people.rb

@ -0,0 +1,13 @@
class CreatePeople < ActiveRecord::Migration
def self.up
create_table :people do |t|
t.string :firstname
t.string :lastname
t.timestamps
end
end
def self.down
drop_table :people
end
end

21
db/schema.rb

@ -0,0 +1,21 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20090306144503) do
create_table "people", :force => true do |t|
t.string "firstname"
t.string "lastname"
t.datetime "created_at"
t.datetime "updated_at"
end
end

0
lib/tasks/.gitignore

7
test/fixtures/people.yml

@ -0,0 +1,7 @@
one:
firstname: MyString
lastname: MyString
two:
firstname: MyString
lastname: MyString

54
test/functional/people_controller_test.rb

@ -0,0 +1,54 @@
require 'test_helper'
class PeopleControllerTest < ActionController::TestCase
def test_index
get :index
assert_template 'index'
end
def test_show
get :show, :id => Person.first
assert_template 'show'
end
def test_new
get :new
assert_template 'new'
end
def test_create_invalid
Person.any_instance.stubs(:valid?).returns(false)
post :create
assert_template 'new'
end
def test_create_valid
Person.any_instance.stubs(:valid?).returns(true)
post :create
assert_redirected_to person_url(assigns(:person))
end
def test_edit
get :edit, :id => Person.first
assert_template 'edit'
end
def test_update_invalid
Person.any_instance.stubs(:valid?).returns(false)
put :update, :id => Person.first
assert_template 'edit'
end
def test_update_valid
Person.any_instance.stubs(:valid?).returns(true)
put :update, :id => Person.first
assert_redirected_to person_url(assigns(:person))
end
def test_destroy
person = Person.first
delete :destroy, :id => person
assert_redirected_to people_url
assert !Person.exists?(person.id)
end
end

7
test/unit/person_test.rb

@ -0,0 +1,7 @@
require 'test_helper'
class PersonTest < ActiveSupport::TestCase
def test_should_be_valid
assert Person.new.valid?
end
end