From 3b377bc04b81a76bb18f4e0cc13da157ccf710ab Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 18 Jul 2016 09:37:43 +0200 Subject: [PATCH] Handle new page rate limit. --- app/models/channel/driver/facebook.rb | 7 +++++++ test/integration/facebook_test.rb | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/channel/driver/facebook.rb b/app/models/channel/driver/facebook.rb index c7fff2561..4bcf5d029 100644 --- a/app/models/channel/driver/facebook.rb +++ b/app/models/channel/driver/facebook.rb @@ -43,6 +43,13 @@ class Channel::Driver::Facebook =end def fetchable?(_channel) + return true if Rails.env.test? + + # because of new page rate limit - https://developers.facebook.com/blog/post/2016/06/16/page-level-rate-limits/ + # only fetch once in 5 minutes + return true if !channel.preferences + return true if !channel.preferences[:last_fetch] + return false if channel.preferences[:last_fetch] > Time.zone.now - 5.minutes true end diff --git a/test/integration/facebook_test.rb b/test/integration/facebook_test.rb index 648feedcf..bc7ffe12a 100644 --- a/test/integration/facebook_test.rb +++ b/test/integration/facebook_test.rb @@ -175,8 +175,7 @@ class FacebookTest < ActiveSupport::TestCase # check customer customer = ticket.customer - assert_equal('Bernd', customer.firstname) - assert_equal('Hofbecker', customer.lastname) + assert_equal(customer_name, "#{customer.firstname} #{customer.lastname}") # reply via ticket reply_text = "What's your issue Bernd?" @@ -195,7 +194,7 @@ class FacebookTest < ActiveSupport::TestCase outbound_article = Ticket::Article.find(outbound_article.id) assert(outbound_article, 'outbound article created') - assert_equal(outbound_article.from, 'Hansi Merkurs Hutfabrik', 'ticket article outbound count') + assert_equal(outbound_article.from, page_name, 'ticket article outbound count') assert_equal(outbound_article.ticket.articles.count, 2, 'ticket article outbound count') post_comment = 'The peacock feather is fallen off.' @@ -226,7 +225,7 @@ class FacebookTest < ActiveSupport::TestCase outbound_article = Ticket::Article.find(outbound_article.id) assert(outbound_article, 'outbound article created') - assert_equal(outbound_article.from, 'Hansi Merkurs Hutfabrik', 'ticket article outbound count') + assert_equal(outbound_article.from, page_name, 'ticket article outbound count') assert_equal(outbound_article.ticket.articles.count, 4, 'ticket article outbound count') end