Skip to content

Commit

Permalink
Controller scaffold for Process Unit
Browse files Browse the repository at this point in the history
  • Loading branch information
alachaum committed Mar 19, 2011
1 parent d4985a2 commit 21304c6
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 1 deletion.
81 changes: 81 additions & 0 deletions app/controllers/process_units_controller.rb
@@ -1,2 +1,83 @@
class ProcessUnitsController < ApplicationController
# GET /process_units
# GET /process_units.xml
def index
@process_units = ProcessUnit.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @process_units }
end
end

# GET /process_units/1
# GET /process_units/1.xml
def show
@process_unit = ProcessUnit.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @process_unit }
end
end

# GET /process_units/new
# GET /process_units/new.xml
def new
@process_unit = ProcessUnit.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @process_unit }
end
end

# GET /process_units/1/edit
def edit
@process_unit = ProcessUnit.find(params[:id])
end

# POST /process_units
# POST /process_units.xml
def create
@process_unit = ProcessUnit.new(params[:process_unit])

respond_to do |format|
if @process_unit.save
format.html { redirect_to(@process_unit, :notice => 'Process unit was successfully created.') }
format.xml { render :xml => @process_unit, :status => :created, :location => @process_unit }
else
format.html { render :action => "new" }
format.xml { render :xml => @process_unit.errors, :status => :unprocessable_entity }
end
end
end

# PUT /process_units/1
# PUT /process_units/1.xml
def update
@process_unit = ProcessUnit.find(params[:id])

