Fixes a bug where the Foundation source strategy failed because http.rb automatically sent a `Content-Length: 0` header with all GET requests, which caused Foundation to return a 400 Bad Request error. This behavior was fixed in http.rb 5.x. http.rb 5.x has a breaking change where it now includes the request object inside the response object, which we have to handle in a few places.
26 lines
981 B
Ruby
26 lines
981 B
Ruby
require 'test_helper'
|
|
|
|
class ReportbooruServiceTest < ActiveSupport::TestCase
|
|
def setup
|
|
@service = ReportbooruService.new(reportbooru_server: "http://localhost:1234")
|
|
@post = create(:post)
|
|
@date = Date.parse("2000-01-01")
|
|
end
|
|
|
|
context "#popular_posts" do
|
|
should "return the list of popular posts on success" do
|
|
mock_post_view_rankings(@date, [[@post.id, 100]])
|
|
|
|
posts = @service.popular_posts(@date)
|
|
assert_equal([@post], posts)
|
|
end
|
|
|
|
should "return nothing on failure" do
|
|
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", request: nil))
|
|
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", request: nil))
|
|
|
|
assert_equal([], @service.popular_posts(@date))
|
|
end
|
|
end
|
|
end
|