diff --git a/app/controllers/process_units_controller.rb b/app/controllers/process_units_controller.rb index 7729304..492e05f 100644 --- a/app/controllers/process_units_controller.rb +++ b/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 diff --git a/app/views/process_units/_form.html.erb b/app/views/process_units/_form.html.erb new file mode 100644 index 0000000..28127bb --- /dev/null +++ b/app/views/process_units/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@process_unit) do |f| %> + <% if @process_unit.errors.any? %> +
+

<%= pluralize(@process_unit.errors.count, "error") %> prohibited this process_unit from being saved:

+ + +
+ <% end %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/process_units/edit.html.erb b/app/views/process_units/edit.html.erb new file mode 100644 index 0000000..0d09613 --- /dev/null +++ b/app/views/process_units/edit.html.erb @@ -0,0 +1,6 @@ +

Editing process_unit

+ +<%= render 'form' %> + +<%= link_to 'Show', @process_unit %> | +<%= link_to 'Back', process_units_path %> diff --git a/app/views/process_units/index.html.erb b/app/views/process_units/index.html.erb new file mode 100644 index 0000000..e039cee --- /dev/null +++ b/app/views/process_units/index.html.erb @@ -0,0 +1,21 @@ +

Listing process_units

+ + + + + + + + +<% @process_units.each do |process_unit| %> + + + + + +<% end %> +
<%= link_to 'Show', process_unit %><%= link_to 'Edit', edit_process_unit_path(process_unit) %><%= link_to 'Destroy', process_unit, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New Process unit', new_process_unit_path %> diff --git a/app/views/process_units/new.html.erb b/app/views/process_units/new.html.erb new file mode 100644 index 0000000..aaaa54f --- /dev/null +++ b/app/views/process_units/new.html.erb @@ -0,0 +1,5 @@ +

New process_unit

+ +<%= render 'form' %> + +<%= link_to 'Back', process_units_path %> diff --git a/app/views/process_units/show.html.erb b/app/views/process_units/show.html.erb new file mode 100644 index 0000000..e7db36e --- /dev/null +++ b/app/views/process_units/show.html.erb @@ -0,0 +1,5 @@ +

<%= notice %>

+ + +<%= link_to 'Edit', edit_process_unit_path(@process_unit) %> | +<%= link_to 'Back', process_units_path %> diff --git a/config/routes.rb b/config/routes.rb index d08e263..c4a69fa 100644 --- a/config/routes.rb +++ b/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. diff --git a/spec/controllers/process_units_controller_spec.rb b/spec/controllers/process_units_controller_spec.rb index 16663dc..9a4404a 100644 --- a/spec/controllers/process_units_controller_spec.rb +++ b/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 diff --git a/spec/requests/process_units_spec.rb b/spec/requests/process_units_spec.rb new file mode 100644 index 0000000..d2288b4 --- /dev/null +++ b/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 diff --git a/spec/routing/process_units_routing_spec.rb b/spec/routing/process_units_routing_spec.rb new file mode 100644 index 0000000..c31a9ee --- /dev/null +++ b/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 diff --git a/spec/views/process_units/edit.html.erb_spec.rb b/spec/views/process_units/edit.html.erb_spec.rb new file mode 100644 index 0000000..04f9c5e --- /dev/null +++ b/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 diff --git a/spec/views/process_units/index.html.erb_spec.rb b/spec/views/process_units/index.html.erb_spec.rb new file mode 100644 index 0000000..d862907 --- /dev/null +++ b/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 diff --git a/spec/views/process_units/new.html.erb_spec.rb b/spec/views/process_units/new.html.erb_spec.rb new file mode 100644 index 0000000..f05ef5c --- /dev/null +++ b/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 diff --git a/spec/views/process_units/show.html.erb_spec.rb b/spec/views/process_units/show.html.erb_spec.rb new file mode 100644 index 0000000..bd54717 --- /dev/null +++ b/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

" do + render + end +end