<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,10 @@
-if ([Rails::VERSION::MAJOR, Rails::VERSION::MINOR] &lt;=&gt; [2,1]) &gt;= 0 # if the rails version is 2.1 or greater...&#205;
-  ActiveRecord::Base.include_root_in_json = true
-end
+# Include hook code here
+if !Object.constants.include?(&quot;RESOURCE_FULL_PLUGIN_INCLUDED&quot;)
+  RESOURCE_FULL_PLUGIN_INCLUDED = true
+
+  if ([Rails::VERSION::MAJOR, Rails::VERSION::MINOR] &lt;=&gt; [2,1]) &gt;= 0 # if the rails version is 2.1 or greater...&#205;
+    ActiveRecord::Base.include_root_in_json = true
+  end
 
-require 'resource_full'
+  require 'resource_full'
+end</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,20 +3,20 @@ module ResourceFull
     include ResourceFull::Render::HTML
     include ResourceFull::Render::JSON
     include ResourceFull::Render::XML
-    
+
     def self.included(controller)
       controller.rescue_from Exception, :with =&gt; :handle_generic_exception_with_correct_response_format
     end
-    
+
     private
-  
-    CONFLICT_MESSAGE = if defined?(ActiveRecord::Errors) 
+
+    CONFLICT_MESSAGE = if defined?(ActiveRecord::Errors)
       if ([Rails::VERSION::MAJOR, Rails::VERSION::MINOR] &lt;=&gt; [2,1]) &gt;= 0 # if the rails version is 2.1 or greater...&#205;
         (I18n.translate 'activerecord.errors.messages')[:taken]
       else
         ActiveRecord::Errors.default_error_messages[:taken]
       end
-    else 
+    else
       &quot;has already been taken&quot;
     end
 
@@ -25,7 +25,7 @@ module ResourceFull
         :conflict
       else :unprocessable_entity end
     end
-    
+
     def handle_generic_exception_with_correct_response_format(exception)
       if request.format.xml?
         if defined?(ExceptionNotifiable) &amp;&amp; defined?(ExceptionNotifier) &amp;&amp; self.is_a?(ExceptionNotifiable) &amp;&amp; !(consider_all_requests_local || local_request?)
@@ -35,7 +35,7 @@ module ResourceFull
              when Symbol then send(deliverer)
              when Proc then deliverer.call(self)
            end
-        
+
            ExceptionNotifier.deliver_exception_notification(exception, self,
              request, data)
         end
@@ -49,7 +49,7 @@ module ResourceFull
              when Symbol then send(deliverer)
              when Proc then deliverer.call(self)
            end
-        
+
            ExceptionNotifier.deliver_exception_notification(exception, self,
              request, data)
         end</diff>
      <filename>lib/resource_full/render.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@ module ResourceFull
   module Render
     module HTML
       protected
