0
@@ -7,43 +7,163 @@ describe "ThingsController", "with all the resourceful actions" do
0
- @object = stub('Thing')
0
- @objects = stub_list(5, 'Thing')
0
+ @objects = stub_list(5, 'Thing') do |t|
0
+ [:destroy, :save, :update_attributes].each { |m| t.stubs(m).returns(true) }
0
+ t.stubs(:to_param).returns('12')
0
+ @object = @objects.first
0
Thing.stubs(:find).returns(@object)
0
+ Thing.stubs(:new).returns(@object)
0
+ (Resourceful::ACTIONS - Resourceful::MODIFYING_ACTIONS).each(&method(:should_render_html))
0
+ Resourceful::ACTIONS.each(&method(:should_render_js))
0
+ Resourceful::ACTIONS.each(&method(:shouldnt_render_xml))
0
it "should find all records on GET /things" do
0
Thing.expects(:find).with(:all).returns(@objects)
0
- it "should return a list of objects for #current_object
after GET /things" do
0
+ it "should return a list of objects for #current_object
s after GET /things" do
0
Thing.stubs(:find).returns(@objects)
0
controller.current_objects.should == @objects
0
it "should assign @things to a list of objects for GET /things" do
0
Thing.stubs(:find).returns(@objects)
0
assigns(:things).should == @objects
0
- it "should render HTML by default for GET /things" do
0
- response.should be_success
0
- response.content_type.should == 'text/html'
0
+ it "should find the record with id 12 on GET /things/12" do
0
+ Thing.expects(:find).with('12').returns(@object)
0
+ it "should return an object for #current_object after GET /things/12" do
0
+ Thing.stubs(:find).returns(@object)
0
+ controller.current_object.should == @object
0
- it "should render JS for GET /things" do
0
- post :index, :format => 'js'
0
- response.should be_success
0
- response.content_type.should == 'text/javascript'
0
+ it "should assign @thing to an object for GET /things/12" do
0
+ Thing.stubs(:find).returns(@object)
0
+ assigns(:thing).should == @object
0
+ it "should find the record with id 12 on GET /things/12/edit" do
0
+ Thing.expects(:find).with('12').returns(@object)
0
- it "shouldn't render XML for GET /things" do
0
- post :index, :format => 'xml'
0
+ it "should return an object for #current_object after GET /things/12/edit" do
0
+ Thing.stubs(:find).returns(@object)
0
+ controller.current_object.should == @object
0
+ it "should assign @thing to an object for GET /things/12/edit" do
0
+ Thing.stubs(:find).returns(@object)
0
+ assigns(:thing).should == @object
0
+ it "should create a new object from params[:thing] for GET /things/new" do
0
+ Thing.expects(:new).with('name' => "Herbert the thing").returns(@object)
0
+ get :new, :thing => {:name => "Herbert the thing"}
0
+ it "should create a new object even if there aren't any params for GET /things/new" do
0
+ Thing.expects(:new).with(nil).returns(@object)
0
+ it "should return the new object for #current_object after GET /things/new" do
0
+ Thing.stubs(:new).returns(@object)
0
+ controller.current_object.should == @object
0
+ it "should assign @thing to the new object for GET /things/new" do
0
+ Thing.stubs(:new).returns(@object)
0
+ assigns(:thing).should == @object
0
+ it "should create a new object from params[:thing] for POST /things" do
0
+ Thing.expects(:new).with('name' => "Herbert the thing").returns(@object)
0
+ post :create, :thing => {:name => "Herbert the thing"}
0
+ it "should create a new object even if there aren't any params for POST /things" do
0
+ Thing.expects(:new).with(nil).returns(@object)
0
+ it "should return the new object for #current_object after POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ controller.current_object.should == @object
0
+ it "should assign @thing to the new object for POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ assigns(:thing).should == @object
0
+ it "should save the new object for POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ @object.expects(:save)
0
+ it "should set an appropriate flash notice for a successful POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ flash[:notice].should == "Create successful!"
0
+ it "should redirect to the new object for a successful POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ response.should redirect_to('/things/12')
0
+ it "should set an appropriate flash error for an unsuccessful POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ @object.stubs(:save).returns(false)
0
+ flash[:error].should == "There was a problem!"
0
+ it "should give a failing response for an unsuccessful POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ @object.stubs(:save).returns(false)
0
response.should_not be_success
0
- response.code.should == '406'
0
+ response.code.should == '422'
0
+ it "should render the #new template for an unsuccessful POST /things" do
0
+ Thing.stubs(:new).returns(@object)
0
+ @object.stubs(:save).returns(false)
0
+ response.should render_template('new')
Comments
No one has commented yet.