From 0a06b3d977d0f815a54d0c2aa501a1e4b0bbaca7 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 13 Sep 2018 16:32:35 +0800 Subject: [PATCH] Accept custom AR relation for `UploadRecovery`. --- lib/upload_recovery.rb | 4 ++-- spec/lib/upload_recovery_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rb index 8eb1e7725a8..0bac5eb9666 100644 --- a/lib/upload_recovery.rb +++ b/lib/upload_recovery.rb @@ -3,8 +3,8 @@ class UploadRecovery @dry_run = dry_run end - def recover - Post.where("raw LIKE '%upload:\/\/%'").find_each do |post| + def recover(posts = Post) + posts.where("raw LIKE '%upload:\/\/%'").find_each do |post| begin analyzer = PostAnalyzer.new(post.raw, post.topic_id) cooked_stripped = analyzer.send(:cooked_stripped) diff --git a/spec/lib/upload_recovery_spec.rb b/spec/lib/upload_recovery_spec.rb index 01334c5e7e5..7a5929d8ffa 100644 --- a/spec/lib/upload_recovery_spec.rb +++ b/spec/lib/upload_recovery_spec.rb @@ -46,6 +46,14 @@ RSpec.describe UploadRecovery do end end + it 'accepts a custom ActiveRecord relation' do + post.update!(updated_at: 2.days.ago) + upload.destroy! + + upload_recovery.expects(:recover_from_local).never + upload_recovery.recover(Post.where("updated_at >= ?", 1.day.ago)) + end + it 'should recover the upload' do stub_request(:get, "http://test.localhost#{upload.url}") .to_return(status: 200)