-  
+
       def show_html
         self.model_object = send(&quot;find_#{model_name}&quot;)
       rescue ActiveRecord::RecordNotFound =&gt; e
@@ -24,7 +24,7 @@ module ResourceFull
       end
 
       def update_html
-        self.model_object = send(&quot;update_#{model_name}&quot;)      
+        self.model_object = send(&quot;update_#{model_name}&quot;)
         if model_object.errors.empty?
           flash[:info] = &quot;Successfully updated #{model_name.humanize} with ID of #{model_object.id}.&quot;
           redirect_to :action =&gt; :index, :format =&gt; :html
@@ -40,8 +40,11 @@ module ResourceFull
       rescue ActiveRecord::RecordNotFound =&gt; e
         flash[:error] = e.message
         redirect_to :back
+      rescue ActiveRecord::ActiveRecordError =&gt; e
+        flash[:error] = e.message
+        redirect_to :back
       end
-  
+
       def new_html
         self.model_object = send(&quot;new_#{model_name}&quot;)
       end</diff>
      <filename>lib/resource_full/render/html.rb</filename>
    </modified>
    <modified>
      <diff>@@ -62,6 +62,9 @@ module ResourceFull
         head :ok
       rescue ActiveRecord::RecordNotFound =&gt; e
         render :json =&gt; e.to_json , :status =&gt; :not_found
+      rescue ActiveRecord::ActiveRecordError =&gt; e
+        # Dont want the whole backtrace - just the message
+        render :xml =&gt; {:error =&gt; {:text =&gt; e.message}}.to_json, :status =&gt; :unprocessable_entity
       end
 
       def new_json_options</diff>
      <filename>lib/resource_full/render/json.rb</filename>
    </modified>
    <modified>
      <diff>@@ -52,6 +52,11 @@ module ResourceFull
         head :ok
       rescue ActiveRecord::RecordNotFound =&gt; e
         render :xml =&gt; e.to_xml, :status =&gt; :not_found
+      rescue ActiveRecord::ActiveRecordError =&gt; e
+        # Dont want the whole backtrace - just the message
+        builder = Builder::XmlMarkup.new(:indent =&gt; 0)
+        builder.errors { | b | b.error(e.message) }
+        render :xml =&gt; builder, :status =&gt; :unprocessable_entity
       end
 
       def new_xml_options</diff>
      <filename>lib/resource_full/render/xml.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,13 +7,9 @@ module ResourceFull
         base.before_filter :move_queryable_params_into_model_params_on_create, :only =&gt; [:create]
       end
     end
-    
-    # Override this to provide custom find conditions.  This is automatically merged at query
-    # time with the queried conditions extracted from params.
-    def find_options; {}; end
-    
+
     protected
-    
+
     def find_model_object
       # TODO I am not sure what the correct behavior should be here, but I'm artifically
       # generating the exception in order to avoid altering the render methods for the time being.
@@ -21,33 +17,33 @@ module ResourceFull
         raise ActiveRecord::RecordNotFound, &quot;not found: #{params[:id]}&quot; if o.nil?
       end
     end
-  
+
     def new_model_object
       model_class.new
     end
-    
+
     def update_model_object
       returning(find_model_object) do |object|
         object.update_attributes params[model_name]
       end
     end
-    
+
     def create_model_object
       model_class.create(params[model_name])
     end
-    
+
     def destroy_model_object
       model_class.destroy_all(resource_identifier =&gt; params[:id])
     end
-  
+
     def find_all_model_objects
       completed_query.find(:all)
     end
-    
+
     def count_all_model_objects
       completed_query.count
     end
-    
+
     def move_queryable_params_into_model_params_on_create
       params.except(model_name).each do |param_name, value|
         if self.class.queryable_params.collect(&amp;:name).include?(param_name.to_sym)
@@ -55,20 +51,19 @@ module ResourceFull
         end
       end
     end
-    
+
     private
-    
+
       def completed_query
         self.class.queryable_params.inject(model_class) do |finder, queryer|
           queryer.find finder, params
         end
       end
-    
+
       def resource_identifier
         returning(self.class.resource_identifier) do |column|
           return column.call(params[:id]) if column.is_a?(Proc)
         end
       end
-
   end
-end
\ No newline at end of file
+end</diff>
      <filename>lib/resource_full/retrieve.rb</filename>
    </modified>
    <modified>
      <diff>@@ -76,6 +76,23 @@ describe &quot;ResourceFull::Render::JSON&quot; , :type =&gt; :controller do
     hash[&quot;error&quot;][&quot;text&quot;].should == &quot;SomeNonsenseException: sparrow farts&quot;
   end
   
+  it &quot;rescues all unhandled exceptions with an XML response for destroy action as well&quot; do
+    mock_user = ResourceFullMockUser.create!
+    ResourceFullMockUser.send :define_method, :destroy do
+      errors.add_to_base(&quot;Cannot delete&quot;)
+      raise ActiveRecord::RecordInvalid.new(self)
+    end
+
+    begin
+      delete :destroy, :id =&gt; mock_user.id.to_s, :format =&gt; 'json'
+
+      hash = Hash.from_json(response.body)
+      hash[&quot;error&quot;][&quot;text&quot;].should == &quot;Validation failed: Cannot delete&quot;
+    ensure
+      ResourceFullMockUser.send :remove_method, :destroy
+    end
+  end
+
   it &quot;it sends an exception notification email if ExceptionNotifier is enabled and still renders the JSON error response&quot; do
     cleanup = unless defined? ExceptionNotifier
       module ExceptionNotifier; end</diff>
      <filename>spec/resource_full/render/json_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 describe &quot;ResourceFull::Render::XML&quot; , :type =&gt; :controller do
   controller_name &quot;resource_full_mock_users&quot;
-  
+
   before :each do
     ResourceFullMockUser.delete_all
     ResourceFullMockUsersController.resource_identifier = :id
@@ -14,67 +14,83 @@ describe &quot;ResourceFull::Render::XML&quot; , :type =&gt; :controller do
     response.body.should have_tag(&quot;resource-full-mock-user&quot;)
     response.code.should == '200'
   end
-  
+
   it &quot;renders the appropriate error message if it can't find the model object&quot; do
     get :show, :id =&gt; 1, :format =&gt; 'xml'
     response.body.should have_tag(&quot;errors&quot;) { with_tag(&quot;error&quot;, &quot;ActiveRecord::RecordNotFound: not found: 1&quot;) }
     response.code.should == '404'
   end
-  
+
   it &quot;renders all model objects&quot; do
     2.times { ResourceFullMockUser.create! }
     get :index, :format =&gt; 'xml'
     Hash.from_xml(response.body)['resource_full_mock_users'].size.should == 2
     response.code.should == '200'
   end
-  
+
   it &quot;creates and renders a new model object with an empty body&quot; do
     put :create, :resource_full_mock_user =&gt; { 'first_name' =&gt; 'brian' }, :format =&gt; 'xml'
     response.body.should == ResourceFullMockUser.find(:first).to_xml
     ResourceFullMockUser.find(:first).first_name.should == 'brian'
   end
-  
+
   it &quot;creates a new model object and returns a status code of 201 (created)&quot; do
     put :create, :resource_full_mock_user =&gt; { 'first_name' =&gt; 'brian' }, :format =&gt; 'xml'
     response.code.should == '201'
   end
-  
+
   it &quot;creates a new model object and places the location of the new object in the Location header&quot; do
     put :create, :resource_full_mock_user =&gt; {}, :format =&gt; 'xml'
     response.headers['Location'].should == resource_full_mock_user_url(ResourceFullMockUser.find(:first))
   end
-  
+
   it &quot;renders appropriate errors if a model validation fails&quot; do
     ResourceFullMockUser.send :define_method, :validate do
       errors.add :first_name, &quot;can't be blank&quot; if self.first_name.blank?
     end
-    
+
     put :create, :resource_full_mock_user =&gt; {}, :format =&gt; 'xml'
     response.should have_tag(&quot;errors&quot;) { with_tag(&quot;error&quot;, &quot;First name can't be blank&quot;)}
-    
+
     ResourceFullMockUser.send :remove_method, :validate
   end
-  
+
   it &quot;renders the XML for a new model object&quot; do
     get :new, :format =&gt; 'xml'
     response.body.should == ResourceFullMockUser.new.to_xml
   end
-  
+
   class SomeNonsenseException &lt; Exception; end
-  
+
   it &quot;rescues all unhandled exceptions with an XML response&quot; do
     ResourceFullMockUser.expects(:find).raises SomeNonsenseException, &quot;sparrow farts&quot;
     get :index, :format =&gt; 'xml'
     response.should have_tag(&quot;errors&quot;) { with_tag(&quot;error&quot;, &quot;SomeNonsenseException: sparrow farts&quot;) }
   end
-  
+
+  it &quot;rescues all unhandled exceptions with an XML response for destroy action as well&quot; do
+    mock_user = ResourceFullMockUser.create!
+    ResourceFullMockUser.send :define_method, :destroy do
+      errors.add_to_base(&quot;Cannot delete&quot;)
+      raise ActiveRecord::RecordInvalid.new(self)
+    end
+
+    begin
+      delete :destroy, :id =&gt; mock_user.id.to_s, :format =&gt; 'xml'
+
+      response.should have_tag(&quot;errors&quot;) { with_tag(&quot;error&quot;, &quot;Validation failed: Cannot delete&quot;) }
+    ensure
+      ResourceFullMockUser.send :remove_method, :destroy
+    end
+  end
+
   it &quot;it sends an exception notification email if ExceptionNotifier is enabled and still renders the XML error response&quot; do
     cleanup = unless defined? ExceptionNotifier
       module ExceptionNotifier; end
       module ExceptionNotifiable; end
       true
     end
-    
+
     ResourceFullMockUsersController.send :include, ExceptionNotifiable
     ResourceFullMockUser.expects(:find).raises SomeNonsenseException, &quot;sparrow farts&quot;
     ResourceFullMockUsersController.stubs(:exception_data).returns(nil)
@@ -83,13 +99,13 @@ describe &quot;ResourceFull::Render::XML&quot; , :type =&gt; :controller do
     ExceptionNotifier.expects(:deliver_exception_notification)
     get :index, :format =&gt; 'xml'
     response.should have_tag(&quot;errors&quot;) { with_tag(&quot;error&quot;, &quot;SomeNonsenseException: sparrow farts&quot;) }
-    
+
     if cleanup
       Object.send :remove_const, :ExceptionNotifier
       Object.send :remove_const, :ExceptionNotifiable
     end
-  end 
-  
+  end
+
   it &quot;retains the generic error 500 when re-rendering unhandled exceptions&quot; do
     ResourceFullMockUser.expects(:find).raises SomeNonsenseException, &quot;sparrow farts&quot;
     get :index, :format =&gt; 'xml'</diff>
      <filename>spec/resource_full/render/xml_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2ada3d9dcc79c7a99c57ad99d8f983b0fddbcdcd</id>
    </parent>
  </parents>
  <author>
    <name>Vijay Aravamudhan</name>
    <email>avijayr - at - gmail - dot - com</email>
  </author>
  <url>http://github.com/bguthrie/resource_full/commit/7f08b1185af706f02bac7bc12dcd66daf94316aa</url>
  <id>7f08b1185af706f02bac7bc12dcd66daf94316aa</id>
  <committed-date>2009-09-20T14:51:26-07:00</committed-date>
  <authored-date>2009-09-20T14:51:26-07:00</authored-date>
  <message>Vijay: Added functionality to handle errors on delete call for all formats. Removed (old) no-op method (find_options) in retrieve.rb. Removed trailing spaces for easier diff with other branch from our svn repo.</message>
  <tree>5e0acb72b6f77e6a6f46a0b50944e68903506f51</tree>
  <committer>
    <name>Vijay Aravamudhan</name>
    <email>avijayr - at - gmail - dot - com</email>
  </committer>
</commit>
