Skip to content

Commit 09a6dc5

Browse files
committed
added destroy class method to Destroyable
1 parent 2796435 commit 09a6dc5

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v1.4.20
2+
- added destroy class method to Destroyable
3+
14
v1.4.19
25
- create SparkQLErrors attribute for SparkApi::Response and populate when present
36
- create Errors attribute for SparkApi::Response and populate when present

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.19
1+
1.4.20

lib/spark_api/models/concerns/destroyable.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ module Concerns
44

55
module Destroyable
66

7+
def self.included(base)
8+
base.extend(ClassMethods)
9+
end
10+
11+
module ClassMethods
12+
13+
def destroy(id, arguments = {})
14+
connection.delete("#{path}/#{id}", arguments)
15+
end
16+
17+
end
18+
19+
720
def destroy(arguments = {})
821
self.errors = []
922
begin

spec/unit/spark_api/models/concerns/destroyable_spec.rb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,32 @@ class MyExampleModel < Base
1414
@model = MyExampleModel.first
1515
end
1616

17-
it "should not be destroyed" do
18-
@model.destroyed?.should eq(false)
17+
describe 'destroyed?' do
18+
19+
it "should not be destroyed" do
20+
@model.destroyed?.should eq(false)
21+
end
1922
end
2023

21-
it "should be destroyable" do
22-
stub_api_delete("/some/place/20101230223226074201000000")
23-
@model = MyExampleModel.first
24-
@model.destroy
25-
@model.destroyed?.should eq(true)
24+
describe 'destroy' do
25+
26+
it "should be destroyable" do
27+
stub_api_delete("/some/place/20101230223226074201000000")
28+
@model = MyExampleModel.first
29+
@model.destroy
30+
@model.destroyed?.should eq(true)
31+
end
32+
33+
end
34+
35+
describe 'destroy class method' do
36+
37+
it "allows you to destroy with only the id" do
38+
stub_api_delete("/test/example/20101230223226074201000000")
39+
MyExampleModel.destroy('20101230223226074201000000')
40+
expect_api_request(:delete, "/test/example/20101230223226074201000000").to have_been_made.once
41+
end
42+
2643
end
2744

2845
end

0 commit comments

Comments
 (0)