spec/serializable/paging_spec.rb in restpack_serializer-0.2.6 vs spec/serializable/paging_spec.rb in restpack_serializer-0.2.7
- old
+ new
@@ -19,11 +19,13 @@
end
it "includes valid paging meta data" do
page[:meta][:songs][:count].should == 18
page[:meta][:songs][:page_count].should == 2
page[:meta][:songs][:previous_page].should == nil
+ page[:meta][:songs][:previous_href].should == nil
page[:meta][:songs][:next_page].should == 2
+ page[:meta][:songs][:next_href].should == '/songs.json?page=2'
end
it "includes links" do
page[:links].should == {
'songs.album' => { :href => "/albums/{songs.album}.json", :type => :albums },
'songs.artist' => { :href => "/artists/{songs.artist}.json", :type => :artists }
@@ -35,10 +37,14 @@
let(:params) { { page_size: '3' } }
it "returns custom page sizes" do
page[:meta][:songs][:page_size].should == 3
page[:meta][:songs][:page_count].should == 6
end
+ it "includes the custom page size in the page hrefs" do
+ page[:meta][:songs][:next_page].should == 2
+ page[:meta][:songs][:next_href].should == '/songs.json?page=2&page_size=3'
+ end
end
it "serializes results" do
first = Song.first
page[:songs].first.should == {
@@ -69,10 +75,11 @@
it "returns second page" do
page[:songs].length.should == 8
page[:meta][:songs][:page].should == 2
page[:meta][:songs][:previous_page].should == 1
page[:meta][:songs][:next_page].should == nil
+ page[:meta][:songs][:previous_href].should == '/songs.json'
end
end
context "when sideloading" do
let(:params) { { includes: 'albums' } }
@@ -83,17 +90,25 @@
it "includes the side-loads in the main meta data" do
page[:meta][:songs][:includes].should == [:albums]
end
+ it "includes the side-loads in page hrefs" do
+ page[:meta][:songs][:next_href].should == '/songs.json?page=2&includes=albums'
+ end
+
context "with includes as comma delimited string" do
let(:params) { { includes: "albums,artists" } }
it "includes side-loaded models" do
page[:albums].should_not == nil
page[:artists].should_not == nil
end
+ it "includes the side-loads in page hrefs" do
+ page[:meta][:songs][:next_href].should == '/songs.json?page=2&includes=albums,artists'
+ end
+
it "includes links" do
page[:links]['songs.album'].should_not == nil
page[:links]['songs.artist'].should_not == nil
page[:links]['albums.songs'].should_not == nil
page[:links]['albums.artist'].should_not == nil
@@ -115,9 +130,13 @@
context "with :album_id filter" do
let(:params) { { album_id: @album1.id.to_s } }
it "returns a page with songs from album1" do
page[:meta][:songs][:count].should == @album1.songs.length
+ end
+
+ it "includes the filter in page hrefs" do
+ page[:meta][:songs][:next_href].should == "/songs.json?page=2&album_id=#{@album1.id}"
end
end
end
context "with custom scope" do