Files
danbooru/test/test_helpers/reportbooru_helper.rb
evazion fbab273c81 Upgrade http.rb gem to 5.0.4.
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.
2022-02-22 00:17:05 -06:00

26 lines
1.1 KiB
Ruby

module ReportbooruHelper
def mock_request(url, method: :get, status: 200, body: nil, http: Danbooru::Http.any_instance, **options)
response = HTTP::Response.new(status: status, body: body, version: "1.1", request: nil)
http.stubs(method).with(url, **options).returns(response)
end
def mock_post_search_rankings(date = Date.today, rankings)
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:1234")
url = "http://localhost:1234/post_searches/rank?date=#{date}"
mock_request(url, body: rankings.to_json)
end
def mock_missed_search_rankings(date = Date.today, rankings)
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:1234")
url = "http://localhost:1234/missed_searches"
data = rankings.map { _1.join(" ") }.join("\n")
mock_request(url, body: data)
end
def mock_post_view_rankings(date = Date.today, rankings)
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:1234")
url = "http://localhost:1234/post_views/rank?date=#{date}"
mock_request(url, body: rankings.to_json)
end
end