diff --git a/test/unit/api/articles_test.rb b/test/unit/api/articles_test.rb index a9dcbd0..b04332b 100644 --- a/test/unit/api/articles_test.rb +++ b/test/unit/api/articles_test.rb @@ -82,6 +82,28 @@ class ArticlesTest < ActiveSupport::TestCase assert_not_includes json['articles'].map {|a| a['id']}, child.id end + should 'list articles with pagination' do + Article.destroy_all + article_one = fast_create(Article, :profile_id => user.person.id, :name => "Another thing") + article_two = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + + params[:page] = 1 + params[:per_page] = 1 + get "/api/v1/articles/?#{params.to_query}" + json_page_one = JSON.parse(last_response.body) + + params[:page] = 2 + params[:per_page] = 1 + get "/api/v1/articles/?#{params.to_query}" + json_page_two = JSON.parse(last_response.body) + + assert_includes json_page_one["articles"].map { |a| a["id"] }, article_two.id + assert_not_includes json_page_one["articles"].map { |a| a["id"] }, article_one.id + + assert_includes json_page_two["articles"].map { |a| a["id"] }, article_one.id + assert_not_includes json_page_two["articles"].map { |a| a["id"] }, article_two.id + end + ############################# # Profile Articles # ############################# diff --git a/test/unit/api/communities_test.rb b/test/unit/api/communities_test.rb index a65ae8b..1fc7674 100644 --- a/test/unit/api/communities_test.rb +++ b/test/unit/api/communities_test.rb @@ -120,4 +120,25 @@ class CommunitiesTest < ActiveSupport::TestCase assert_equivalent [c1.id], json['communities'].map {|c| c['id']} end + should 'list communities with pagination' do + community1 = fast_create(Community, :public_profile => true) + community2 = fast_create(Community) + + params[:page] = 2 + params[:per_page] = 1 + get "/api/v1/communities?#{params.to_query}" + json_page_two = JSON.parse(last_response.body) + + params[:page] = 1 + params[:per_page] = 1 + get "/api/v1/communities?#{params.to_query}" + json_page_one = JSON.parse(last_response.body) + + + assert_includes json_page_one["communities"].map { |a| a["id"] }, community1.id + assert_not_includes json_page_one["communities"].map { |a| a["id"] }, community2.id + + assert_includes json_page_two["communities"].map { |a| a["id"] }, community2.id + assert_not_includes json_page_two["communities"].map { |a| a["id"] }, community1.id + end end -- libgit2 0.21.2