Browse Source

Build load scaffolding

master
jimi 16 years ago
committed by jimi
parent
commit
7d831b76c9
  1. 40
      app/controllers/loads_controller.rb
  2. 2
      app/helpers/loads_helper.rb
  3. 2
      app/models/load.rb
  4. 24
      app/views/loads/_form.html.erb
  5. 8
      app/views/loads/edit.html.erb
  6. 21
      app/views/loads/index.html.erb
  7. 5
      app/views/loads/new.html.erb
  8. 2
      config/routes.rb
  9. 16
      db/migrate/20090311052854_create_loads.rb
  10. 12
      db/schema.rb
  11. 13
      test/fixtures/loads.yml
  12. 49
      test/functional/loads_controller_test.rb
  13. 7
      test/unit/load_test.rb

40
app/controllers/loads_controller.rb

@ -0,0 +1,40 @@
class LoadsController < ApplicationController
def index
@loads = Load.all
end
def new
@load = Load.new
end
def create
@load = Load.new(params[:load])
if @load.save
flash[:notice] = "Successfully created load."
redirect_to loads_url
else
render :action => 'new'
end
end
def edit
@load = Load.find(params[:id])
end
def update
@load = Load.find(params[:id])
if @load.update_attributes(params[:load])
flash[:notice] = "Successfully updated load."
redirect_to loads_url
else
render :action => 'edit'
end
end
def destroy
@load = Load.find(params[:id])
@load.destroy
flash[:notice] = "Successfully destroyed load."
redirect_to loads_url
end
end

2
app/helpers/loads_helper.rb

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

2
app/models/load.rb

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

24
app/views/loads/_form.html.erb

@ -0,0 +1,24 @@
<% form_for @load do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :number %><br />
<%= f.text_field :number %>
</p>
<p>
<%= f.label :start_date %><br />
<%= f.date_select :start_date %>
</p>
<p>
<%= f.label :end_date %><br />
<%= f.date_select :end_date %>
</p>
<p>
<%= f.label :hub_in %><br />
<%= f.text_field :hub_in %>
</p>
<p>
<%= f.label :hub_out %><br />
<%= f.text_field :hub_out %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>

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

@ -0,0 +1,8 @@
<% title "Load Details" %>
<%= render :partial => 'form' %>
<p class="nav">
<%= link_to "Delete", @load, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "View List", loads_path %>
</p>

21
app/views/loads/index.html.erb

@ -0,0 +1,21 @@
<% title "Load List" %>
<table class="listing" cellspacing="0">
<tr>
<th>Number</th>
<th>Start Date</th>
<th>End Date</th>
<th>Hub In</th>
<th>Hub Out</th>
</tr>
<% for load in @loads %>
<tr class="<%= cycle("light", "dark") -%>" onclick="location.href='<%= edit_load_path(load) %>'">
<td><%=h load.number %></td>
<td><%=h load.start_date %></td>
<td><%=h load.end_date %></td>
<td><%=h load.hub_in %></td>
<td><%=h load.hub_out %></td>
</tr>
<% end %>
</table>
<p class="nav"><%= link_to "New Load", new_load_path %></p>

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

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

2
config/routes.rb

@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.resources :loads
map.resources :employees map.resources :employees
map.resources :people map.resources :people

16
db/migrate/20090311052854_create_loads.rb

@ -0,0 +1,16 @@
class CreateLoads < ActiveRecord::Migration
def self.up
create_table :loads do |t|
t.string :number
t.date :start_date
t.date :end_date
t.integer :hub_in
t.integer :hub_out
t.timestamps
end
end
def self.down
drop_table :loads
end
end

12
db/schema.rb

@ -9,7 +9,17 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20090310055631) do
ActiveRecord::Schema.define(:version => 20090311052854) do
create_table "loads", :force => true do |t|
t.string "number"
t.date "start_date"
t.date "end_date"
t.integer "hub_in"
t.integer "hub_out"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "people", :force => true do |t| create_table "people", :force => true do |t|
t.string "firstname" t.string "firstname"

13
test/fixtures/loads.yml

@ -0,0 +1,13 @@
one:
number: MyString
start_date: 2009-03-11
end_date: 2009-03-11
hub_in: 1
hub_out: 1
two:
number: MyString
start_date: 2009-03-11
end_date: 2009-03-11
hub_in: 1
hub_out: 1

49
test/functional/loads_controller_test.rb

@ -0,0 +1,49 @@
require 'test_helper'
class LoadsControllerTest < ActionController::TestCase
def test_index
get :index
assert_template 'index'
end
def test_new
get :new
assert_template 'new'
end
def test_create_invalid
Load.any_instance.stubs(:valid?).returns(false)
post :create
assert_template 'new'
end
def test_create_valid
Load.any_instance.stubs(:valid?).returns(true)
post :create
assert_redirected_to loads_url
end
def test_edit
get :edit, :id => Load.first
assert_template 'edit'
end
def test_update_invalid
Load.any_instance.stubs(:valid?).returns(false)
put :update, :id => Load.first
assert_template 'edit'
end
def test_update_valid
Load.any_instance.stubs(:valid?).returns(true)
put :update, :id => Load.first
assert_redirected_to loads_url
end
def test_destroy
load = Load.first
delete :destroy, :id => load
assert_redirected_to loads_url
assert !Load.exists?(load.id)
end
end

7
test/unit/load_test.rb

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