spec/groovehq/resource_collection_spec.rb in groovehq-1.0.6 vs spec/groovehq/resource_collection_spec.rb in groovehq-1.0.7
- old
+ new
@@ -61,34 +61,48 @@
before do
page_1 = {
tickets: [{ title: "Ticket 1" }],
meta: {
pagination: {
- next_page: "http://api.groovehq.dev/v1/tickets?page=2"
+ next_page: "http://api.groovehq.dev/v1/tickets?page=2",
+ current_page: 1,
+ total_pages: 3,
+ total_count: 3
}
}
}.stringify_keys
page_2 = {
tickets: [{ title: "Ticket 2"}],
meta: {
pagination: {
prev_page: "http://api.groovehq.dev/v1/tickets?page=1",
- next_page: "http://api.groovehq.dev/v1/tickets?page=3"
+ next_page: "http://api.groovehq.dev/v1/tickets?page=3",
+ current_page: 2,
+ total_pages: 3,
+ total_count: 3
}
}
}.stringify_keys
page_3 = {
tickets: [{ title: "Ticket 3"}],
meta: {
pagination: {
+ next_page: "http://api.groovehq.dev/v1/tickets",
prev_page: "http://api.groovehq.dev/v1/tickets?page=2",
+ current_page: 3,
+ total_pages: 3,
+ total_count: 3
}
}
}.stringify_keys
+ stub_request(:get, "http://api.groovehq.dev/v1/tickets").
+ with(headers: {'Authorization' => 'Bearer phantogram'}).
+ to_return(body: page_1.to_json, status: 200)
+
stub_request(:get, "http://api.groovehq.dev/v1/tickets?page=2").
with(headers: {'Authorization' => 'Bearer phantogram'}).
to_return(body: page_2.to_json, status: 200)
stub_request(:get, "http://api.groovehq.dev/v1/tickets?page=3").
@@ -113,10 +127,10 @@
expect(resource.collection.size).to eql(3)
end
it "respects :per_page and other parameters except :page" do
resource = GrooveHQ::ResourceCollection.new(client, @page_1, page: 1, per_page: 20, foo: "bar")
- stub_request(:get, "http://api.groovehq.dev/v1/tickets?page=2&per_page=20&foo=bar").
+ stub_request(:get, /http:\/\/api.groovehq.dev\/v1\/tickets\?page=\d+(&per_page=\d+)?(&foo=bar)?/).
with(headers: {'Authorization' => 'Bearer phantogram'}).
to_return(body: {tickets: []}.to_json, status: 200)
expect(resource.map(&:title)).to eql(["Ticket 1"])
end