Skip to content

Commit 6b84cf0

Browse files
committed
pass to_json onto resource attributes
1 parent 0423dec commit 6b84cf0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/zendesk_api/resource.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def path(*args)
8484
@association.generate_path(self, *args)
8585
end
8686

87+
def to_json(*args)
88+
method_missing(:to_json, *args)
89+
end
90+
8791
def to_s
8892
"#{self.class.singular_resource_name}: #{attributes.inspect}"
8993
end

spec/resource_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ def to_param; "TESTDATA"; end
328328
end
329329
end
330330

331+
context "#to_json" do
332+
subject { ZendeskAPI::TestResource.new(client, :id => 1) }
333+
334+
it "should call #to_json on @attributes" do
335+
subject.attributes.should_receive(:to_json)
336+
subject.to_json
337+
end
338+
end
339+
331340
context "#==" do
332341
it "is same when id is same" do
333342
ZendeskAPI::TestResource.new(client, :id => 1, "bar" => "baz").should == ZendeskAPI::TestResource.new(client, :id => 1, "foo" => "bar")

0 commit comments

Comments
 (0)