Skip to content

Commit ce2b77d

Browse files
authored
Merge pull request zendesk#472 from zendesk/fix/add_create_or_update_method_to_collection
Fix/add create or update method to collection
2 parents caef698 + 1cdb12c commit ce2b77d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/zendesk_api/collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def initialize(client, resource, options = {})
4747
end
4848

4949
# Methods that take a Hash argument
50-
methods = %w{create find update update_many destroy}
50+
methods = %w{create find update update_many destroy create_or_update}
5151
methods += methods.map { |method| method + "!" }
5252
methods.each do |deferrable|
5353
# Passes arguments and the proper path to the resource class method.

spec/core/collection_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@
4949
assert_requested(:put, %r{bulk_test_resources/update_many\?ids=1,2,3$})
5050
end
5151

52+
it "should defer #create_or_update to the resource class" do
53+
resource = ZendeskAPI::Collection.new(client, ZendeskAPI::CreateOrUpdateTestResource)
54+
stub_json_request(:post, %r{create_or_update_test_resources/create_or_update}, json(create_or_update_test_resource: { param: "abc" }))
55+
56+
resource.create_or_update!
57+
58+
assert_requested(:post, %r{create_or_update_test_resources/create_or_update$})
59+
end
60+
5261
it "should defer #create to the resource class" do
5362
stub_json_request(:post, %r{test_resources$}, json(:test_resource => {}))
5463
subject.create

0 commit comments

Comments
 (0)