Skip to content

Commit

Permalink
Fixes bug with fetching next/previous page of clips
Browse files Browse the repository at this point in the history
  • Loading branch information
vesan committed Jul 31, 2015
1 parent 5e3ada1 commit d139674
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/kippt/collection.rb
Expand Up @@ -37,7 +37,7 @@ def next_page?
def next_page
raise Kippt::APIError.new("There is no next page") if @next.nil? || @next == ""

collection_resource.collection_from_url(@next)
collection_resource_from_url(@next).fetch
end

def previous_page?
Expand All @@ -48,14 +48,14 @@ def previous_page?
def previous_page
raise Kippt::APIError.new("There is no previous page") if @previous.nil? || @previous == ""

collection_resource.collection_from_url(@previous)
collection_resource_from_url(@previous).fetch
end
alias_method :prev_page, :previous_page

private

def collection_resource
@collection_resource ||= client.collection_resource_for(collection_resource_class)
def collection_resource_from_url(url)
client.collection_resource_for(collection_resource_class, url)
end

def client
Expand Down
1 change: 1 addition & 0 deletions spec/kippt/clip_collection_spec.rb
Expand Up @@ -9,6 +9,7 @@
let(:client) { stub }
subject { Kippt::ClipCollection.new(data, client) }
let(:subject_with_multiple_pages) { Kippt::ClipCollection.new(data_with_multiple_pages, client) }
let(:collection_resource_class) { Kippt::Clips }

it_behaves_like "collection"
end
1 change: 1 addition & 0 deletions spec/kippt/list_collection_spec.rb
Expand Up @@ -8,6 +8,7 @@
let(:client) { stub }
subject { Kippt::ListCollection.new(data, client) }
let(:subject_with_multiple_pages) { Kippt::ListCollection.new(data_with_multiple_pages, client) }
let(:collection_resource_class) { Kippt::Lists }

it_behaves_like "collection"
end
1 change: 1 addition & 0 deletions spec/kippt/user_collection_spec.rb
Expand Up @@ -9,6 +9,7 @@
let(:client) { stub }
subject { Kippt::UserCollection.new(data, client) }
let(:subject_with_multiple_pages) { Kippt::UserCollection.new(data_with_multiple_pages, client) }
let(:collection_resource_class) { Kippt::Users }

it_behaves_like "collection"
end
12 changes: 6 additions & 6 deletions spec/shared_examples/collection.rb
Expand Up @@ -56,11 +56,10 @@
let(:collection_resource) { stub }

it "gets the next page of results from the collection resource" do
client.stub(:collection_resource_for).and_return(collection_resource)
client.should_receive(:collection_resource_for).with(collection_resource_class, data_with_multiple_pages["meta"]["next"]).and_return(collection_resource)

results = stub
collection_resource.should_receive(:collection_from_url).
with(data_with_multiple_pages["meta"]["next"]).
collection_resource.should_receive(:fetch).
and_return(results)

subject_with_multiple_pages.next_page.should eq results
Expand Down Expand Up @@ -95,11 +94,12 @@
let(:collection_resource) { stub }

it "gets the previous page of results from the collection resource" do
client.stub(:collection_resource_for).and_return(collection_resource)
client.should_receive(:collection_resource_for)
.with(collection_resource_class, data_with_multiple_pages["meta"]["previous"])
.and_return(collection_resource)

results = stub
collection_resource.should_receive(:collection_from_url).
with(data_with_multiple_pages["meta"]["previous"]).
collection_resource.should_receive(:fetch).
and_return(results)

subject_with_multiple_pages.previous_page.should eq results
Expand Down

0 comments on commit d139674

Please sign in to comment.