From 9b4cb0ca9c1b0a296280bf742bed01a1ac197845 Mon Sep 17 00:00:00 2001 From: Luciano Prestes Cavalcanti Date: Thu, 6 Aug 2015 12:20:30 -0300 Subject: [PATCH] Add tests for API timestamp --- test/unit/api/articles_test.rb | 15 +++++++++++++++ test/unit/api/communities_test.rb | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/test/unit/api/articles_test.rb b/test/unit/api/articles_test.rb index b04332b..b44887d 100644 --- a/test/unit/api/articles_test.rb +++ b/test/unit/api/articles_test.rb @@ -104,6 +104,21 @@ class ArticlesTest < ActiveSupport::TestCase assert_not_includes json_page_two["articles"].map { |a| a["id"] }, article_two.id end + should 'list articles with timestamp' do + 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") + + article_one.updated_at = Time.now + 3.hours + article_one.save! + + params[:timestamp] = Time.now + 1.hours + get "/api/v1/articles/?#{params.to_query}" + json = JSON.parse(last_response.body) + + assert_includes json["articles"].map { |a| a["id"] }, article_one.id + assert_not_includes json["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 1fc7674..c954508 100644 --- a/test/unit/api/communities_test.rb +++ b/test/unit/api/communities_test.rb @@ -141,4 +141,19 @@ class CommunitiesTest < ActiveSupport::TestCase 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 + + should 'list communities with timestamp' do + community1 = fast_create(Community, :public_profile => true) + community2 = fast_create(Community) + + community1.updated_at = Time.now + 3.hours + community1.save! + + params[:timestamp] = Time.now + 1.hours + get "/api/v1/communities/?#{params.to_query}" + json = JSON.parse(last_response.body) + + assert_includes json["communities"].map { |a| a["id"] }, community1.id + assert_not_includes json["communities"].map { |a| a["id"] }, community2.id + end end -- libgit2 0.21.2