respond_to do |format|
if @process_unit.update_attributes(params[:process_unit])
format.html { redirect_to(@process_unit, :notice => 'Process unit was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @process_unit.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /process_units/1
# DELETE /process_units/1.xml
def destroy
@process_unit = ProcessUnit.find(params[:id])
@process_unit.destroy

respond_to do |format|
format.html { redirect_to(process_units_url) }
format.xml { head :ok }
end
end
end
17 changes: 17 additions & 0 deletions app/views/process_units/_form.html.erb
@@ -0,0 +1,17 @@
<%= form_for(@process_unit) do |f| %>
<% if @process_unit.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@process_unit.errors.count, "error") %> prohibited this process_unit from being saved:</h2>

<ul>
<% @process_unit.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/process_units/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing process_unit</h1>

<%= render 'form' %>
<%= link_to 'Show', @process_unit %> |
<%= link_to 'Back', process_units_path %>
21 changes: 21 additions & 0 deletions app/views/process_units/index.html.erb
@@ -0,0 +1,21 @@
<h1>Listing process_units</h1>

<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>

<% @process_units.each do |process_unit| %>
<tr>
<td><%= link_to 'Show', process_unit %></td>
<td><%= link_to 'Edit', edit_process_unit_path(process_unit) %></td>
<td><%= link_to 'Destroy', process_unit, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Process unit', new_process_unit_path %>
5 changes: 5 additions & 0 deletions app/views/process_units/new.html.erb
@@ -0,0 +1,5 @@
<h1>New process_unit</h1>

<%= render 'form' %>
<%= link_to 'Back', process_units_path %>
5 changes: 5 additions & 0 deletions app/views/process_units/show.html.erb
@@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>


<%= link_to 'Edit', edit_process_unit_path(@process_unit) %> |
<%= link_to 'Back', process_units_path %>
3 changes: 2 additions & 1 deletion config/routes.rb
@@ -1,7 +1,8 @@
Switcher::Application.routes.draw do
resources :process_units


resources :process_flows
resources :process_units

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
120 changes: 120 additions & 0 deletions spec/controllers/process_units_controller_spec.rb
@@ -1,5 +1,125 @@
require 'spec_helper'

# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by the Rails when you ran the scaffold generator.

describe ProcessUnitsController do

def mock_process_unit(stubs={})
@mock_process_unit ||= mock_model(ProcessUnit, stubs).as_null_object
end

describe "GET index" do
it "assigns all process_units as @process_units" do
ProcessUnit.stub(:all) { [mock_process_unit] }
get :index
assigns(:process_units).should eq([mock_process_unit])
end
end

describe "GET show" do
it "assigns the requested process_unit as @process_unit" do
ProcessUnit.stub(:find).with("37") { mock_process_unit }
get :show, :id => "37"
assigns(:process_unit).should be(mock_process_unit)
end
end

describe "GET new" do
it "assigns a new process_unit as @process_unit" do
ProcessUnit.stub(:new) { mock_process_unit }
get :new
assigns(:process_unit).should be(mock_process_unit)
end
end

describe "GET edit" do
it "assigns the requested process_unit as @process_unit" do
ProcessUnit.stub(:find).with("37") { mock_process_unit }
get :edit, :id => "37"
assigns(:process_unit).should be(mock_process_unit)
end
end

describe "POST create" do
describe "with valid params" do
it "assigns a newly created process_unit as @process_unit" do
ProcessUnit.stub(:new).with({'these' => 'params'}) { mock_process_unit(:save => true) }
post :create, :process_unit => {'these' => 'params'}
assigns(:process_unit).should be(mock_process_unit)
end

it "redirects to the created process_unit" do
ProcessUnit.stub(:new) { mock_process_unit(:save => true) }
post :create, :process_unit => {}
response.should redirect_to(process_unit_url(mock_process_unit))
end
end

describe "with invalid params" do
it "assigns a newly created but unsaved process_unit as @process_unit" do
ProcessUnit.stub(:new).with({'these' => 'params'}) { mock_process_unit(:save => false) }
post :create, :process_unit => {'these' => 'params'}
assigns(:process_unit).should be(mock_process_unit)
end

it "re-renders the 'new' template" do
ProcessUnit.stub(:new) { mock_process_unit(:save => false) }
post :create, :process_unit => {}
response.should render_template("new")
end
end
end

describe "PUT update" do
describe "with valid params" do
it "updates the requested process_unit" do
ProcessUnit.stub(:find).with("37") { mock_process_unit }
mock_process_unit.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :process_unit => {'these' => 'params'}
end

it "assigns the requested process_unit as @process_unit" do
ProcessUnit.stub(:find) { mock_process_unit(:update_attributes => true) }
put :update, :id => "1"
assigns(:process_unit).should be(mock_process_unit)
end

it "redirects to the process_unit" do
ProcessUnit.stub(:find) { mock_process_unit(:update_attributes => true) }
put :update, :id => "1"
response.should redirect_to(process_unit_url(mock_process_unit))
end
end

describe "with invalid params" do
it "assigns the process_unit as @process_unit" do
ProcessUnit.stub(:find) { mock_process_unit(:update_attributes => false) }
put :update, :id => "1"
assigns(:process_unit).should be(mock_process_unit)
end

it "re-renders the 'edit' template" do
ProcessUnit.stub(:find) { mock_process_unit(:update_attributes => false) }
put :update, :id => "1"
response.should render_template("edit")
end
end
end

describe "DELETE destroy" do
it "destroys the requested process_unit" do
ProcessUnit.stub(:find).with("37") { mock_process_unit }
mock_process_unit.should_receive(:destroy)
delete :destroy, :id => "37"
end

it "redirects to the process_units list" do
ProcessUnit.stub(:find) { mock_process_unit }
delete :destroy, :id => "1"
response.should redirect_to(process_units_url)
end
end

end
11 changes: 11 additions & 0 deletions spec/requests/process_units_spec.rb
@@ -0,0 +1,11 @@
require 'spec_helper'

describe "ProcessUnits" do
describe "GET /process_units" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get process_units_path
response.status.should be(200)
end
end
end
35 changes: 35 additions & 0 deletions spec/routing/process_units_routing_spec.rb
@@ -0,0 +1,35 @@
require "spec_helper"

describe ProcessUnitsController do
describe "routing" do

it "recognizes and generates #index" do
{ :get => "/process_units" }.should route_to(:controller => "process_units", :action => "index")
end

it "recognizes and generates #new" do
{ :get => "/process_units/new" }.should route_to(:controller => "process_units", :action => "new")
end

it "recognizes and generates #show" do
{ :get => "/process_units/1" }.should route_to(:controller => "process_units", :action => "show", :id => "1")
end

it "recognizes and generates #edit" do
{ :get => "/process_units/1/edit" }.should route_to(:controller => "process_units", :action => "edit", :id => "1")
end

it "recognizes and generates #create" do
{ :post => "/process_units" }.should route_to(:controller => "process_units", :action => "create")
end

it "recognizes and generates #update" do
{ :put => "/process_units/1" }.should route_to(:controller => "process_units", :action => "update", :id => "1")
end

it "recognizes and generates #destroy" do
{ :delete => "/process_units/1" }.should route_to(:controller => "process_units", :action => "destroy", :id => "1")
end

end
end
15 changes: 15 additions & 0 deletions spec/views/process_units/edit.html.erb_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

describe "process_units/edit.html.erb" do
before(:each) do
@process_unit = assign(:process_unit, stub_model(ProcessUnit))
end

it "renders the edit process_unit form" do
render

# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => process_unit_path(@process_unit), :method => "post" do
end
end
end
14 changes: 14 additions & 0 deletions spec/views/process_units/index.html.erb_spec.rb
@@ -0,0 +1,14 @@
require 'spec_helper'

describe "process_units/index.html.erb" do
before(:each) do
assign(:process_units, [
stub_model(ProcessUnit),
stub_model(ProcessUnit)
])
end

it "renders a list of process_units" do
render
end
end
15 changes: 15 additions & 0 deletions spec/views/process_units/new.html.erb_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

describe "process_units/new.html.erb" do
before(:each) do
assign(:process_unit, stub_model(ProcessUnit).as_new_record)
end

it "renders new process_unit form" do
render

# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "form", :action => process_units_path, :method => "post" do
end
end
end
11 changes: 11 additions & 0 deletions spec/views/process_units/show.html.erb_spec.rb
@@ -0,0 +1,11 @@
require 'spec_helper'

describe "process_units/show.html.erb" do
before(:each) do
@process_unit = assign(:process_unit, stub_model(ProcessUnit))
end

it "renders attributes in <p>" do
render
end
end

0 comments on commit 21304c6

Please sign in to comment.