2626 let ( :response_page1 ) { double ( "response_page1" , body : response_body_page1 ) }
2727
2828 before do
29- allow ( subject ) . to receive ( :get_response ) . with ( " test_resources" ) . and_return ( response_page1 )
29+ stub_json_request ( :get , %r{ test_resources} , json ( response_body_page1 ) )
3030 end
3131
3232 context "when CBP is used" do
3333 it "is empty on the first page" do
34- subject . fetch
35-
36- expect ( subject . prev ) . to eq ( [ ] )
34+ stub_const ( "ZendeskAPI::TestResource::CBP_ACTIONS" , %w[ test_resources ] )
35+ collection = ZendeskAPI :: Collection . new ( client , ZendeskAPI :: TestResource )
36+ expect ( collection . prev ) . to eq ( [ ] )
3737 end
3838 end
3939 end
@@ -1015,8 +1015,9 @@ def to_proc
10151015 end
10161016 end
10171017
1018- context "when fetching a collection" do
1018+ context "when fetching a collection that supports CBP " do
10191019 before do
1020+ stub_const ( "ZendeskAPI::TestResource::CBP_ACTIONS" , %w[ test_resources ] )
10201021 expect ( subject ) . to receive ( :get_response ) . with ( "test_resources" ) . and_return ( cbp_success_response )
10211022 end
10221023
@@ -1033,18 +1034,6 @@ def to_proc
10331034 end
10341035 end
10351036
1036- context "when the endpoint does not support CBP" do
1037- before do
1038- expect ( subject ) . to receive ( :get_response ) . with ( "test_resources" ) . and_raise ( ZendeskAPI ::Error ::NetworkError ) . twice
1039- end
1040-
1041- it "tries an OBP request after a failed CBP request" do
1042- subject . per_page ( 2 ) . fetch
1043- expect ( subject . instance_variable_get ( :@options ) [ "per_page" ] ) . to eq ( 2 )
1044- expect ( subject . instance_variable_get ( :@options ) [ "page" ] ) . to be_nil
1045- end
1046- end
1047-
10481037 describe "#all going through multiple pages" do
10491038 def generate_response ( index , has_more )
10501039 {
@@ -1061,6 +1050,7 @@ def generate_response(index, has_more)
10611050 }
10621051 end
10631052 before do
1053+ stub_const ( "ZendeskAPI::TestResource::CBP_ACTIONS" , %w[ test_resources ] )
10641054 stub_json_request ( :get , %r{test_resources\? page%5Bsize%5D=1} , json ( generate_response ( 1 , true ) ) )
10651055 stub_json_request ( :get , %r{test_resources.json\/ \? page%5Bafter%5D=after1&page%5Bsize%5D=1} , json ( generate_response ( 2 , true ) ) )
10661056 stub_json_request ( :get , %r{test_resources.json\/ \? page%5Bafter%5D=after2&page%5Bsize%5D=1} , json ( generate_response ( 3 , true ) ) )
@@ -1069,12 +1059,12 @@ def generate_response(index, has_more)
10691059
10701060 it "fetches all pages and yields the correct arguments" do
10711061 expect do |b |
1072- silence_logger { subject . all ( &b ) }
1062+ silence_logger { subject . per_page ( 1 ) . all ( &b ) }
10731063 end . to yield_successive_args (
1074- [ ZendeskAPI ::TestResource . new ( client , id : 1 ) , "after" => "after1" , "before" => "before0" , "size" => 100 ] ,
1075- [ ZendeskAPI ::TestResource . new ( client , id : 2 ) , "after" => "after2" , "before" => "before1" , "size" => 100 ] ,
1076- [ ZendeskAPI ::TestResource . new ( client , id : 3 ) , "after" => "after3" , "before" => "before2" , "size" => 100 ] ,
1077- [ ZendeskAPI ::TestResource . new ( client , id : 4 ) , "after" => "after4" , "before" => "before3" , "size" => 100 ]
1064+ [ ZendeskAPI ::TestResource . new ( client , id : 1 ) , "after" => "after1" , "before" => "before0" , "size" => 1 ] ,
1065+ [ ZendeskAPI ::TestResource . new ( client , id : 2 ) , "after" => "after2" , "before" => "before1" , "size" => 1 ] ,
1066+ [ ZendeskAPI ::TestResource . new ( client , id : 3 ) , "after" => "after3" , "before" => "before2" , "size" => 1 ] ,
1067+ [ ZendeskAPI ::TestResource . new ( client , id : 4 ) , "after" => "after4" , "before" => "before3" , "size" => 1 ]
10781068 )
10791069 end
10801070 end
0 commit comments