require File.dirname(__FILE__) + '/../spec_helper' describe UnstaticNodesController, "handling GET /unstatic_nodes/new" do before(:each) do @unstatic_node = mock_model(UnstaticNode) UnstaticNode.stub!(:new).and_return(@unstatic_node) end def do_get get :new, :name => "new node" end it "should be successful" do do_get response.should be_success end it "should create a new unstatic_node" do UnstaticNode.should_receive(:new).and_return(@unstatic_node) do_get end it "should create the new unstatic_node with params[:name]" do UnstaticNode.should_receive(:new).with(:name => "new node") do_get end it "should assign the new unstatic_node for the view" do do_get assigns[:unstatic_node].should == @unstatic_node end it "should render form" do do_get response.should render_template("form") end end describe UnstaticNodesController, "handling POST /unstatic_nodes" do before(:each) do @unstatic_node = mock_model(UnstaticNode, :save => true) UnstaticNode.stub!(:new).and_return(@unstatic_node) end def do_post post :create, :unstatic_node => {}, :origin => "/" end it "should create a new unstatic_node with the passed params" do UnstaticNode.should_receive(:new).with({}).and_return(@unstatic_node) do_post end it "should assign the created unstatic_node for the view" do do_post assigns[:unstatic_node].should == @unstatic_node end it "should save the created unstatic_node" do @unstatic_node.should_receive(:save) do_post end it "should redirect to originating page on successful save" do do_post response.should redirect_to("/") end it "should re-render form on failed save" do @unstatic_node.should_receive(:save).and_return(false) do_post response.should render_template("form") end end describe UnstaticNodesController, "handling GET /unstatic_nodes/1/edit" do before(:each) do @unstatic_node = mock_model(UnstaticNode) UnstaticNode.stub!(:find).and_return(@unstatic_node) end def do_get get :edit, :id => 1 end it "should be successful" do do_get response.should be_success end it "should find the requested unstatic_node" do UnstaticNode.should_receive(:find).with("1").and_return(@unstatic_node) do_get end it "should assign the unstatic_node for the view" do do_get assigns[:unstatic_node].should == @unstatic_node end it "should render form" do do_get response.should render_template("form") end end describe UnstaticNodesController, "handling PUT /unstatic_nodes/1" do before(:each) do @unstatic_node = mock_model(UnstaticNode, :save => true, :update_attributes => true) UnstaticNode.stub!(:find).and_return(@unstatic_node) end def do_post put :update, :id => 1, :unstatic_node => { "content" => "content" }, :origin => "/" end it "should find requested unstatic_node" do UnstaticNode.should_receive(:find).with("1").and_return(@unstatic_node) do_post end it "should assign the unstatic_node for the view" do do_post assigns[:unstatic_node].should == @unstatic_node end it "should update the unstatic_node with the new content" do @unstatic_node.should_receive(:update_attributes).with({ "content" => "content" }) do_post end it "should redirect to originating page on successful update" do do_post response.should redirect_to("/") end it "should re-render edit form on failed save" do @unstatic_node.should_receive(:update_attributes).and_return(false) do_post response.should render_template("form") end end