Fix broken specs since all urls will be oneboxed.

This commit is contained in:
Guo Xiang Tan 2017-01-06 10:01:14 +08:00
parent f473a119ff
commit d10fe51b72
3 changed files with 11 additions and 9 deletions

View File

@ -31,15 +31,17 @@ class UserDestroyer
# block all external urls
if opts[:block_urls]
post.topic_links.each do |link|
unless link.internal or Oneboxer.oneboxer_exists_for_url?(link.url)
ScreenedUrl.watch(link.url, link.domain, ip_address: user.ip_address).try(:record_match!)
unless link.internal ||
(Oneboxer.engine(link.url) != Onebox::Engine::WhitelistedGenericOnebox)
ScreenedUrl.watch(link.url, link.domain, ip_address: user.ip_address)&.record_match!
end
end
end
PostDestroyer.new(@actor.staff? ? @actor : Discourse.system_user, post).destroy
if post.topic and post.is_first_post?
if post.topic && post.is_first_post?
Topic.unscoped.where(id: post.topic.id).update_all(user_id: nil)
end
end

View File

@ -46,10 +46,6 @@ module Oneboxer
""
end
def self.oneboxer_exists_for_url?(url)
Onebox.has_matcher?(url)
end
def self.invalidate(url)
Rails.cache.delete(onebox_cache_key(url))
end
@ -124,6 +120,10 @@ module Oneboxer
$redis.del(preview_key(user_id))
end
def self.engine(url)
Onebox::Matcher.new(url).oneboxed
end
private
def self.preview_key(user_id)

View File

@ -239,12 +239,12 @@ describe UserDestroyer do
it "doesn't add ScreenedUrl records by default" do
ScreenedUrl.expects(:watch).never
UserDestroyer.new(@admin).destroy(@user, {delete_posts: true})
UserDestroyer.new(@admin).destroy(@user, delete_posts: true)
end
it "adds ScreenedUrl records when :block_urls is true" do
ScreenedUrl.expects(:watch).with(anything, anything, has_key(:ip_address)).at_least_once
UserDestroyer.new(@admin).destroy(@user, {delete_posts: true, block_urls: true})
UserDestroyer.new(@admin).destroy(@user, delete_posts: true, block_urls: true)
end
end