require File.dirname(__FILE__) + '/../spec_helper' describe <%= controller_class_name %>Controller do <% if options[:fixtures] -%> fixtures :all <% end %> integrate_views it "index action should render index template" do get :index response.should render_template(:index) end it "show action should render show template" do get :show, :id => <%= class_name %>.first response.should render_template(:show) end it "new action should render new template" do get :new response.should render_template(:new) end it "create action should render new template when model is invalid" do <%= resource_instance %> = <%= class_name %>.new <%= resource_instance %>.stub!(:valid?).and_return(false) <%= class_name %>.stub!(:new).and_return(<%= resource_instance %>) lambda { post :create, :<%= singular_name %> => {} }.should change(<%= class_name %>, :count).by(0) end it "create action should redirect when model is valid" do <%= resource_instance %> = <%= class_name %>.new <%= resource_instance %>.stub!(:valid?).and_return(true) <%= class_name %>.stub!(:new).and_return(<%= resource_instance %>) lambda { post :create, :<%= singular_name %> => {} }.should change(<%= class_name %>, :count).by(1) end it "edit action should render edit template" do get :edit, :id => <%= class_name %>.first response.should render_template(:edit) end it "update action should redirect when model is valid" do put :update, :id => <%= class_name %>.first, :<%= singular_name %> => {} response.should redirect_to(<%= singular_name %>_url(assigns[:<%= singular_name %>])) end it "destroy action should destroy model and redirect to index action" do lambda { delete :destroy, :id => <%= class_name %>.first }.should change(<%= class_name %>, :count).by(-1) response.should redirect_to(<%= plural_name %>_url) end end