Skip to content

Commit 6bfbcc6

Browse files
committed
simplifies how cbp support is implemented by each resource class
1 parent 94ce86e commit 6bfbcc6

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

lib/zendesk_api/cbp_support.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/zendesk_api/resource.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'zendesk_api/association'
55
require 'zendesk_api/associations'
66
require 'zendesk_api/verbs'
7-
require 'zendesk_api/cbp_support'
87

98
# See docs: https://developer.zendesk.com/api-reference/
109
module ZendeskAPI
@@ -164,7 +163,10 @@ def attribute_changes
164163
class DataResource < Data
165164
attr_accessor :error, :error_message
166165
extend Verbs
167-
include CBPSupport
166+
167+
def self.cbp_path_regexes
168+
[]
169+
end
168170
end
169171

170172
# Represents a resource that can only GET

lib/zendesk_api/resources.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ def self.incremental_export(client, start_time)
153153
ZendeskAPI::Collection.new(client, self, :path => "incremental/organizations?start_time=#{start_time.to_i}")
154154
end
155155

156-
CBP_ACTIONS = [/organizations$/].freeze
156+
def self.cbp_path_regexes
157+
[/organizations$/]
158+
end
157159
end
158160

159161
class Brand < Resource
@@ -183,7 +185,9 @@ class OrganizationSubscription < ReadResource
183185
has User
184186
has Organization
185187

186-
CBP_ACTIONS = [%r{organizations/\d+/subscriptions$}].freeze
188+
def self.cbp_path_regexes
189+
[%r{organizations/\d+/subscriptions$}]
190+
end
187191
end
188192

189193
class Category < Resource
@@ -382,7 +386,9 @@ class Ticket < Resource
382386
extend UpdateMany
383387
extend DestroyMany
384388

385-
CBP_ACTIONS = [/tickets$/].freeze
389+
def self.cbp_path_regexes
390+
[/tickets$/]
391+
end
386392

387393
# Unlike other attributes, "comment" is not a property of the ticket,
388394
# but is used as a "comment on save", so it should be kept unchanged,
@@ -604,8 +610,11 @@ class Trigger < Rule
604610
include Conditions
605611
include Actions
606612

607-
CBP_ACTIONS = [/triggers$/, %r{triggers/active$}].freeze
608613
has :execution, :class => RuleExecution
614+
615+
def self.cbp_path_regexes
616+
[/triggers$/, %r{triggers/active$}]
617+
end
609618
end
610619

611620
class Automation < Rule
@@ -650,17 +659,23 @@ def self.preview(client, options = {})
650659
end
651660

652661
class GroupMembership < Resource
653-
CBP_ACTIONS = [%r{groups/\d+/memberships$}].freeze
654662
extend CreateMany
655663
extend DestroyMany
656664

657665
has User
658666
has Group
667+
668+
def self.cbp_path_regexes
669+
[%r{groups/\d+/memberships$}]
670+
end
659671
end
660672

661673
class Group < Resource
662-
CBP_ACTIONS = [/groups$/, %r{groups/assignable$}].freeze
663674
has_many :memberships, :class => GroupMembership, :path => "memberships"
675+
676+
def self.cbp_path_regexes
677+
[/groups$/, %r{groups/assignable$}]
678+
end
664679
end
665680

666681
class User < Resource

spec/core/collection_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
end
3131

3232
context "when CBP is used" do
33+
before { allow(ZendeskAPI::TestResource).to receive(:cbp_path_regexes).and_return([/test_resources/]) }
3334
it "is empty on the first page" do
34-
stub_const("ZendeskAPI::TestResource::CBP_ACTIONS", %w[test_resources])
3535
collection = ZendeskAPI::Collection.new(client, ZendeskAPI::TestResource)
3636
expect(collection.prev).to eq([])
3737
end
@@ -1045,7 +1045,7 @@ def to_proc
10451045

10461046
context "when fetching a collection that supports CBP" do
10471047
before do
1048-
stub_const("ZendeskAPI::TestResource::CBP_ACTIONS", %w[test_resources])
1048+
allow(ZendeskAPI::TestResource).to receive(:cbp_path_regexes).and_return([/test_resources/])
10491049
expect(subject).to receive(:get_response).with("test_resources").and_return(cbp_success_response)
10501050
end
10511051

@@ -1078,7 +1078,7 @@ def generate_response(index, has_more)
10781078
}
10791079
end
10801080
before do
1081-
stub_const("ZendeskAPI::TestResource::CBP_ACTIONS", %w[test_resources])
1081+
allow(ZendeskAPI::TestResource).to receive(:cbp_path_regexes).and_return([/test_resources/])
10821082
stub_json_request(:get, %r{test_resources\?page%5Bsize%5D=1}, json(generate_response(1, true)))
10831083
stub_json_request(:get, %r{test_resources.json\/\?page%5Bafter%5D=after1&page%5Bsize%5D=1}, json(generate_response(2, true)))
10841084
stub_json_request(:get, %r{test_resources.json\/\?page%5Bafter%5D=after2&page%5Bsize%5D=1}, json(generate_response(3, true)))

0 commit comments

Comments
 (0)