post replacements: refactor and fix tests.
* Move replacement tests from test/unit/upload_service_test.rb to test/functional/post_replacement_controller_test.rb * Move UploadService::Replacer to PostReplacementProcessor. * Fix a minor bug where if you used the API to replace a post with a file, the replacement would fail unless you passed an empty string for the replacement_url.
This commit is contained in:
@@ -6,8 +6,9 @@ class PostReplacement < ApplicationRecord
|
||||
before_validation :initialize_fields, on: :create
|
||||
attr_accessor :replacement_file, :final_source, :tags
|
||||
|
||||
attribute :replacement_url, default: ""
|
||||
|
||||
def initialize_fields
|
||||
self.creator = CurrentUser.user
|
||||
self.original_url = post.source
|
||||
self.tags = "#{post.tag_string} #{tags}"
|
||||
|
||||
@@ -27,6 +28,10 @@ class PostReplacement < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def process!
|
||||
PostReplacementProcessor.new(post: post, replacement: self).process!
|
||||
end
|
||||
|
||||
def suggested_tags_for_removal
|
||||
tags = post.tag_array.select do |tag|
|
||||
Danbooru.config.post_replacement_tag_removals.any? do |pattern|
|
||||
|
||||
Reference in New Issue
Block a user