diff --git a/app/controllers/loads_controller.rb b/app/controllers/loads_controller.rb new file mode 100644 index 0000000..a0239a8 --- /dev/null +++ b/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 diff --git a/app/helpers/loads_helper.rb b/app/helpers/loads_helper.rb new file mode 100644 index 0000000..5ea1781 --- /dev/null +++ b/app/helpers/loads_helper.rb @@ -0,0 +1,2 @@ +module LoadsHelper +end diff --git a/app/models/load.rb b/app/models/load.rb new file mode 100644 index 0000000..5aa35ec --- /dev/null +++ b/app/models/load.rb @@ -0,0 +1,2 @@ +class Load < ActiveRecord::Base +end diff --git a/app/views/loads/_form.html.erb b/app/views/loads/_form.html.erb new file mode 100644 index 0000000..bd80e7a --- /dev/null +++ b/app/views/loads/_form.html.erb @@ -0,0 +1,24 @@ +<% form_for @load do |f| %> + <%= f.error_messages %> +

+ <%= f.label :number %>
+ <%= f.text_field :number %> +

+

+ <%= f.label :start_date %>
+ <%= f.date_select :start_date %> +

+

+ <%= f.label :end_date %>
+ <%= f.date_select :end_date %> +

+

+ <%= f.label :hub_in %>
+ <%= f.text_field :hub_in %> +

+

+ <%= f.label :hub_out %>
+ <%= f.text_field :hub_out %> +

+

<%= f.submit "Submit" %>

+<% end %> diff --git a/app/views/loads/edit.html.erb b/app/views/loads/edit.html.erb new file mode 100644 index 0000000..ceaeb01 --- /dev/null +++ b/app/views/loads/edit.html.erb @@ -0,0 +1,8 @@ +<% title "Load Details" %> + +<%= render :partial => 'form' %> + + diff --git a/app/views/loads/index.html.erb b/app/views/loads/index.html.erb new file mode 100644 index 0000000..a6348cc --- /dev/null +++ b/app/views/loads/index.html.erb @@ -0,0 +1,21 @@ +<% title "Load List" %> + + + + + + + + + <% for load in @loads %> + " onclick="location.href='<%= edit_load_path(load) %>'"> + + + + + + + <% end %> +
NumberStart DateEnd DateHub InHub Out
<%=h load.number %><%=h load.start_date %><%=h load.end_date %><%=h load.hub_in %><%=h load.hub_out %>
+ + diff --git a/app/views/loads/new.html.erb b/app/views/loads/new.html.erb new file mode 100644 index 0000000..2d86368 --- /dev/null +++ b/app/views/loads/new.html.erb @@ -0,0 +1,5 @@ +<% title "New Load" %> + +<%= render :partial => 'form' %> + + diff --git a/config/routes.rb b/config/routes.rb index 4cd8886..90c9bdb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ ActionController::Routing::Routes.draw do |map| + map.resources :loads + map.resources :employees map.resources :people diff --git a/db/migrate/20090311052854_create_loads.rb b/db/migrate/20090311052854_create_loads.rb new file mode 100644 index 0000000..5f339dd --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 996426e..93062c2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,17 @@ # # 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| t.string "firstname" diff --git a/test/fixtures/loads.yml b/test/fixtures/loads.yml new file mode 100644 index 0000000..d15769c --- /dev/null +++ b/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 diff --git a/test/functional/loads_controller_test.rb b/test/functional/loads_controller_test.rb new file mode 100644 index 0000000..7778672 --- /dev/null +++ b/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 diff --git a/test/unit/load_test.rb b/test/unit/load_test.rb new file mode 100644 index 0000000..2f74c07 --- /dev/null +++ b/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