tests: add iqdb queries controller tests.
This commit is contained in:
@@ -13,5 +13,6 @@ FactoryGirl.define do
|
||||
image_height 1000
|
||||
file_size 2000
|
||||
rating "q"
|
||||
source { FFaker::Internet.http_url }
|
||||
end
|
||||
end
|
||||
|
||||
33
test/functional/iqdb_queries_controller_test.rb
Normal file
33
test/functional/iqdb_queries_controller_test.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/iqdb_test_helper'
|
||||
|
||||
class IqdbQueriesControllerTest < ActionController::TestCase
|
||||
include IqdbTestHelper
|
||||
|
||||
context "The iqdb controller" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@posts = FactoryGirl.create_list(:post, 2)
|
||||
mock_iqdb_service!
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "render with a post_id" do
|
||||
mock_iqdb_matches!(@posts[0], @posts)
|
||||
post :create, { post_id: @posts[0].id, format: "js" }, { user_id: @user.id }
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render with an url" do
|
||||
mock_iqdb_matches!(@posts[0].source, @posts)
|
||||
post :create, { url: @posts[0].source }, { user_id: @user.id }
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -16,5 +16,16 @@ module IqdbTestHelper
|
||||
|
||||
service = mock_sqs_service.new
|
||||
Post.stubs(:iqdb_sqs_service).returns(service)
|
||||
|
||||
Danbooru.config.stubs(:iqdbs_auth_key).returns("hunter2")
|
||||
Danbooru.config.stubs(:iqdbs_server).returns("http://localhost:3004")
|
||||
end
|
||||
|
||||
def mock_iqdb_matches!(post_or_source, matches)
|
||||
source = post_or_source.is_a?(Post) ? post_or_source.complete_preview_file_url : post_or_source
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2039,7 +2039,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "a post that has been updated" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, :rating => "q", :tag_string => "aaa")
|
||||
@post = FactoryGirl.create(:post, :rating => "q", :tag_string => "aaa", :source => nil)
|
||||
@post.stubs(:merge_version?).returns(false)
|
||||
@post.update_attributes(:tag_string => "aaa bbb ccc ddd")
|
||||
@post.update_attributes(:tag_string => "bbb xxx yyy", :source => "xyz")
|
||||
|
||||
Reference in New Issue
Block a user