This commit is contained in:
r888888888
2017-06-29 16:05:01 -07:00
parent c4503e9971
commit d7690d24b0
6 changed files with 15 additions and 14 deletions

View File

@@ -27,6 +27,6 @@ module IqdbTestHelper
url = "http://localhost:3004/similar?key=hunter2&url=#{CGI.escape source}&ref"
body = matches.map { |post| { post_id: post.id } }.to_json
FakeWeb.register_uri(:get, url, body: body)
stub_request(:get, url).to_return(body: body)
end
end

View File

@@ -1,12 +1,12 @@
module ReportbooruHelper
def mock_popular_search_service!
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:3003")
FakeWeb.register_uri(:get, "http://localhost:3003/hits/month?date=#{Date.today}", body: "kantai_collection 1000.0\ntouhou 500.0")
FakeWeb.register_uri(:get, "http://localhost:3003/hits/day?date=#{Date.today}", body: "kantai_collection 1000.0\ntouhou 500.0")
stub_request(:get, "http://localhost:3003/hits/month?date=#{Date.today}").to_return(body: "kantai_collection 1000.0\ntouhou 500.0")
stub_request(:get, "http://localhost:3003/hits/day?date=#{Date.today}").to_return(body: "kantai_collection 1000.0\ntouhou 500.0")
end
def mock_missed_search_service!
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:3003")
FakeWeb.register_uri(:get, "http://localhost:3003/missed_searches", body: "kantai_collection 1000.0\ntouhou 500.0")
stub_request(:get, "http://localhost:3003/missed_searches").to_return(body: "kantai_collection 1000.0\ntouhou 500.0")
end
end

View File

@@ -11,6 +11,7 @@ end
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'cache'
require 'webmock/minitest'
Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file}
Dir[File.expand_path(File.dirname(__FILE__) + "/helpers/*.rb")].each {|file| require file}

View File

@@ -1,6 +1,5 @@
require 'test_helper'
require 'helpers/saved_search_test_helper'
require 'fakeweb'
class SavedSearchTest < ActiveSupport::TestCase
include SavedSearchTestHelper
@@ -46,14 +45,10 @@ class SavedSearchTest < ActiveSupport::TestCase
end
context "Fetching the post ids for a search" do
teardown do
FakeWeb.clean_registry
end
context "with a label" do
setup do
SavedSearch.expects(:queries_for).with(1, "blah").returns(%w(a b c))
FakeWeb.register_uri(:post, "http://localhost:3001/v2/search", :body => "1 2 3 4")
stub_request(:post, "http://localhost:3001/v2/search").to_return(:body => "1 2 3 4")
end
should "return a list of ids" do
@@ -65,7 +60,7 @@ class SavedSearchTest < ActiveSupport::TestCase
context "without a label" do
setup do
SavedSearch.expects(:queries_for).with(1, nil).returns(%w(a b c))
FakeWeb.register_uri(:post, "http://localhost:3001/v2/search", :body => "1 2 3 4")
stub_request(:post, "http://localhost:3001/v2/search").to_return(:body => "1 2 3 4")
end
should "return a list of ids" do