describe "the update action" do before :each do @<%= singular_name %> = mock_record <%= class_name %> end context "with valid data" do before :each do mock(@<%= singular_name %>).update_attributes("these" => "params") { true } end context "in html format" do before :each do put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" } end it { should route(:put, <%= singular_name %>_path(@<%= singular_name %>)).to(:action => :update, :id => @<%= singular_name %>.to_param) } it { should respond_with(:redirect) } it { should redirect_to(<%= singular_name %>_url(@<%= singular_name %>)) } it { should set_the_flash.to("<%= class_name.titleize %> was successfully updated.") } it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) } end context "in xml format" do before :each do put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" }, :format => "xml" end it { should route(:put, <%= singular_name %>_path(@<%= singular_name %>, :format => :xml)).to(:action => :update, :id => @<%= singular_name %>.to_param, :format => :xml) } it { should respond_with_content_type(:xml) } it { should respond_with(:ok) } it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) } end end context "with invalid data" do before :each do mock(@<%= singular_name %>).update_attributes("these" => "params") { false } end context "in html format" do before :each do put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" } end it { should respond_with(:success) } it { should render_template(:edit) } it { should_not set_the_flash } it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) } it { should have_form_to(<%= singular_name %>_path(@<%= singular_name %>)) } end context "in xml format" do before :each do mock(@<%= singular_name %>.errors).to_xml { "XML errors" } put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" }, :format => "xml" end it { should respond_with_content_type(:xml) } it { should respond_with(:unprocessable_entity) } it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) } specify { response.should have_text("XML errors") } end end end