Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
## spec/controllers/generic_rest_controller_spec.rb describe GenericRestController do before :each do # removing the stub! requires me to send :resource_name # in the the action parameters. controller.stub!(:resource_class).and_return(Post) end describe 'responding to GET index' do it 'should expose all find records as @collection' do Post.should_receive(:find).and_return([mock_post]) get :index #, :resource_name => 'post' assigns[:collection].should == [mock_post] end end end ## app/controllers/generic_rest_controller.rb class GenericRestController < ApplicationController def index @collection = resource_class.find(:all) end private def resource_class @resource_class ||= params['resource_name'].camelize.constantize end end
This paste will be private.
From the Design Piracy series on my blog: