Skip to content

Commit

Permalink
Add params to DELETE (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
amalagaura authored Nov 20, 2023
1 parent d110eda commit 129f538
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/spyke/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def uri(uri_template = nil)

def send_request(method, path, params)
connection.send(method) do |request|
if method == :get
if [:get, :delete].include?(method)
path, params = merge_query_params(path, params)
request.url path, params
else
Expand Down
4 changes: 2 additions & 2 deletions lib/spyke/orm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def save
end
end

def destroy
self.attributes = delete
def destroy(params = {})
self.attributes = delete(params)
end

def update(new_attributes)
Expand Down
8 changes: 8 additions & 0 deletions test/orm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def test_to_params_with_custom_root
assert_equal({ 'foto' => { 'url' => 'bob.jpg' } }, Cookbook::Photo.new(url: 'bob.jpg').to_params)
end

def test_destroy_with_params
endpoint = stub_request(:delete, 'http://sushi.com/recipes/1?cascade=true').to_return_json(result: { id: 1, deleted: true })
recipe = Recipe.new(id: 1)
recipe.destroy(cascade: true)
assert recipe.deleted
assert_requested endpoint
end

def test_destroy
endpoint = stub_request(:delete, 'http://sushi.com/recipes/1').to_return_json(result: { id: 1, deleted: true })
recipe = Recipe.new(id: 1)
Expand Down

0 comments on commit 129f538

Please sign in to comment.