Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controller scaffold for Process Unit
- Loading branch information
Showing
14 changed files
with
358 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing process_unit</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @process_unit %> | | ||
<%= link_to 'Back', process_units_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New process_unit</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', process_units_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
|
||
<%= link_to 'Edit', edit_process_unit_path(@process_unit) %> | | ||
<%= link_to 'Back', process_units_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |