spec/namely/resource_gateway_spec.rb in namely-0.2.1 vs spec/namely/resource_gateway_spec.rb in namely-0.2.2

- old
+ new

@@ -41,9 +41,40 @@ status: 200 ) expect(gateway.json_index).to eq ["woo!"] end + + context "for paged resources" do + def gateway + @gateway ||= Namely::ResourceGateway.new( + access_token: access_token, + endpoint: "widgets", + resource_name: "widgets", + subdomain: subdomain, + paged: true + ) + end + + it "emits an enumerator that represents all paged items" do + stub_request(:get, "https://#{subdomain}.namely.com/api/v1/widgets"). + with(query: { access_token: access_token }). + to_return(body: { widgets: [ id: "123-456" ] }.to_json) + + stub_request(:get, "https://#{subdomain}.namely.com/api/v1/widgets"). + with(query: { access_token: access_token, after: "123-456" }). + to_return(body: { widgets: [ id: "456-789" ] }.to_json) + + stub_request(:get, "https://#{subdomain}.namely.com/api/v1/widgets"). + with(query: { access_token: access_token, after: "456-789" }). + to_return(body: { widgets: [ ] }.to_json) + + expect(gateway.json_index).to be_kind_of(Enumerator) + ids = gateway.json_index.map { |h| h['id'] } + + expect(ids).to eq(['123-456', '456-789']) + end + end end describe "#json_show" do it "returns the parsed JSON representation of #show" do stub_request(