Fix #4522: Sidebar doesn't show most searched tags at certain times of day.

Revert back to previous workaround of fetching previous day if current
day returns no result. A terrible hack, really we should convert dates
to Reportbooru's timezone, but that has other complications.
This commit is contained in:
evazion
2020-06-19 13:49:22 -05:00
parent 67a52dbc2d
commit 7a1efc2744
5 changed files with 23 additions and 22 deletions

View File

@@ -4,20 +4,20 @@ class ReportbooruServiceTest < ActiveSupport::TestCase
def setup
@service = ReportbooruService.new(reportbooru_server: "http://localhost:1234")
@post = create(:post)
@date = "2000-01-01"
@date = Date.parse("2000-01-01")
end
context "#popular_posts" do
should "return the list of popular posts on success" do
body = "[[#{@post.id},100.0]]"
@service.http.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date}").returns(HTTP::Response.new(status: 200, body: body, version: "1.1"))
mock_post_view_rankings(@date, [[@post.id, 100]])
posts = @service.popular_posts(@date)
assert_equal([@post], posts)
end
should "return nothing on failure" do
@service.http.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date}").returns(HTTP::Response.new(status: 500, body: "", version: "1.1"))
Danbooru::Http.any_instance.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date}").returns(HTTP::Response.new(status: 500, body: "", version: "1.1"))
Danbooru::Http.any_instance.expects(:get).with("http://localhost:1234/post_views/rank?date=#{@date.yesterday}").returns(HTTP::Response.new(status: 500, body: "", version: "1.1"))
assert_equal([], @service.popular_posts(@date))
end