diff --git a/lib/her/model/orm.rb b/lib/her/model/orm.rb index 87f46428..1a0c8624 100644 --- a/lib/her/model/orm.rb +++ b/lib/her/model/orm.rb @@ -1,3 +1,4 @@ +# coding: utf-8 module Her module Model # This module adds ORM-like capabilities to the model @@ -72,10 +73,10 @@ def save! # @user = User.find(1) # @user.destroy # # Called via DELETE "/users/1" - def destroy + def destroy(params = {}) method = self.class.method_for(:destroy) run_callbacks :destroy do - self.class.request(:_method => method, :_path => request_path) do |parsed_data, response| + self.class.request(params.merge(:_method => method, :_path => request_path)) do |parsed_data, response| assign_attributes(self.class.parse(parsed_data[:data])) if parsed_data[:data].any? @metadata = parsed_data[:metadata] @response_errors = parsed_data[:errors] diff --git a/spec/model/orm_spec.rb b/spec/model/orm_spec.rb index 247bfd67..295003c9 100644 --- a/spec/model/orm_spec.rb +++ b/spec/model/orm_spec.rb @@ -413,6 +413,31 @@ def friends @user.active.should be_falsey @user.should be_destroyed end + + context "with params" do + before do + Her::API.setup :url => "https://api.example.com" do |builder| + builder.use Her::Middleware::FirstLevelParseJSON + builder.use Faraday::Request::UrlEncoded + builder.adapter :test do |stub| + stub.delete("/users/1?delete_type=soft") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke", :active => false }.to_json] } + end + end + end + + it "handle resource deletion through the .destroy class method" do + @user = Foo::User.destroy_existing(1, delete_type: 'soft') + @user.active.should be_false + @user.should be_destroyed + end + + it "handle resource deletion through #destroy on an existing resource" do + @user = Foo::User.find(1) + @user.destroy(delete_type: 'soft') + @user.active.should be_false + @user.should be_destroyed + end + end end context 'customizing HTTP methods' do